Lagrange [dev]

TUI: UI behavior and layout tweaks

=> 96f1c1eb9ce3484606c60ff00c52785a77d47c21

diff --git a/src/app.c b/src/app.c
index e17d78fd..8345657b 100644
--- a/src/app.c
+++ b/src/app.c
@@ -2234,6 +2234,13 @@ void processEvents_App(enum iAppEventMode eventMode) {
                         wasUsed = iTrue;
                     }
                 }
+                if (!wasUsed && ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_ESCAPE &&
+                    current_Root() && focus_Widget() &&
+                    focusRoot_Widget(focus_Widget()) == get_Root()->widget) {
+                    /* Pressing Escape will clear focus. */
+                    setFocus_Widget(NULL);
+                    wasUsed = iTrue;
+                }
                 if (!wasUsed) {
                     /* ^G is an alternative for Escape. */
                     if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == 'g' &&
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index a9716c08..3ca52773 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -4594,7 +4594,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
                                     { "---", 0, 0, NULL } },
                                 4);
                     }
-#if defined (iPlatformApple) && defined (LAGRANGE_ENABLE_MAC_MENUS)
+#if (defined (iPlatformApple) && defined (LAGRANGE_ENABLE_MAC_MENUS)) || defined (iPlatformTerminal)
                     pushBackN_Array(
                         &items,
                         (iMenuItem[]){
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 00237f6f..809c986f 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -81,6 +81,9 @@ static iInt2 padding_LabelWidget_(const iLabelWidget *d, int corner) {
             widgetPad.x += gap_UI * 5;
         }
     }
+    if (isTerminal_Platform()) {
+        return add_I2(widgetPad, init_I2(1 + (d->icon ? 1 : 0), 0));
+    }
     if (isMobile_Platform()) {
         return add_I2(widgetPad,
                       init_I2(flags & tight_WidgetFlag ? 2 * gap_UI : (4 * gap_UI),
diff --git a/src/ui/root.c b/src/ui/root.c
index b467dd9b..00817c97 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -524,8 +524,13 @@ iBool handleRootCommands_Widget(iWidget *root, const char *cmd) {
     else if (equal_Command(cmd, "menubar.focus")) {
         iWidget *menubar = findWidget_App("menubar");
         if (menubar) {
-            setFocus_Widget(child_Widget(menubar, 0));
-            postCommand_Widget(focus_Widget(), "trigger");
+            if (focus_Widget() && hasParent_Widget(focus_Widget(), menubar)) {
+                setFocus_Widget(NULL);
+            }
+            else {
+                setFocus_Widget(child_Widget(menubar, 0));
+                postCommand_Widget(focus_Widget(), "trigger");
+            }
         }
         return iTrue;
     }
diff --git a/src/ui/scrollwidget.c b/src/ui/scrollwidget.c
index 0e0d8485..24cbc178 100644
--- a/src/ui/scrollwidget.c
+++ b/src/ui/scrollwidget.c
@@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 iDefineObjectConstruction(ScrollWidget)
 
 #if defined (iPlatformTerminal)
-const int fadeTime_ScrollWidget_   = 10;
-const int unfadeTime_ScrollWidget_ = 10;
+const int fadeTime_ScrollWidget_   = 1;
+const int unfadeTime_ScrollWidget_ = 1;
 #else
 const int fadeTime_ScrollWidget_   = 200;
 const int unfadeTime_ScrollWidget_ = 66;
diff --git a/src/ui/util.c b/src/ui/util.c
index e9ef5ebf..5d9ec625 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1797,6 +1797,9 @@ int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) {
 
 iLabelWidget *makeMenuButton_LabelWidget(const char *label, const iMenuItem *items, size_t n) {
     iLabelWidget *button = new_LabelWidget(label, "menu.open");
+    if (isTerminal_Platform()) {
+        setFlags_Widget(as_Widget(button), tight_WidgetFlag, iTrue);
+    }
     iWidget *menu = makeMenuFlags_Widget(as_Widget(button), items, n, iTrue /* allow native */);
     setFrameColor_Widget(menu, uiBackgroundSelected_ColorId);
     setId_Widget(menu, "menu");
@@ -2100,6 +2103,9 @@ static void addTabPage_Widget_(iWidget *tabs, enum iWidgetAddPos addPos, iWidget
         iClob(newKeyMods_LabelWidget(label, key, kmods, format_CStr("tabs.switch page:%p", page))),
         addPos);
     checkIcon_LabelWidget((iLabelWidget *) button);
+    if (isTerminal_Platform()) {
+        setIcon_LabelWidget((iLabelWidget *) button, 0); /* no icon in the terminal (lack of room) */
+    }
     setFlags_Widget(button, selected_WidgetFlag, isSel);
     setFlags_Widget(button,
                     commandOnClick_WidgetFlag |
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/dev/cdiff/96f1c1eb9ce3484606c60ff00c52785a77d47c21
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
30.078252 milliseconds
Gemini-to-HTML Time
0.328707 milliseconds

This content has been proxied by September (3851b).