summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-13 19:52:21 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-13 19:52:21 +0300
commit4cf52f29b926a924d838a3158d5c78b3337ee0ee (patch)
treedf72c72e3edccb9ce88136c7caa6d3644b1c8349 /src/ui/util.c
parentaeb65e88297725634a4e55663e2ecc83805d9073 (diff)
Mobile: New selection logic for InputWidget
Touch-based interaction requires a different kind of selection and copy/paste behavior. This isn't done yet; especially multi-line text still needs work.
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 48ed41a6..cfa8152c 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -706,23 +706,36 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
706 setFrameColor_Widget(menu, uiSeparator_ColorId); 706 setFrameColor_Widget(menu, uiSeparator_ColorId);
707 } 707 }
708 iBool haveIcons = iFalse; 708 iBool haveIcons = iFalse;
709 iWidget *horizGroup = NULL;
709 for (size_t i = 0; i < n; ++i) { 710 for (size_t i = 0; i < n; ++i) {
710 const iMenuItem *item = &items[i]; 711 const iMenuItem *item = &items[i];
711 if (!item->label) { 712 if (!item->label) {
712 break; 713 break;
713 } 714 }
714 if (equal_CStr(item->label, "---")) { 715 const char *labelText = item->label;
716 if (!startsWith_CStr(labelText, ">>>")) {
717 horizGroup = NULL;
718 }
719 if (equal_CStr(labelText, "---")) {
715 addChild_Widget(menu, iClob(makeMenuSeparator_())); 720 addChild_Widget(menu, iClob(makeMenuSeparator_()));
716 } 721 }
717 else { 722 else {
718 iBool isInfo = iFalse; 723 iBool isInfo = iFalse;
719 const char *labelText = item->label; 724 if (startsWith_CStr(labelText, ">>>")) {
725 labelText += 3;
726 if (!horizGroup) {
727 horizGroup = makeHDiv_Widget();
728 setFlags_Widget(horizGroup, resizeHeightOfChildren_WidgetFlag, iFalse);
729 setFlags_Widget(horizGroup, arrangeHeight_WidgetFlag, iTrue);
730 addChild_Widget(menu, iClob(horizGroup));
731 }
732 }
720 if (startsWith_CStr(labelText, "```")) { 733 if (startsWith_CStr(labelText, "```")) {
721 labelText += 3; 734 labelText += 3;
722 isInfo = iTrue; 735 isInfo = iTrue;
723 } 736 }
724 iLabelWidget *label = addChildFlags_Widget( 737 iLabelWidget *label = addChildFlags_Widget(
725 menu, 738 horizGroup ? horizGroup : menu,
726 iClob(newKeyMods_LabelWidget(labelText, item->key, item->kmods, item->command)), 739 iClob(newKeyMods_LabelWidget(labelText, item->key, item->kmods, item->command)),
727 noBackground_WidgetFlag | frameless_WidgetFlag | alignLeft_WidgetFlag | 740 noBackground_WidgetFlag | frameless_WidgetFlag | alignLeft_WidgetFlag |
728 drawKey_WidgetFlag | itemFlags); 741 drawKey_WidgetFlag | itemFlags);
@@ -766,6 +779,34 @@ void openMenu_Widget(iWidget *d, iInt2 windowCoord) {
766 openMenuFlags_Widget(d, windowCoord, iTrue); 779 openMenuFlags_Widget(d, windowCoord, iTrue);
767} 780}
768 781
782static void updateMenuItemFonts_Widget_(iWidget *d) {
783 const iBool isPortraitPhone = (deviceType_App() == phone_AppDeviceType && isPortrait_App());
784 const iBool isSlidePanel = (flags_Widget(d) & horizontalOffset_WidgetFlag) != 0;
785 iForEach(ObjectList, i, children_Widget(d)) {
786 if (isInstance_Object(i.object, &Class_LabelWidget)) {
787 iLabelWidget *label = i.object;
788 const iBool isCaution = startsWith_String(text_LabelWidget(label), uiTextCaution_ColorEscape);
789 if (isWrapped_LabelWidget(label)) {
790 continue;
791 }
792 if (deviceType_App() == desktop_AppDeviceType) {
793 setFont_LabelWidget(label, isCaution ? uiLabelBold_FontId : uiLabel_FontId);
794 }
795 else if (isPortraitPhone) {
796 if (!isSlidePanel) {
797 setFont_LabelWidget(label, isCaution ? defaultBigBold_FontId : defaultBig_FontId);
798 }
799 }
800 else {
801 setFont_LabelWidget(label, isCaution ? uiContentBold_FontId : uiContent_FontId);
802 }
803 }
804 else if (childCount_Widget(i.object)) {
805 updateMenuItemFonts_Widget_(i.object);
806 }
807 }
808}
809
769void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) { 810void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
770 const iRect rootRect = rect_Root(d->root); 811 const iRect rootRect = rect_Root(d->root);
771 const iInt2 rootSize = rootRect.size; 812 const iInt2 rootSize = rootRect.size;
@@ -788,28 +829,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
788 } 829 }
789 d->rect.size.x = rootSize.x; 830 d->rect.size.x = rootSize.x;
790 } 831 }
791 /* Update item fonts. */ { 832 updateMenuItemFonts_Widget_(d);
792 iForEach(ObjectList, i, children_Widget(d)) {
793 if (isInstance_Object(i.object, &Class_LabelWidget)) {
794 iLabelWidget *label = i.object;
795 const iBool isCaution = startsWith_String(text_LabelWidget(label), uiTextCaution_ColorEscape);
796 if (isWrapped_LabelWidget(label)) {
797 continue;
798 }
799 if (deviceType_App() == desktop_AppDeviceType) {
800 setFont_LabelWidget(label, isCaution ? uiLabelBold_FontId : uiLabel_FontId);
801 }
802 else if (isPortraitPhone) {
803 if (!isSlidePanel) {
804 setFont_LabelWidget(label, isCaution ? defaultBigBold_FontId : defaultBig_FontId);
805 }
806 }
807 else {
808 setFont_LabelWidget(label, isCaution ? uiContentBold_FontId : uiContent_FontId);
809 }
810 }
811 }
812 }
813 arrange_Widget(d); 833 arrange_Widget(d);
814 if (isPortraitPhone) { 834 if (isPortraitPhone) {
815 if (isSlidePanel) { 835 if (isSlidePanel) {