Try to make TextInput work

makingSettings
marouault 3 years ago
parent 62d546974a
commit 44f5902828

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

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

@ -52,7 +52,7 @@ SDL_Rect windowSize = {10, 10, 900, 900};
TextInput* textInput = array_TextInput_Last(&inputProcessor.tabTextInput); TextInput* textInput = array_TextInput_Last(&inputProcessor.tabTextInput);
SDL_Rect size = {.x=10, .y=10, .w=90, .h=20}; 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"); fprintf(stderr, "WARNING: can't init TextInput\n");
return; return;

Loading…
Cancel
Save