diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-08 17:11:56 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-08 17:11:56 +0200 |
commit | fde64385b7cf0a51e471112ce80e6b2d81540e08 (patch) | |
tree | f367f9597b3f5e4c016b27265c60a9b3c6fd1554 /src/ui/util.c | |
parent | 776d917183f179545dbed6888788a8e3c0e5a7a7 (diff) |
Mobile: SmoothScroll pull flags; menu and value input sizing
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 097eb548..6e139856 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -480,6 +480,7 @@ void init_SmoothScroll(iSmoothScroll *d, iWidget *owner, iSmoothScrollNotifyFunc | |||
480 | d->widget = owner; | 480 | d->widget = owner; |
481 | d->notify = notify; | 481 | d->notify = notify; |
482 | d->pullActionTriggered = 0; | 482 | d->pullActionTriggered = 0; |
483 | d->flags = 0; | ||
483 | } | 484 | } |
484 | 485 | ||
485 | void reset_SmoothScroll(iSmoothScroll *d) { | 486 | void reset_SmoothScroll(iSmoothScroll *d) { |
@@ -550,7 +551,7 @@ void moveSpan_SmoothScroll(iSmoothScroll *d, int offset, uint32_t span) { | |||
550 | } | 551 | } |
551 | #endif | 552 | #endif |
552 | int destY = targetValue_Anim(&d->pos) + offset; | 553 | int destY = targetValue_Anim(&d->pos) + offset; |
553 | if (destY < -pullActionThreshold_SmoothScroll_(d)) { | 554 | if (d->flags & pullDownAction_SmoothScrollFlag && destY < -pullActionThreshold_SmoothScroll_(d)) { |
554 | if (d->pullActionTriggered == 0) { | 555 | if (d->pullActionTriggered == 0) { |
555 | d->pullActionTriggered = iTrue; | 556 | d->pullActionTriggered = iTrue; |
556 | #if defined (iPlatformAppleMobile) | 557 | #if defined (iPlatformAppleMobile) |
@@ -764,12 +765,13 @@ void makeMenuItems_Widget(iWidget *menu, const iMenuItem *items, size_t n) { | |||
764 | drawKey_WidgetFlag | itemFlags); | 765 | drawKey_WidgetFlag | itemFlags); |
765 | setWrap_LabelWidget(label, isInfo); | 766 | setWrap_LabelWidget(label, isInfo); |
766 | haveIcons |= checkIcon_LabelWidget(label); | 767 | haveIcons |= checkIcon_LabelWidget(label); |
767 | updateSize_LabelWidget(label); /* drawKey was set */ | ||
768 | setFlags_Widget(as_Widget(label), disabled_WidgetFlag, isDisabled); | 768 | setFlags_Widget(as_Widget(label), disabled_WidgetFlag, isDisabled); |
769 | if (isInfo) { | 769 | if (isInfo) { |
770 | setFlags_Widget(as_Widget(label), fixedHeight_WidgetFlag, iTrue); /* wrap changes height */ | 770 | setFlags_Widget(as_Widget(label), resizeToParentWidth_WidgetFlag | |
771 | fixedHeight_WidgetFlag, iTrue); /* wrap changes height */ | ||
771 | setTextColor_LabelWidget(label, uiTextAction_ColorId); | 772 | setTextColor_LabelWidget(label, uiTextAction_ColorId); |
772 | } | 773 | } |
774 | updateSize_LabelWidget(label); /* drawKey was set */ | ||
773 | } | 775 | } |
774 | } | 776 | } |
775 | if (deviceType_App() == phone_AppDeviceType) { | 777 | if (deviceType_App() == phone_AppDeviceType) { |
@@ -1051,7 +1053,8 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1051 | #else | 1053 | #else |
1052 | const iRect rootRect = rect_Root(d->root); | 1054 | const iRect rootRect = rect_Root(d->root); |
1053 | const iInt2 rootSize = rootRect.size; | 1055 | const iInt2 rootSize = rootRect.size; |
1054 | const iBool isPortraitPhone = (deviceType_App() == phone_AppDeviceType && isPortrait_App()); | 1056 | const iBool isPhone = (deviceType_App() == phone_AppDeviceType); |
1057 | const iBool isPortraitPhone = (isPhone && isPortrait_App()); | ||
1055 | const iBool isSlidePanel = (flags_Widget(d) & horizontalOffset_WidgetFlag) != 0; | 1058 | const iBool isSlidePanel = (flags_Widget(d) & horizontalOffset_WidgetFlag) != 0; |
1056 | if (postCommands) { | 1059 | if (postCommands) { |
1057 | postCommand_App("cancel"); /* dismiss any other menus */ | 1060 | postCommand_App("cancel"); /* dismiss any other menus */ |
@@ -1139,16 +1142,14 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1139 | raise_Widget(d); | 1142 | raise_Widget(d); |
1140 | if (deviceType_App() != desktop_AppDeviceType) { | 1143 | if (deviceType_App() != desktop_AppDeviceType) { |
1141 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, | 1144 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, |
1142 | !isPortraitPhone); | 1145 | !isPhone); |
1143 | setFlags_Widget(d, | 1146 | setFlags_Widget(d, |
1144 | resizeWidthOfChildren_WidgetFlag | drawBackgroundToBottom_WidgetFlag | | 1147 | resizeWidthOfChildren_WidgetFlag | drawBackgroundToBottom_WidgetFlag | |
1145 | drawBackgroundToVerticalSafeArea_WidgetFlag, | 1148 | drawBackgroundToVerticalSafeArea_WidgetFlag, |
1146 | isPortraitPhone); | 1149 | isPhone); |
1147 | if (isPortraitPhone) { | 1150 | if (isPhone) { |
1148 | if (!isSlidePanel) { | 1151 | setFlags_Widget(d, borderTop_WidgetFlag, !isSlidePanel && isPortrait_App()); /* menu is otherwise frameless */ |
1149 | setFlags_Widget(d, borderTop_WidgetFlag, iTrue); | 1152 | setFixedSize_Widget(d, init_I2(iMin(rootSize.x, rootSize.y), -1)); |
1150 | } | ||
1151 | d->rect.size.x = rootSize.x; | ||
1152 | } | 1153 | } |
1153 | else { | 1154 | else { |
1154 | d->rect.size.x = 0; | 1155 | d->rect.size.x = 0; |
@@ -1156,12 +1157,18 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1156 | } | 1157 | } |
1157 | updateMenuItemFonts_Widget_(d); | 1158 | updateMenuItemFonts_Widget_(d); |
1158 | arrange_Widget(d); | 1159 | arrange_Widget(d); |
1159 | if (isPortraitPhone) { | 1160 | if (!isSlidePanel) { |
1161 | /* LAYOUT BUG: Height of wrapped menu items is incorrect with a single arrange! */ | ||
1162 | arrange_Widget(d); | ||
1163 | } | ||
1164 | if (deviceType_App() == phone_AppDeviceType) { | ||
1160 | if (isSlidePanel) { | 1165 | if (isSlidePanel) { |
1161 | d->rect.pos = zero_I2(); | 1166 | d->rect.pos = zero_I2(); |
1162 | } | 1167 | } |
1163 | else { | 1168 | else { |
1164 | d->rect.pos = init_I2(0, rootSize.y); | 1169 | d->rect.pos = windowToLocal_Widget(d, |
1170 | init_I2(rootSize.x / 2 - d->rect.size.x / 2, | ||
1171 | rootSize.y)); | ||
1165 | } | 1172 | } |
1166 | } | 1173 | } |
1167 | else if (menuOpenFlags & center_MenuOpenFlags) { | 1174 | else if (menuOpenFlags & center_MenuOpenFlags) { |
@@ -1638,7 +1645,7 @@ static void acceptValueInput_(iWidget *dlg) { | |||
1638 | } | 1645 | } |
1639 | } | 1646 | } |
1640 | 1647 | ||
1641 | static void updateValueInputWidth_(iWidget *dlg) { | 1648 | static void updateValueInputSizing_(iWidget *dlg) { |
1642 | const iRect safeRoot = safeRect_Root(dlg->root); | 1649 | const iRect safeRoot = safeRect_Root(dlg->root); |
1643 | const iInt2 rootSize = safeRoot.size; | 1650 | const iInt2 rootSize = safeRoot.size; |
1644 | iWidget * title = findChild_Widget(dlg, "valueinput.title"); | 1651 | iWidget * title = findChild_Widget(dlg, "valueinput.title"); |
@@ -1651,20 +1658,15 @@ static void updateValueInputWidth_(iWidget *dlg) { | |||
1651 | iMin(rootSize.x, iMaxi(iMaxi(100 * gap_UI, title->rect.size.x), prompt->rect.size.x)); | 1658 | iMin(rootSize.x, iMaxi(iMaxi(100 * gap_UI, title->rect.size.x), prompt->rect.size.x)); |
1652 | } | 1659 | } |
1653 | /* Adjust the maximum number of visible lines. */ | 1660 | /* Adjust the maximum number of visible lines. */ |
1654 | int footer = 6 * gap_UI + get_MainWindow()->keyboardHeight; | 1661 | int footer = 6 * gap_UI; |
1655 | #if defined (iPlatformAppleMobile) | ||
1656 | if (deviceType_App() == phone_AppDeviceType) { | ||
1657 | footer -= 12 * gap_UI; /* A little suspect, this... Check the math? */ | ||
1658 | } | ||
1659 | #endif | ||
1660 | iWidget *buttons = findChild_Widget(dlg, "dialogbuttons"); | 1662 | iWidget *buttons = findChild_Widget(dlg, "dialogbuttons"); |
1661 | if (buttons) { | 1663 | if (buttons && deviceType_App() == desktop_AppDeviceType) { |
1662 | footer += height_Widget(buttons); | 1664 | footer += height_Widget(buttons); |
1663 | } | 1665 | } |
1664 | iInputWidget *input = findChild_Widget(dlg, "input"); | 1666 | iInputWidget *input = findChild_Widget(dlg, "input"); |
1665 | setLineLimits_InputWidget(input, | 1667 | setLineLimits_InputWidget(input, |
1666 | 1, | 1668 | 1, |
1667 | (bottom_Rect(safeRect_Root(dlg->root)) - footer - | 1669 | (bottom_Rect(visibleRect_Root(dlg->root)) - footer - |
1668 | top_Rect(boundsWithoutVisualOffset_Widget(as_Widget(input)))) / | 1670 | top_Rect(boundsWithoutVisualOffset_Widget(as_Widget(input)))) / |
1669 | lineHeight_Text(font_InputWidget(input))); | 1671 | lineHeight_Text(font_InputWidget(input))); |
1670 | } | 1672 | } |
@@ -1673,7 +1675,7 @@ iBool valueInputHandler_(iWidget *dlg, const char *cmd) { | |||
1673 | iWidget *ptr = as_Widget(pointer_Command(cmd)); | 1675 | iWidget *ptr = as_Widget(pointer_Command(cmd)); |
1674 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "keyboard.changed")) { | 1676 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "keyboard.changed")) { |
1675 | if (isVisible_Widget(dlg)) { | 1677 | if (isVisible_Widget(dlg)) { |
1676 | updateValueInputWidth_(dlg); | 1678 | updateValueInputSizing_(dlg); |
1677 | arrange_Widget(dlg); | 1679 | arrange_Widget(dlg); |
1678 | } | 1680 | } |
1679 | return iFalse; | 1681 | return iFalse; |
@@ -1847,7 +1849,7 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1847 | dlg->rect.pos.y -= delta; | 1849 | dlg->rect.pos.y -= delta; |
1848 | } | 1850 | } |
1849 | } | 1851 | } |
1850 | updateValueInputWidth_(dlg); | 1852 | updateValueInputSizing_(dlg); |
1851 | setupSheetTransition_Mobile(dlg, incoming_TransitionFlag | top_TransitionDir); | 1853 | setupSheetTransition_Mobile(dlg, incoming_TransitionFlag | top_TransitionDir); |
1852 | return dlg; | 1854 | return dlg; |
1853 | } | 1855 | } |
@@ -1855,7 +1857,7 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1855 | void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) { | 1857 | void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) { |
1856 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.title"), title); | 1858 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.title"), title); |
1857 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.prompt"), prompt); | 1859 | setTextCStr_LabelWidget(findChild_Widget(d, "valueinput.prompt"), prompt); |
1858 | updateValueInputWidth_(d); | 1860 | updateValueInputSizing_(d); |
1859 | } | 1861 | } |
1860 | 1862 | ||
1861 | static void updateQuestionWidth_(iWidget *dlg) { | 1863 | static void updateQuestionWidth_(iWidget *dlg) { |