Try to make TextInput work

makingSettings
marouault 3 years ago
parent 62d546974a
commit 44f5902828

@ -3,7 +3,8 @@
InputProcessor createInputProcessor() {
InputProcessor inputProcessor = {
.tabButton = array_P_Button_Create(),
.tabTextInput = array_TextInput_Create()
.tabTextInput = array_TextInput_Create(),
.selectedTextInput = NULL
};
return inputProcessor;
}

@ -14,8 +14,8 @@ bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAd
const size_t lenStrToAdd = strlen(strToAdd);
char newValue[lenText+lenStrToAdd+1];
//strcpy(newValue, "");
strncat(newValue, textInput->value, textInput->cursorPosition);
strcpy(newValue, "");
strncpy(newValue, textInput->value, textInput->cursorPosition);
strcat(newValue, strToAdd);
strcat(newValue, textInput->value+textInput->cursorPosition);
@ -34,8 +34,8 @@ bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAd
bool removeCharacterToInputTextValueAtCursor(TextInput* textInput)
{
size_t removeSize = 0;
size_t lenText = strlen(textInput->value);
while (lenText>removeSize && textInput->value[textInput->cursorPosition - 1] < -64) {
size_t lenText = strlen(textInput->value);
while (lenText>removeSize && textInput->value[textInput->cursorPosition - removeSize-1] < -64) {
removeSize++;
}
if (lenText>removeSize) {
@ -69,9 +69,9 @@ bool removeCharacterToInputTextValueAtCursor(TextInput* textInput)
}
strcpy(tmp, textInput->value);
//strcpy(textInput->value, "");
strcpy(textInput->value, "");
strncpy(textInput->value, tmp, textInput->cursorPosition-removeSize);
strcat(textInput->value, tmp+textInput->cursorPosition);
strcat(textInput->value, tmp+textInput->cursorPosition+1);
textInput->cursorPosition -= 1;
return true;
}

@ -52,7 +52,7 @@ SDL_Rect windowSize = {10, 10, 900, 900};
TextInput* textInput = array_TextInput_Last(&inputProcessor.tabTextInput);
SDL_Rect size = {.x=10, .y=10, .w=90, .h=20};
if(!initTextInput(textInput, &size, NULL, fontHandler.fonts[FONT_retro]))
if(!initTextInput(textInput, &size, NULL, fontHandler.fonts[FONT_PublicPixel]))
{
fprintf(stderr, "WARNING: can't init TextInput\n");
return;

Loading…
Cancel
Save