From 0f0eef8c4228b06c5388aa4ca9e02ab8efee8273 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 15 Sep 2021 14:07:33 +0300 Subject: Mobile: Minor improvements Fixed issues: scrollbar goes under toolbar, value input dialog grows too tall, Undo/Select All in the clip menu. --- src/app.c | 3 +++ src/ui/inputwidget.c | 12 ++++++++++++ src/ui/scrollwidget.c | 20 +++++++++++++++++--- src/ui/util.c | 16 ++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 37f9c804..ed72c450 100644 --- a/src/app.c +++ b/src/app.c @@ -2756,6 +2756,9 @@ iBool handleCommand_App(const char *cmd) { else if (equal_Command(cmd, "document.changed")) { /* Set of open tabs has changed. */ postCommand_App("document.openurls.changed"); + if (deviceType_App() == phone_AppDeviceType) { + showToolbar_Root(d->window->roots[0], iTrue); + } return iFalse; } else if (equal_Command(cmd, "ident.new")) { diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 146b46b6..c8010fc6 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -821,6 +821,7 @@ void setMaxLen_InputWidget(iInputWidget *d, size_t maxLen) { } void setLineLimits_InputWidget(iInputWidget *d, int minLines, int maxLines) { + maxLines = iMax(minLines, maxLines); if (d->minWrapLines != minLines || d->maxWrapLines != maxLines) { d->minWrapLines = minLines; d->maxWrapLines = maxLines; @@ -1895,6 +1896,17 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { paste_InputWidget_(d); return iTrue; } + else if (isCommand_UserEvent(ev, "input.undo") && isEditing_InputWidget_(d)) { + if (popUndo_InputWidget_(d)) { + refresh_Widget(w); + contentsWereChanged_InputWidget_(d); + } + return iTrue; + } + else if (isCommand_UserEvent(ev, "input.selectall") && isEditing_InputWidget_(d)) { + selectAll_InputWidget(d); + return iTrue; + } else if (isCommand_UserEvent(ev, "theme.changed")) { if (d->buffered) { d->inFlags |= needUpdateBuffer_InputWidgetFlag; diff --git a/src/ui/scrollwidget.c b/src/ui/scrollwidget.c index 0bab601a..b6f73b6c 100644 --- a/src/ui/scrollwidget.c +++ b/src/ui/scrollwidget.c @@ -90,8 +90,22 @@ static int thumbSize_ScrollWidget_(const iScrollWidget *d) { return iMax(gap_UI * 6, d->thumbSize); } +static iRect bounds_ScrollWidget_(const iScrollWidget *d) { + const iWidget *w = constAs_Widget(d); + iRect bounds = bounds_Widget(w); + if (deviceType_App() == phone_AppDeviceType && isPortrait_App()) { + /* Account for the hidable toolbar. */ + int toolbarHeight = lineHeight_Text(uiLabelLarge_FontId) + 3 * gap_UI; + int excess = bottom_Rect(bounds) - (bottom_Rect(safeRect_Root(w->root)) - toolbarHeight); + if (excess > 0) { + adjustEdges_Rect(&bounds, 0, 0, -excess, 0); + } + } + return bounds; +} + static iRect thumbRect_ScrollWidget_(const iScrollWidget *d) { - const iRect bounds = bounds_Widget(constAs_Widget(d)); + const iRect bounds = bounds_ScrollWidget_(d); iRect rect = init_Rect(bounds.pos.x, bounds.pos.y, bounds.size.x, 0); const int total = size_Range(&d->range); if (total > 0) { @@ -181,7 +195,7 @@ static iBool processEvent_ScrollWidget_(iScrollWidget *d, const SDL_Event *ev) { refresh_Widget(w); return iTrue; case drag_ClickResult: { - const iRect bounds = bounds_Widget(w); + const iRect bounds = bounds_ScrollWidget_(d); const int offset = delta_Click(&d->click).y; const int total = size_Range(&d->range); int dpos = (float) offset / (float) (height_Rect(bounds) - thumbSize_ScrollWidget_(d)) * total; @@ -218,7 +232,7 @@ static iBool processEvent_ScrollWidget_(iScrollWidget *d, const SDL_Event *ev) { static void draw_ScrollWidget_(const iScrollWidget *d) { const iWidget *w = constAs_Widget(d); - const iRect bounds = bounds_Widget(w); + const iRect bounds = bounds_ScrollWidget_(d); const iBool isPressed = (flags_Widget(w) & pressed_WidgetFlag) != 0; if (bounds.size.x > 0) { iPaint p; diff --git a/src/ui/util.c b/src/ui/util.c index cfa8152c..eb3d1cf2 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1218,11 +1218,23 @@ static void updateValueInputWidth_(iWidget *dlg) { dlg->rect.size.x = iMin(rootSize.x, iMaxi(iMaxi(100 * gap_UI, title->rect.size.x), prompt->rect.size.x)); } + /* Adjust the maximum number of visible lines. */ + int footer = 6 * gap_UI + get_Window()->keyboardHeight; + iWidget *buttons = findChild_Widget(dlg, "dialogbuttons"); + if (buttons) { + footer += height_Widget(buttons); + } + iInputWidget *input = findChild_Widget(dlg, "input"); + setLineLimits_InputWidget(input, + 1, + (bottom_Rect(safeRect_Root(dlg->root)) - footer - + top_Rect(boundsWithoutVisualOffset_Widget(as_Widget(input)))) / + lineHeight_Text(font_InputWidget(input))); } iBool valueInputHandler_(iWidget *dlg, const char *cmd) { iWidget *ptr = as_Widget(pointer_Command(cmd)); - if (equal_Command(cmd, "window.resized")) { + if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "keyboard.changed")) { if (isVisible_Widget(dlg)) { updateValueInputWidth_(dlg); arrange_Widget(dlg); @@ -1357,7 +1369,6 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con setText_InputWidget(input, initialValue); } setId_Widget(as_Widget(input), "input"); - updateValueInputWidth_(dlg); addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); addChild_Widget(dlg, iClob(makeDialogButtons_Widget( @@ -1379,6 +1390,7 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con dlg->rect.pos.y -= delta; } } + updateValueInputWidth_(dlg); setupSheetTransition_Mobile(dlg, incoming_TransitionFlag | top_TransitionDir); return dlg; } -- cgit v1.2.3