Fix backspace not working properly on some mobile devices

This commit is contained in:
UnknownShadow200 2020-01-22 19:09:53 +11:00
parent 93cdbdd2c5
commit 746191384d
4 changed files with 23 additions and 21 deletions

View File

@ -831,7 +831,7 @@ static int EditHotkeyScreen_KeyPress(void* screen, char keyChar) {
static int EditHotkeyScreen_TextChanged(void* screen, const String* str) {
#ifdef CC_BUILD_TOUCH
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
InputWidget_SetAndSyncText(&s->input.base, str);
InputWidget_SetText(&s->input.base, str);
#endif
return true;
}
@ -1023,7 +1023,7 @@ static int GenLevelScreen_KeyPress(void* screen, char keyChar) {
static int GenLevelScreen_TextChanged(void* screen, const String* str) {
#ifdef CC_BUILD_TOUCH
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
if (s->selected) InputWidget_SetAndSyncText(&s->selected->base, str);
if (s->selected) InputWidget_SetText(&s->selected->base, str);
#endif
return true;
}
@ -1377,7 +1377,7 @@ static int SaveLevelScreen_TextChanged(void* screen, const String* str) {
#ifdef CC_BUILD_TOUCH
struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen;
SaveLevelScreen_RemoveOverwrites(s);
InputWidget_SetAndSyncText(&s->input.base, str);
InputWidget_SetText(&s->input.base, str);
#endif
return true;
}
@ -2055,7 +2055,7 @@ static int MenuOptionsScreen_KeyPress(void* screen, char keyChar) {
static int MenuOptionsScreen_TextChanged(void* screen, const String* str) {
#ifdef CC_BUILD_TOUCH
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
if (s->activeI >= 0) InputWidget_SetAndSyncText(&s->input.base, str);
if (s->activeI >= 0) InputWidget_SetText(&s->input.base, str);
#endif
return true;
}
@ -2112,14 +2112,11 @@ static void MenuOptionsScreen_OK(void* screen, void* widget) {
static void MenuOptionsScreen_Default(void* screen, void* widget) {
String value; char valueBuffer[STRING_SIZE];
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct MenuInputDesc* desc;
struct MenuInputDesc* desc = &s->descs[s->activeI];
desc = &s->descs[s->activeI];
String_InitArray(value, valueBuffer);
desc->VTABLE->GetDefault(desc, &value);
InputWidget_Clear(&s->input.base);
InputWidget_AppendString(&s->input.base, &value);
InputWidget_SetText(&s->input.base, &value);
}
static void MenuOptionsScreen_Bool(void* screen, void* widget) {

View File

@ -727,7 +727,7 @@ static int ChatScreen_TextChanged(void* screen, const String* str) {
struct ChatScreen* s = (struct ChatScreen*)screen;
if (!s->grabsInput) return false;
InputWidget_SetAndSyncText(&s->input.base, str);
InputWidget_SetText(&s->input.base, str);
ChatScreen_UpdateChatYOffsets(s);
#endif
return true;
@ -965,7 +965,7 @@ void ChatScreen_OpenInput(const String* text) {
void ChatScreen_AppendInput(const String* text) {
struct ChatScreen* s = &ChatScreen_Instance;
InputWidget_AppendString(&s->input.base, text);
InputWidget_AppendText(&s->input.base, text);
ChatScreen_UpdateChatYOffsets(s);
}

View File

@ -1060,7 +1060,7 @@ static cc_bool InputWidget_TryAppendChar(struct InputWidget* w, char c) {
return true;
}
void InputWidget_AppendString(struct InputWidget* w, const String* text) {
void InputWidget_AppendText(struct InputWidget* w, const String* text) {
int i, appended = 0;
for (i = 0; i < text->length; i++) {
if (InputWidget_TryAppendChar(w, text->buffer[i])) appended++;
@ -1174,7 +1174,7 @@ static void InputWidget_EndKey(struct InputWidget* w) {
}
static void InputWidget_CopyFromClipboard(String* text, void* w) {
InputWidget_AppendString((struct InputWidget*)w, text);
InputWidget_AppendText((struct InputWidget*)w, text);
}
static cc_bool InputWidget_OtherKey(struct InputWidget* w, int key) {
@ -1204,12 +1204,14 @@ void InputWidget_UpdateText(struct InputWidget* w) {
InputWidget_CalculateLineSizes(w);
w->RemakeTexture(w);
InputWidget_UpdateCaret(w);
Window_SetKeyboardText(&w->text);
}
void InputWidget_SetAndSyncText(struct InputWidget* w, const String* str) {
void InputWidget_SetText(struct InputWidget* w, const String* str) {
InputWidget_Clear(w);
InputWidget_AppendString(w, str);
Window_SetKeyboardText(&w->text);
InputWidget_AppendText(w, str);
/* If text is empty, InputWidget_UpdateText won't have been called */
if (!w->text.length) Window_SetKeyboardText(&w->text);
}
static void InputWidget_Free(void* widget) {
@ -1723,7 +1725,7 @@ static void ChatInputWidget_TabKey(struct InputWidget* w) {
if (w->caretPos != -1) w->caretPos -= len;
name = TabList_UNSAFE_GetPlayer(matches[0]);
InputWidget_AppendString(w, &name);
InputWidget_AppendText(w, &name);
} else if (numMatches > 1) {
String_InitArray(str, strBuffer);
String_Format1(&str, "&e%i matching names: ", &numMatches);
@ -2573,7 +2575,7 @@ static void SpecialInputWidget_IntersectsBody(struct SpecialInputWidget* w, int
/* TODO: Not be so hacky */
if (w->selectedIndex == 0) str.length = 2;
InputWidget_AppendString(w->target, &str);
InputWidget_AppendText(w->target, &str);
}
static void SpecialInputTab_Init(struct SpecialInputTab* tab, STRING_REF String* title, int itemsPerRow, int charsPerItem, STRING_REF String* contents) {

View File

@ -130,16 +130,19 @@ struct InputWidget {
/* Removes all characters and then deletes the input texture. */
CC_NOINLINE void InputWidget_Clear(struct InputWidget* w);
/* Tries appending all characters from the given string, then update the input texture. */
CC_NOINLINE void InputWidget_AppendString(struct InputWidget* w, const String* text);
CC_NOINLINE void InputWidget_AppendText(struct InputWidget* w, const String* text);
/* Tries appending the given character, then updates the input texture. */
CC_NOINLINE void InputWidget_Append(struct InputWidget* w, char c);
/* Redraws text and recalculates associated state. */
/* Also calls Window_SetKeyboardText with the text in the input widget. */
/* This way native text input state stays synchronised with the input widget. */
/* (e.g. may only accept numerical input, so 'c' gets stripped from str) */
CC_NOINLINE void InputWidget_UpdateText(struct InputWidget* w);
/* Shorthand for InputWidget_Clear followed by InputWidget_AppendString, */
/* Shorthand for InputWidget_Clear followed by InputWidget_AppendText, */
/* then calls Window_SetKeyboardText with the text in the input widget. */
/* This way native text input state stays synchronised with the input widget. */
/* (e.g. may only accept numerical input, so 'c' gets stripped from str) */
CC_NOINLINE void InputWidget_SetAndSyncText(struct InputWidget* w, const String* str);
CC_NOINLINE void InputWidget_SetText(struct InputWidget* w, const String* str);
struct MenuInputDesc;