From eddc86b7b0795fe7c7a82d86f6ee151ccdca229f Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 6 Mar 2021 14:44:17 +0200 Subject: Mobile: Dealing with keyboard height The software keyboard obstructs part of the UI, so need to offset the view if the focused input widget would not be visible. --- src/ui/window.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/ui/window.c') diff --git a/src/ui/window.c b/src/ui/window.c index bf7214f4..9ff22d35 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1136,6 +1136,7 @@ static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) { iInt2 *size = &d->root->rect.size; const iInt2 oldSize = *size; SDL_GetRendererOutputSize(d->render, &size->x, &size->y); + size->y -= d->keyboardHeight; if (notifyAlways || !isEqual_I2(oldSize, *size)) { const iBool isHoriz = (d->place.lastNotifiedSize.x != size->x); const iBool isVert = (d->place.lastNotifiedSize.y != size->y); @@ -1287,6 +1288,8 @@ void init_Window(iWindow *d, iRect rect) { d->isMouseInside = iTrue; d->ignoreClick = iFalse; d->focusGainedAt = 0; + d->keyboardHeight = 0; + init_Anim(&d->rootOffset, 0.0f); uint32_t flags = 0; #if defined (iPlatformAppleDesktop) SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); @@ -1704,6 +1707,7 @@ void draw_Window(iWindow *d) { if (d->isDrawFrozen) { return; } +// printf("num pending: %d\n", numPendingGlyphs_Text()); const int winFlags = SDL_GetWindowFlags(d->win); const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0; /* Clear the window. The clear color is visible as a border around the window @@ -1797,6 +1801,10 @@ iInt2 rootSize_Window(const iWindow *d) { return d ? d->root->rect.size : zero_I2(); } +iInt2 visibleRootSize_Window(const iWindow *d) { + return addY_I2(rootSize_Window(d), -d->keyboardHeight); +} + iInt2 coord_Window(const iWindow *d, int x, int y) { #if defined (iPlatformMsys) || defined (iPlatformLinux) /* On Windows, surface coordinates are in pixels. */ @@ -1828,6 +1836,18 @@ iWindow *get_Window(void) { return theWindow_; } +void setKeyboardHeight_Window(iWindow *d, int height) { + if (d->keyboardHeight != height) { + d->keyboardHeight = height; + if (height == 0) { + setFlags_Anim(&d->rootOffset, easeBoth_AnimFlag, iTrue); + setValue_Anim(&d->rootOffset, 0, 250); + } + postCommandf_App("keyboard.changed arg:%d", height); + postRefresh_App(); + } +} + void setSnap_Window(iWindow *d, int snapMode) { if (!prefs_App()->customFrame) { if (snapMode == maximized_WindowSnap) { -- cgit v1.2.3