summaryrefslogtreecommitdiff
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-06 14:44:17 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-06 14:44:17 +0200
commiteddc86b7b0795fe7c7a82d86f6ee151ccdca229f (patch)
tree7eea8ac70aa37d068adfc2d06dc066367a10572c /src/ui/window.c
parent7fa64b95d0c63b243f50b23c5551a7e04fe90c30 (diff)
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.
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c20
1 files changed, 20 insertions, 0 deletions
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) {
1136 iInt2 *size = &d->root->rect.size; 1136 iInt2 *size = &d->root->rect.size;
1137 const iInt2 oldSize = *size; 1137 const iInt2 oldSize = *size;
1138 SDL_GetRendererOutputSize(d->render, &size->x, &size->y); 1138 SDL_GetRendererOutputSize(d->render, &size->x, &size->y);
1139 size->y -= d->keyboardHeight;
1139 if (notifyAlways || !isEqual_I2(oldSize, *size)) { 1140 if (notifyAlways || !isEqual_I2(oldSize, *size)) {
1140 const iBool isHoriz = (d->place.lastNotifiedSize.x != size->x); 1141 const iBool isHoriz = (d->place.lastNotifiedSize.x != size->x);
1141 const iBool isVert = (d->place.lastNotifiedSize.y != size->y); 1142 const iBool isVert = (d->place.lastNotifiedSize.y != size->y);
@@ -1287,6 +1288,8 @@ void init_Window(iWindow *d, iRect rect) {
1287 d->isMouseInside = iTrue; 1288 d->isMouseInside = iTrue;
1288 d->ignoreClick = iFalse; 1289 d->ignoreClick = iFalse;
1289 d->focusGainedAt = 0; 1290 d->focusGainedAt = 0;
1291 d->keyboardHeight = 0;
1292 init_Anim(&d->rootOffset, 0.0f);
1290 uint32_t flags = 0; 1293 uint32_t flags = 0;
1291#if defined (iPlatformAppleDesktop) 1294#if defined (iPlatformAppleDesktop)
1292 SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); 1295 SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl");
@@ -1704,6 +1707,7 @@ void draw_Window(iWindow *d) {
1704 if (d->isDrawFrozen) { 1707 if (d->isDrawFrozen) {
1705 return; 1708 return;
1706 } 1709 }
1710// printf("num pending: %d\n", numPendingGlyphs_Text());
1707 const int winFlags = SDL_GetWindowFlags(d->win); 1711 const int winFlags = SDL_GetWindowFlags(d->win);
1708 const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0; 1712 const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0;
1709 /* Clear the window. The clear color is visible as a border around the window 1713 /* Clear the window. The clear color is visible as a border around the window
@@ -1797,6 +1801,10 @@ iInt2 rootSize_Window(const iWindow *d) {
1797 return d ? d->root->rect.size : zero_I2(); 1801 return d ? d->root->rect.size : zero_I2();
1798} 1802}
1799 1803
1804iInt2 visibleRootSize_Window(const iWindow *d) {
1805 return addY_I2(rootSize_Window(d), -d->keyboardHeight);
1806}
1807
1800iInt2 coord_Window(const iWindow *d, int x, int y) { 1808iInt2 coord_Window(const iWindow *d, int x, int y) {
1801#if defined (iPlatformMsys) || defined (iPlatformLinux) 1809#if defined (iPlatformMsys) || defined (iPlatformLinux)
1802 /* On Windows, surface coordinates are in pixels. */ 1810 /* On Windows, surface coordinates are in pixels. */
@@ -1828,6 +1836,18 @@ iWindow *get_Window(void) {
1828 return theWindow_; 1836 return theWindow_;
1829} 1837}
1830 1838
1839void setKeyboardHeight_Window(iWindow *d, int height) {
1840 if (d->keyboardHeight != height) {
1841 d->keyboardHeight = height;
1842 if (height == 0) {
1843 setFlags_Anim(&d->rootOffset, easeBoth_AnimFlag, iTrue);
1844 setValue_Anim(&d->rootOffset, 0, 250);
1845 }
1846 postCommandf_App("keyboard.changed arg:%d", height);
1847 postRefresh_App();
1848 }
1849}
1850
1831void setSnap_Window(iWindow *d, int snapMode) { 1851void setSnap_Window(iWindow *d, int snapMode) {
1832 if (!prefs_App()->customFrame) { 1852 if (!prefs_App()->customFrame) {
1833 if (snapMode == maximized_WindowSnap) { 1853 if (snapMode == maximized_WindowSnap) {