diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-16 13:21:36 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-16 13:21:36 +0300 |
commit | 97f9a1c9bf49ca67fe1f99c57aa70e0bdf64a466 (patch) | |
tree | b680da6408f78c4555edf3f6b9e86c6ce8925a53 /src/ui/root.c | |
parent | 19f29bc4382b3dfe9d3c21ddabd5501919c76566 (diff) |
Cleanup: Moved mobile UI code to its own file
The mobile UI related code has grown large enough to warrant a separate file.
Also, work-in-progress redo of the Preferences layout so it can be used with landscape as well.
Diffstat (limited to 'src/ui/root.c')
-rw-r--r-- | src/ui/root.c | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/src/ui/root.c b/src/ui/root.c index f37d274d..6cf3f424 100644 --- a/src/ui/root.c +++ b/src/ui/root.c | |||
@@ -469,11 +469,11 @@ static void setReloadLabel_Root_(iRoot *d, iBool animating) { | |||
469 | const iBool isMobile = deviceType_App() != desktop_AppDeviceType; | 469 | const iBool isMobile = deviceType_App() != desktop_AppDeviceType; |
470 | iLabelWidget *label = findChild_Widget(d->widget, "reload"); | 470 | iLabelWidget *label = findChild_Widget(d->widget, "reload"); |
471 | updateTextCStr_LabelWidget( | 471 | updateTextCStr_LabelWidget( |
472 | label, animating ? loadAnimationCStr_() : (isMobile ? pageMenuCStr_ : reloadCStr_)); | 472 | label, animating ? loadAnimationCStr_() : (/*isMobile ? pageMenuCStr_ :*/ reloadCStr_)); |
473 | if (isMobile) { | 473 | // if (isMobile) { |
474 | setCommand_LabelWidget(label, | 474 | // setCommand_LabelWidget(label, |
475 | collectNewCStr_String(animating ? "navigate.reload" : "menu.open")); | 475 | // collectNewCStr_String(animating ? "navigate.reload" : "menu.open")); |
476 | } | 476 | // } |
477 | } | 477 | } |
478 | 478 | ||
479 | static void checkLoadAnimation_Root_(iRoot *d) { | 479 | static void checkLoadAnimation_Root_(iRoot *d) { |
@@ -539,9 +539,12 @@ static iBool willPerformSearchQuery_(const iString *userInput) { | |||
539 | 539 | ||
540 | static void updateUrlInputContentPadding_(iWidget *navBar) { | 540 | static void updateUrlInputContentPadding_(iWidget *navBar) { |
541 | iInputWidget *url = findChild_Widget(navBar, "url"); | 541 | iInputWidget *url = findChild_Widget(navBar, "url"); |
542 | const iWidget *indicators = findChild_Widget(navBar, "url.rightembed"); | 542 | const int lockWidth = width_Widget(findChild_Widget(navBar, "navbar.lock")); |
543 | setContentPadding_InputWidget(url, -1, | 543 | const int indicatorsWidth = width_Widget(findChild_Widget(navBar, "url.rightembed")); |
544 | width_Widget(indicators)); | 544 | /* The indicators widget has a padding that covers the urlButtons area. */ |
545 | setContentPadding_InputWidget(url, | ||
546 | lockWidth - 2 * gap_UI, // * 0.75f, | ||
547 | indicatorsWidth); | ||
545 | } | 548 | } |
546 | 549 | ||
547 | static void showSearchQueryIndicator_(iBool show) { | 550 | static void showSearchQueryIndicator_(iBool show) { |
@@ -588,12 +591,12 @@ static void updateNavBarSize_(iWidget *navBar) { | |||
588 | updateSize_LabelWidget(label); | 591 | updateSize_LabelWidget(label); |
589 | } | 592 | } |
590 | } | 593 | } |
594 | updateUrlInputContentPadding_(navBar); | ||
591 | /* Note that InputWidget uses the `tight` flag to adjust its inner padding. */ | 595 | /* Note that InputWidget uses the `tight` flag to adjust its inner padding. */ |
592 | /* TODO: Is this redundant? See `updateMetrics_Window_()`. */ | 596 | // const int embedButtonWidth = width_Widget(findChild_Widget(navBar, "navbar.lock")); |
593 | const int embedButtonWidth = width_Widget(findChild_Widget(navBar, "navbar.lock")); | 597 | // setContentPadding_InputWidget(findChild_Widget(navBar, "url"), |
594 | setContentPadding_InputWidget(findChild_Widget(navBar, "url"), | 598 | // embedButtonWidth * 0.75f, |
595 | embedButtonWidth * 0.75f, | 599 | // embedButtonWidth * 0.75f); |
596 | embedButtonWidth * 0.75f); | ||
597 | } | 600 | } |
598 | if (isPhone) { | 601 | if (isPhone) { |
599 | static const char *buttons[] = { "navbar.back", "navbar.forward", "navbar.sidebar", | 602 | static const char *buttons[] = { "navbar.back", "navbar.forward", "navbar.sidebar", |
@@ -904,15 +907,19 @@ void updateMetrics_Root(iRoot *d) { | |||
904 | iWidget *url = findChild_Widget(d->widget, "url"); | 907 | iWidget *url = findChild_Widget(d->widget, "url"); |
905 | iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed"); | 908 | iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed"); |
906 | iWidget *embedPad = findChild_Widget(navBar, "url.embedpad"); | 909 | iWidget *embedPad = findChild_Widget(navBar, "url.embedpad"); |
910 | iWidget *urlButtons = findChild_Widget(navBar, "url.buttons"); | ||
907 | setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI); | 911 | setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI); |
908 | navBar->rect.size.y = 0; /* recalculate height based on children (FIXME: shouldn't be needed) */ | 912 | navBar->rect.size.y = 0; /* recalculate height based on children (FIXME: shouldn't be needed) */ |
909 | updateSize_LabelWidget((iLabelWidget *) lock); | 913 | // updateSize_LabelWidget((iLabelWidget *) lock); |
910 | setFixedSize_Widget(embedPad, init_I2(width_Widget(lock) + gap_UI / 2, 1)); | 914 | // updateSize_LabelWidget((iLabelWidget *) findChild_Widget(navBar, "reload")); |
911 | setContentPadding_InputWidget((iInputWidget *) url, width_Widget(lock) * 0.75, | 915 | // arrange_Widget(urlButtons); |
912 | width_Widget(lock) * 0.75); | 916 | setFixedSize_Widget(embedPad, init_I2(width_Widget(urlButtons) + gap_UI / 2, 1)); |
917 | // setContentPadding_InputWidget((iInputWidget *) url, width_Widget(lock) * 0.75, | ||
918 | // width_Widget(lock) * 0.75); | ||
913 | rightEmbed->rect.pos.y = gap_UI; | 919 | rightEmbed->rect.pos.y = gap_UI; |
914 | updatePadding_Root(d); | 920 | updatePadding_Root(d); |
915 | arrange_Widget(d->widget); | 921 | arrange_Widget(d->widget); |
922 | updateUrlInputContentPadding_(navBar); | ||
916 | postRefresh_App(); | 923 | postRefresh_App(); |
917 | } | 924 | } |
918 | 925 | ||
@@ -1060,7 +1067,7 @@ void createUserInterface_Root(iRoot *d) { | |||
1060 | setNoAutoMinHeight_LabelWidget(fprog, iTrue); | 1067 | setNoAutoMinHeight_LabelWidget(fprog, iTrue); |
1061 | addChildFlags_Widget(rightEmbed, | 1068 | addChildFlags_Widget(rightEmbed, |
1062 | iClob(fprog), | 1069 | iClob(fprog), |
1063 | collapse_WidgetFlag | frameless_WidgetFlag | hidden_WidgetFlag); | 1070 | collapse_WidgetFlag | hidden_WidgetFlag | frameless_WidgetFlag); |
1064 | } | 1071 | } |
1065 | /* Download progress indicator is also inside the input field, but hidden normally. */ { | 1072 | /* Download progress indicator is also inside the input field, but hidden normally. */ { |
1066 | iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 ${mb}", NULL); | 1073 | iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 ${mb}", NULL); |
@@ -1069,7 +1076,7 @@ void createUserInterface_Root(iRoot *d) { | |||
1069 | setAlignVisually_LabelWidget(progress, iTrue); | 1076 | setAlignVisually_LabelWidget(progress, iTrue); |
1070 | setNoAutoMinHeight_LabelWidget(progress, iTrue); | 1077 | setNoAutoMinHeight_LabelWidget(progress, iTrue); |
1071 | addChildFlags_Widget( | 1078 | addChildFlags_Widget( |
1072 | rightEmbed, iClob(progress), collapse_WidgetFlag); | 1079 | rightEmbed, iClob(progress), collapse_WidgetFlag | hidden_WidgetFlag); |
1073 | } | 1080 | } |
1074 | /* Pinning indicator. */ { | 1081 | /* Pinning indicator. */ { |
1075 | iLabelWidget *pin = new_LabelWidget(uiTextAction_ColorEscape leftHalf_Icon, NULL); | 1082 | iLabelWidget *pin = new_LabelWidget(uiTextAction_ColorEscape leftHalf_Icon, NULL); |
@@ -1079,39 +1086,44 @@ void createUserInterface_Root(iRoot *d) { | |||
1079 | setNoAutoMinHeight_LabelWidget(pin, iTrue); | 1086 | setNoAutoMinHeight_LabelWidget(pin, iTrue); |
1080 | addChildFlags_Widget(rightEmbed, | 1087 | addChildFlags_Widget(rightEmbed, |
1081 | iClob(pin), | 1088 | iClob(pin), |
1082 | collapse_WidgetFlag | tight_WidgetFlag | frameless_WidgetFlag); | 1089 | collapse_WidgetFlag | hidden_WidgetFlag | tight_WidgetFlag | frameless_WidgetFlag); |
1090 | } | ||
1091 | iWidget *urlButtons = new_Widget(); | ||
1092 | setId_Widget(urlButtons, "url.buttons"); | ||
1093 | setFlags_Widget(urlButtons, embedFlags | arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); | ||
1094 | /* Mobile page menu. */ | ||
1095 | if (deviceType_App() != desktop_AppDeviceType) { | ||
1096 | iLabelWidget *pageMenuButton; | ||
1097 | /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */ | ||
1098 | pageMenuButton = makeMenuButton_LabelWidget(pageMenuCStr_, | ||
1099 | (iMenuItem[]){ | ||
1100 | { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" }, | ||
1101 | { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" }, | ||
1102 | { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" }, | ||
1103 | { "---", 0, 0, NULL }, | ||
1104 | { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, | ||
1105 | { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" }, | ||
1106 | { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" }, | ||
1107 | { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" }, | ||
1108 | { "---", 0, 0, NULL }, | ||
1109 | { "${menu.page.copyurl}", 0, 0, "document.copylink" }, | ||
1110 | { "${menu.page.copysource}", 'c', KMOD_PRIMARY, "copy" }, | ||
1111 | { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" } }, | ||
1112 | 12); | ||
1113 | setId_Widget(as_Widget(pageMenuButton), "pagemenubutton"); | ||
1114 | setFont_LabelWidget(pageMenuButton, uiContentBold_FontId); | ||
1115 | setAlignVisually_LabelWidget(pageMenuButton, iTrue); | ||
1116 | addChildFlags_Widget(urlButtons, iClob(pageMenuButton), embedFlags); | ||
1117 | updateSize_LabelWidget(pageMenuButton); | ||
1083 | } | 1118 | } |
1084 | /* Reload button. */ { | 1119 | /* Reload button. */ { |
1085 | iLabelWidget *reload; | 1120 | iLabelWidget *reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"); |
1086 | if (deviceType_App() == desktop_AppDeviceType) { | ||
1087 | reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"); | ||
1088 | } | ||
1089 | else { | ||
1090 | /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */ | ||
1091 | reload = makeMenuButton_LabelWidget(pageMenuCStr_, | ||
1092 | (iMenuItem[]){ | ||
1093 | { reload_Icon " ${menu.reload}", reload_KeyShortcut, "navigate.reload" }, | ||
1094 | { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" }, | ||
1095 | { "---", 0, 0, NULL }, | ||
1096 | { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" }, | ||
1097 | { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" }, | ||
1098 | { "---", 0, 0, NULL }, | ||
1099 | { pin_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, | ||
1100 | { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" }, | ||
1101 | { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" }, | ||
1102 | { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" }, | ||
1103 | { "---", 0, 0, NULL }, | ||
1104 | { "${menu.page.copyurl}", 0, 0, "document.copylink" }, | ||
1105 | { "${menu.page.copysource}", 'c', KMOD_PRIMARY, "copy" }, | ||
1106 | { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" } }, | ||
1107 | 14); | ||
1108 | setFont_LabelWidget((iLabelWidget *) reload, uiContentBold_FontId); | ||
1109 | setAlignVisually_LabelWidget((iLabelWidget *) reload, iTrue); | ||
1110 | } | ||
1111 | setId_Widget(as_Widget(reload), "reload"); | 1121 | setId_Widget(as_Widget(reload), "reload"); |
1112 | addChildFlags_Widget(as_Widget(url), iClob(reload), embedFlags | moveToParentRightEdge_WidgetFlag); | 1122 | addChildFlags_Widget(urlButtons, iClob(reload), embedFlags); |
1113 | updateSize_LabelWidget(reload); | 1123 | updateSize_LabelWidget(reload); |
1114 | } | 1124 | } |
1125 | addChildFlags_Widget(as_Widget(url), iClob(urlButtons), moveToParentRightEdge_WidgetFlag); | ||
1126 | arrange_Widget(urlButtons); | ||
1115 | setId_Widget(addChild_Widget(rightEmbed, iClob(makePadding_Widget(0))), "url.embedpad"); | 1127 | setId_Widget(addChild_Widget(rightEmbed, iClob(makePadding_Widget(0))), "url.embedpad"); |
1116 | } | 1128 | } |
1117 | if (deviceType_App() != desktop_AppDeviceType) { | 1129 | if (deviceType_App() != desktop_AppDeviceType) { |