diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-15 14:07:33 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-15 14:07:33 +0300 |
commit | 0f0eef8c4228b06c5388aa4ca9e02ab8efee8273 (patch) | |
tree | 80643db8e0b71328c54277b9c5ccf172772a8f7a /src/ui | |
parent | 6580b4e2c396f2fdfb0fb017ec4249baa2fba5ff (diff) |
Mobile: Minor improvements
Fixed issues: scrollbar goes under toolbar, value input dialog grows too tall, Undo/Select All in the clip menu.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/inputwidget.c | 12 | ||||
-rw-r--r-- | src/ui/scrollwidget.c | 20 | ||||
-rw-r--r-- | src/ui/util.c | 16 |
3 files changed, 43 insertions, 5 deletions
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) { | |||
821 | } | 821 | } |
822 | 822 | ||
823 | void setLineLimits_InputWidget(iInputWidget *d, int minLines, int maxLines) { | 823 | void setLineLimits_InputWidget(iInputWidget *d, int minLines, int maxLines) { |
824 | maxLines = iMax(minLines, maxLines); | ||
824 | if (d->minWrapLines != minLines || d->maxWrapLines != maxLines) { | 825 | if (d->minWrapLines != minLines || d->maxWrapLines != maxLines) { |
825 | d->minWrapLines = minLines; | 826 | d->minWrapLines = minLines; |
826 | d->maxWrapLines = maxLines; | 827 | d->maxWrapLines = maxLines; |
@@ -1895,6 +1896,17 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1895 | paste_InputWidget_(d); | 1896 | paste_InputWidget_(d); |
1896 | return iTrue; | 1897 | return iTrue; |
1897 | } | 1898 | } |
1899 | else if (isCommand_UserEvent(ev, "input.undo") && isEditing_InputWidget_(d)) { | ||
1900 | if (popUndo_InputWidget_(d)) { | ||
1901 | refresh_Widget(w); | ||
1902 | contentsWereChanged_InputWidget_(d); | ||
1903 | } | ||
1904 | return iTrue; | ||
1905 | } | ||
1906 | else if (isCommand_UserEvent(ev, "input.selectall") && isEditing_InputWidget_(d)) { | ||
1907 | selectAll_InputWidget(d); | ||
1908 | return iTrue; | ||
1909 | } | ||
1898 | else if (isCommand_UserEvent(ev, "theme.changed")) { | 1910 | else if (isCommand_UserEvent(ev, "theme.changed")) { |
1899 | if (d->buffered) { | 1911 | if (d->buffered) { |
1900 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | 1912 | 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) { | |||
90 | return iMax(gap_UI * 6, d->thumbSize); | 90 | return iMax(gap_UI * 6, d->thumbSize); |
91 | } | 91 | } |
92 | 92 | ||
93 | static iRect bounds_ScrollWidget_(const iScrollWidget *d) { | ||
94 | const iWidget *w = constAs_Widget(d); | ||
95 | iRect bounds = bounds_Widget(w); | ||
96 | if (deviceType_App() == phone_AppDeviceType && isPortrait_App()) { | ||
97 | /* Account for the hidable toolbar. */ | ||
98 | int toolbarHeight = lineHeight_Text(uiLabelLarge_FontId) + 3 * gap_UI; | ||
99 | int excess = bottom_Rect(bounds) - (bottom_Rect(safeRect_Root(w->root)) - toolbarHeight); | ||
100 | if (excess > 0) { | ||
101 | adjustEdges_Rect(&bounds, 0, 0, -excess, 0); | ||
102 | } | ||
103 | } | ||
104 | return bounds; | ||
105 | } | ||
106 | |||
93 | static iRect thumbRect_ScrollWidget_(const iScrollWidget *d) { | 107 | static iRect thumbRect_ScrollWidget_(const iScrollWidget *d) { |
94 | const iRect bounds = bounds_Widget(constAs_Widget(d)); | 108 | const iRect bounds = bounds_ScrollWidget_(d); |
95 | iRect rect = init_Rect(bounds.pos.x, bounds.pos.y, bounds.size.x, 0); | 109 | iRect rect = init_Rect(bounds.pos.x, bounds.pos.y, bounds.size.x, 0); |
96 | const int total = size_Range(&d->range); | 110 | const int total = size_Range(&d->range); |
97 | if (total > 0) { | 111 | if (total > 0) { |
@@ -181,7 +195,7 @@ static iBool processEvent_ScrollWidget_(iScrollWidget *d, const SDL_Event *ev) { | |||
181 | refresh_Widget(w); | 195 | refresh_Widget(w); |
182 | return iTrue; | 196 | return iTrue; |
183 | case drag_ClickResult: { | 197 | case drag_ClickResult: { |
184 | const iRect bounds = bounds_Widget(w); | 198 | const iRect bounds = bounds_ScrollWidget_(d); |
185 | const int offset = delta_Click(&d->click).y; | 199 | const int offset = delta_Click(&d->click).y; |
186 | const int total = size_Range(&d->range); | 200 | const int total = size_Range(&d->range); |
187 | int dpos = (float) offset / (float) (height_Rect(bounds) - thumbSize_ScrollWidget_(d)) * total; | 201 | 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) { | |||
218 | 232 | ||
219 | static void draw_ScrollWidget_(const iScrollWidget *d) { | 233 | static void draw_ScrollWidget_(const iScrollWidget *d) { |
220 | const iWidget *w = constAs_Widget(d); | 234 | const iWidget *w = constAs_Widget(d); |
221 | const iRect bounds = bounds_Widget(w); | 235 | const iRect bounds = bounds_ScrollWidget_(d); |
222 | const iBool isPressed = (flags_Widget(w) & pressed_WidgetFlag) != 0; | 236 | const iBool isPressed = (flags_Widget(w) & pressed_WidgetFlag) != 0; |
223 | if (bounds.size.x > 0) { | 237 | if (bounds.size.x > 0) { |
224 | iPaint p; | 238 | 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) { | |||
1218 | dlg->rect.size.x = | 1218 | dlg->rect.size.x = |
1219 | iMin(rootSize.x, iMaxi(iMaxi(100 * gap_UI, title->rect.size.x), prompt->rect.size.x)); | 1219 | iMin(rootSize.x, iMaxi(iMaxi(100 * gap_UI, title->rect.size.x), prompt->rect.size.x)); |
1220 | } | 1220 | } |
1221 | /* Adjust the maximum number of visible lines. */ | ||
1222 | int footer = 6 * gap_UI + get_Window()->keyboardHeight; | ||
1223 | iWidget *buttons = findChild_Widget(dlg, "dialogbuttons"); | ||
1224 | if (buttons) { | ||
1225 | footer += height_Widget(buttons); | ||
1226 | } | ||
1227 | iInputWidget *input = findChild_Widget(dlg, "input"); | ||
1228 | setLineLimits_InputWidget(input, | ||
1229 | 1, | ||
1230 | (bottom_Rect(safeRect_Root(dlg->root)) - footer - | ||
1231 | top_Rect(boundsWithoutVisualOffset_Widget(as_Widget(input)))) / | ||
1232 | lineHeight_Text(font_InputWidget(input))); | ||
1221 | } | 1233 | } |
1222 | 1234 | ||
1223 | iBool valueInputHandler_(iWidget *dlg, const char *cmd) { | 1235 | iBool valueInputHandler_(iWidget *dlg, const char *cmd) { |
1224 | iWidget *ptr = as_Widget(pointer_Command(cmd)); | 1236 | iWidget *ptr = as_Widget(pointer_Command(cmd)); |
1225 | if (equal_Command(cmd, "window.resized")) { | 1237 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "keyboard.changed")) { |
1226 | if (isVisible_Widget(dlg)) { | 1238 | if (isVisible_Widget(dlg)) { |
1227 | updateValueInputWidth_(dlg); | 1239 | updateValueInputWidth_(dlg); |
1228 | arrange_Widget(dlg); | 1240 | arrange_Widget(dlg); |
@@ -1357,7 +1369,6 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1357 | setText_InputWidget(input, initialValue); | 1369 | setText_InputWidget(input, initialValue); |
1358 | } | 1370 | } |
1359 | setId_Widget(as_Widget(input), "input"); | 1371 | setId_Widget(as_Widget(input), "input"); |
1360 | updateValueInputWidth_(dlg); | ||
1361 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); | 1372 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); |
1362 | addChild_Widget(dlg, | 1373 | addChild_Widget(dlg, |
1363 | iClob(makeDialogButtons_Widget( | 1374 | iClob(makeDialogButtons_Widget( |
@@ -1379,6 +1390,7 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1379 | dlg->rect.pos.y -= delta; | 1390 | dlg->rect.pos.y -= delta; |
1380 | } | 1391 | } |
1381 | } | 1392 | } |
1393 | updateValueInputWidth_(dlg); | ||
1382 | setupSheetTransition_Mobile(dlg, incoming_TransitionFlag | top_TransitionDir); | 1394 | setupSheetTransition_Mobile(dlg, incoming_TransitionFlag | top_TransitionDir); |
1383 | return dlg; | 1395 | return dlg; |
1384 | } | 1396 | } |