From f8a584f0f4695cbda91e1d00a915aa9d41f19a90 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sun, 8 Oct 2023 21:56:30 -0400 Subject: [PATCH] editbox: Set the system text input rect --- lib/framework/wzapp.h | 9 ++++++++- lib/sdl/main_sdl.cpp | 16 +++++++++++++++- lib/widget/editbox.cpp | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/framework/wzapp.h b/lib/framework/wzapp.h index b3dd1d07634..5a607d71102 100644 --- a/lib/framework/wzapp.h +++ b/lib/framework/wzapp.h @@ -132,7 +132,14 @@ WzString wzGetSelection(); unsigned int wzGetCurrentKey(); void wzDelay(unsigned int delay); //delay in ms // unicode text support -void StartTextInput(void* pTextInputRequester); +struct WzTextInputRect +{ + int x; + int y; + int width; + int height; +}; +void StartTextInput(void* pTextInputRequester, const WzTextInputRect& textInputRect); void StopTextInput(void* pTextInputResigner); bool isInTextInputMode(); bool wzSeemsLikeNonTouchPlatform(); diff --git a/lib/sdl/main_sdl.cpp b/lib/sdl/main_sdl.cpp index 53bc88a3131..902f0cfda37 100644 --- a/lib/sdl/main_sdl.cpp +++ b/lib/sdl/main_sdl.cpp @@ -268,10 +268,16 @@ bool get_scrap(char **dst) } } -void StartTextInput(void* pTextInputRequester) +void StartTextInput(void* pTextInputRequester, const WzTextInputRect& textInputRect) { if (!GetTextEventsOwner) { + SDL_Rect rect; + rect.x = textInputRect.x; + rect.y = textInputRect.y; + rect.w = textInputRect.width; + rect.h = textInputRect.height; + SDL_SetTextInputRect(&rect); SDL_StartTextInput(); // enable text events debug(LOG_INPUT, "SDL text events started"); } @@ -280,6 +286,14 @@ void StartTextInput(void* pTextInputRequester) debug(LOG_INPUT, "StartTextInput called by new input requester before old requester called StopTextInput"); } GetTextEventsOwner = pTextInputRequester; + + // on some platforms, it seems like we also need to call SDL_SetTextInputRect every frame to properly set the text input rect (?) + SDL_Rect rect; + rect.x = textInputRect.x; + rect.y = textInputRect.y; + rect.w = textInputRect.width; + rect.h = textInputRect.height; + SDL_SetTextInputRect(&rect); } void StopTextInput(void* pTextInputResigner) diff --git a/lib/widget/editbox.cpp b/lib/widget/editbox.cpp index 39f8d8fd8d2..b244d00a9be 100644 --- a/lib/widget/editbox.cpp +++ b/lib/widget/editbox.cpp @@ -321,7 +321,7 @@ void W_EDITBOX::run(W_CONTEXT *psContext) return; } dirty = true; - StartTextInput(this); + StartTextInput(this, {screenPosX(), screenPosY(), width(), height()}); /* If there is a mouse click outside of the edit box - stop editing */ int mx = psContext->mx; int my = psContext->my;