Lagrange [work/v1.12]

Mobile: Fixed layout issues

=> 1b716d38a4d7355ded5e495fcfb9a0e45e5fc83f

diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 49918152..de09db47 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -2302,7 +2302,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
     else if (isCommand_UserEvent(ev, "keyboard.changed")) {
         const iBool isKeyboardVisible = (arg_Command(command_UserEvent(ev)) != 0);
         /* Scroll to keep widget visible when keyboard appears. */
-        if (isFocused_Widget(d)) {
+        if (isFocused_Widget(d) && findOverflowScrollable_Widget(parent_Widget(d))) {
             if (isKeyboardVisible) {
                 d->lastOverflowScrollTime = SDL_GetTicks();
                 overflowScrollToKeepVisible_InputWidget_(d);
diff --git a/src/ui/root.c b/src/ui/root.c
index 9bbfe0d9..5d3e436d 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -1120,7 +1120,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
     }
     else if (deviceType_App() == tablet_AppDeviceType && equal_Command(cmd, "keyboard.changed")) {
         const int keyboardHeight = arg_Command(cmd);
-        if (focus_Widget() == findChild_Widget(navBar, "url")) {
+        if (focus_Widget() == findChild_Widget(navBar, "url") && prefs_App()->bottomNavBar) {
             setVisualOffset_Widget(navBar, -keyboardHeight + bottomSafeInset_Mobile(),
                                    400, easeOut_AnimFlag | softer_AnimFlag);
         }
diff --git a/src/ui/widget.c b/src/ui/widget.c
index dbf992aa..d1e139e6 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -519,10 +519,10 @@ static size_t numArrangedChildren_Widget_(const iWidget *d) {
 }
 
 static void centerHorizontal_Widget_(iWidget *d) {
-    d->rect.pos.x = ((d->parent ? width_Rect(innerRect_Widget_(d->parent))
-                                : size_Root(d->root).x) -
-                     width_Rect(d->rect)) /
-                    2;
+    const int width          = width_Rect(d->rect);
+    const int containerWidth = d->parent ? width_Rect(innerRect_Widget_(d->parent))
+                                         : size_Root(d->root).x;
+    d->rect.pos.x = (containerWidth - width) / 2;
     TRACE(d, "center horizontally: %d", d->rect.pos.x);
 }
 
@@ -922,6 +922,28 @@ static void notifySizeChanged_Widget_(iWidget *d) {
     }
 }
 
+static void clampCenteredInRoot_Widget_(iWidget *d) {
+    /* When arranging, we don't yet know if centered widgets will end up outside the root
+       area, because the parent sizes and positions may change. */
+    if (d->flags & centerHorizontal_WidgetFlag) {
+        iRect rootRect = safeRect_Root(d->root);
+        iRect bounds = boundsWithoutVisualOffset_Widget(d);
+        if (width_Rect(bounds) <= width_Rect(rootRect)) {
+            int excess = left_Rect(rootRect) - left_Rect(bounds);
+            if (excess > 0) {
+                d->rect.pos.x += excess;
+            }
+            excess = right_Rect(bounds) - right_Rect(rootRect);
+            if (excess > 0) {
+                d->rect.pos.x -= excess;
+            }
+        }
+    }
+    iForEach(ObjectList, i, d->children) {
+        clampCenteredInRoot_Widget_(i.object);
+    }
+}
+
 void arrange_Widget(iWidget *d) {
     if (d) {
 #if !defined (NDEBUG)
@@ -931,6 +953,7 @@ void arrange_Widget(iWidget *d) {
 #endif
         resetArrangement_Widget_(d); /* back to initial default sizes */
         arrange_Widget_(d);
+        clampCenteredInRoot_Widget_(d);
         notifySizeChanged_Widget_(d);
         d->root->didChangeArrangement = iTrue;
     }
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.12/cdiff/1b716d38a4d7355ded5e495fcfb9a0e45e5fc83f
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
57.685572 milliseconds
Gemini-to-HTML Time
0.363935 milliseconds

This content has been proxied by September (ba2dc).