summaryrefslogtreecommitdiff
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-20 08:33:15 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-20 08:33:15 +0200
commit0c4fc5d9189510ff88369709f018afc550aa0b54 (patch)
tree88f743ca8e6ab22e8eea781d116cdfc34c8b91d0 /src/ui/window.c
parentc1cc59ee6a6d8b88d6f49eb59ffa871d75c75866 (diff)
iOS: Tweaks and changes for phone mode
Phone mode uses a modified user interface. Work in progress...
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index 38df8682..251eb5c4 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -398,9 +398,21 @@ static void checkLoadAnimation_Window_(iWindow *d) {
398 setReloadLabel_Window_(d, isOngoing); 398 setReloadLabel_Window_(d, isOngoing);
399} 399}
400 400
401static void updatePadding_Window_(iWindow *d) {
402#if defined (iPlatformAppleMobile)
403 /* Respect the safe area insets. */ {
404 float left, top, right, bottom;
405 safeAreaInsets_iOS(&left, &top, &right, &bottom);
406 setPadding_Widget(findChild_Widget(d->root, "navdiv"), left, top, right, 0);
407 setPadding_Widget(findChild_Widget(d->root, "toolbar"), left, 0, right, bottom);
408 }
409#endif
410}
411
401static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { 412static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
402 if (equal_Command(cmd, "window.resized")) { 413 if (equal_Command(cmd, "window.resized")) {
403 const iBool isNarrow = width_Rect(bounds_Widget(navBar)) / gap_UI < 140; 414 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
415 const iBool isNarrow = !isPhone && width_Rect(bounds_Widget(navBar)) / gap_UI < 140;
404 if (isNarrow ^ ((flags_Widget(navBar) & tight_WidgetFlag) != 0)) { 416 if (isNarrow ^ ((flags_Widget(navBar) & tight_WidgetFlag) != 0)) {
405 setFlags_Widget(navBar, tight_WidgetFlag, isNarrow); 417 setFlags_Widget(navBar, tight_WidgetFlag, isNarrow);
406 iForEach(ObjectList, i, navBar->children) { 418 iForEach(ObjectList, i, navBar->children) {
@@ -413,6 +425,14 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
413 } 425 }
414 } 426 }
415 } 427 }
428 if (isPhone) {
429 setFlags_Widget(findWidget_App("toolbar"), hidden_WidgetFlag, isLandscape_App());
430 setFlags_Widget(findWidget_App("navbar.back"), hidden_WidgetFlag, isPortrait_App());
431 setFlags_Widget(findWidget_App("navbar.forward"), hidden_WidgetFlag, isPortrait_App());
432 setFlags_Widget(findWidget_App("navbar.ident"), hidden_WidgetFlag, isPortrait_App());
433 setFlags_Widget(findWidget_App("navbar.home"), hidden_WidgetFlag, isPortrait_App());
434 setFlags_Widget(findWidget_App("navbar.menu"), hidden_WidgetFlag, isPortrait_App());
435 }
416 arrange_Widget(navBar); 436 arrange_Widget(navBar);
417 refresh_Widget(navBar); 437 refresh_Widget(navBar);
418 postCommand_Widget(navBar, "layout.changed id:navbar"); 438 postCommand_Widget(navBar, "layout.changed id:navbar");
@@ -592,11 +612,6 @@ static void setupUserInterface_Window(iWindow *d) {
592 setId_Widget(div, "navdiv"); 612 setId_Widget(div, "navdiv");
593 addChild_Widget(d->root, iClob(div)); 613 addChild_Widget(d->root, iClob(div));
594 614
595#if defined (iPlatformAppleMobile)
596 /* System status bar needs space. */
597 setPadding_Widget(div, 0, 4 * gap_UI, 0, 0);
598#endif
599
600#if defined (LAGRANGE_CUSTOM_FRAME) 615#if defined (LAGRANGE_CUSTOM_FRAME)
601 /* Window title bar. */ 616 /* Window title bar. */
602 if (prefs_App()->customFrame) { 617 if (prefs_App()->customFrame) {
@@ -662,13 +677,12 @@ static void setupUserInterface_Window(iWindow *d) {
662 addChild_Widget(div, iClob(navBar)); 677 addChild_Widget(div, iClob(navBar));
663 setBackgroundColor_Widget(navBar, uiBackground_ColorId); 678 setBackgroundColor_Widget(navBar, uiBackground_ColorId);
664 setCommandHandler_Widget(navBar, handleNavBarCommands_); 679 setCommandHandler_Widget(navBar, handleNavBarCommands_);
665 addChild_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f870", 0, 0, "navigate.back"))); 680 setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f870", 0, 0, "navigate.back")), collapse_WidgetFlag), "navbar.back");
666 addChild_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f872", 0, 0, "navigate.forward"))); 681 setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f872", 0, 0, "navigate.forward")), collapse_WidgetFlag), "navbar.forward");
667 iLabelWidget *idMenu = makeMenuButton_LabelWidget( 682 iLabelWidget *idMenu = makeMenuButton_LabelWidget(
668 "\U0001f464", identityButtonMenuItems_, iElemCount(identityButtonMenuItems_)); 683 "\U0001f464", identityButtonMenuItems_, iElemCount(identityButtonMenuItems_));
669 setAlignVisually_LabelWidget(idMenu, iTrue); 684 setAlignVisually_LabelWidget(idMenu, iTrue);
670 addChild_Widget(navBar, iClob(idMenu)); 685 setId_Widget(addChildFlags_Widget(navBar, iClob(idMenu), collapse_WidgetFlag), "navbar.ident");
671 setId_Widget(as_Widget(idMenu), "navbar.ident");
672 iLabelWidget *lock = 686 iLabelWidget *lock =
673 addChildFlags_Widget(navBar, 687 addChildFlags_Widget(navBar,
674 iClob(newIcon_LabelWidget("\U0001f513", SDLK_i, KMOD_PRIMARY, "document.info")), 688 iClob(newIcon_LabelWidget("\U0001f513", SDLK_i, KMOD_PRIMARY, "document.info")),
@@ -711,14 +725,16 @@ static void setupUserInterface_Window(iWindow *d) {
711 setId_Widget(addChild_Widget( 725 setId_Widget(addChild_Widget(
712 navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), 726 navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))),
713 "reload"); 727 "reload");
714 addChild_Widget(navBar, 728 setId_Widget(addChildFlags_Widget(navBar,
715 iClob(newIcon_LabelWidget( 729 iClob(newIcon_LabelWidget(
716 "\U0001f3e0", SDLK_h, KMOD_PRIMARY | KMOD_SHIFT, "navigate.home"))); 730 "\U0001f3e0", SDLK_h, KMOD_PRIMARY | KMOD_SHIFT, "navigate.home")),
731 collapse_WidgetFlag),
732 "navbar.home");
717#if !defined (iHaveNativeMenus) 733#if !defined (iHaveNativeMenus)
718 iLabelWidget *navMenu = 734 iLabelWidget *navMenu =
719 makeMenuButton_LabelWidget("\U0001d362", navMenuItems_, iElemCount(navMenuItems_)); 735 makeMenuButton_LabelWidget("\U0001d362", navMenuItems_, iElemCount(navMenuItems_));
720 setAlignVisually_LabelWidget(navMenu, iTrue); 736 setAlignVisually_LabelWidget(navMenu, iTrue);
721 addChild_Widget(navBar, iClob(navMenu)); 737 setId_Widget(addChildFlags_Widget(navBar, iClob(navMenu), collapse_WidgetFlag), "navbar.menu");
722#else 738#else
723 insertMenuItems_MacOS("File", 1, fileMenuItems_, iElemCount(fileMenuItems_)); 739 insertMenuItems_MacOS("File", 1, fileMenuItems_, iElemCount(fileMenuItems_));
724 insertMenuItems_MacOS("Edit", 2, editMenuItems_, iElemCount(editMenuItems_)); 740 insertMenuItems_MacOS("Edit", 2, editMenuItems_, iElemCount(editMenuItems_));
@@ -773,6 +789,24 @@ static void setupUserInterface_Window(iWindow *d) {
773 addChild_Widget(searchBar, iClob(newIcon_LabelWidget(" \u2b9d ", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); 789 addChild_Widget(searchBar, iClob(newIcon_LabelWidget(" \u2b9d ", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev")));
774 addChild_Widget(searchBar, iClob(newIcon_LabelWidget("\u2a2f", SDLK_ESCAPE, 0, "find.close"))); 790 addChild_Widget(searchBar, iClob(newIcon_LabelWidget("\u2a2f", SDLK_ESCAPE, 0, "find.close")));
775 } 791 }
792#if defined (iPlatformAppleMobile)
793 /* Bottom toolbar. */
794 if (isPhone_iOS()) {
795 iWidget *toolBar = new_Widget();
796 addChild_Widget(div, iClob(toolBar));
797 setId_Widget(toolBar, "toolbar");
798 setFlags_Widget(toolBar, collapse_WidgetFlag | resizeWidthOfChildren_WidgetFlag |
799 arrangeHeight_WidgetFlag | arrangeHorizontal_WidgetFlag, iTrue);
800 setBackgroundColor_Widget(toolBar, uiBackground_ColorId);
801 addChildFlags_Widget(toolBar, iClob(newLargeIcon_LabelWidget("\U0001f870", "navigate.back")), frameless_WidgetFlag);
802 addChildFlags_Widget(toolBar, iClob(newLargeIcon_LabelWidget("\U0001f872", "navigate.forward")), frameless_WidgetFlag);
803 addChildFlags_Widget(toolBar, iClob(newLargeIcon_LabelWidget("\U0001f464", "sidebar.mode arg:3 show:1")), frameless_WidgetFlag);
804 iLabelWidget *menuButton = makeMenuButton_LabelWidget("\U0001d362", navMenuItems_, iElemCount(navMenuItems_));
805 setFont_LabelWidget(menuButton, uiLabelLarge_FontId);
806 addChildFlags_Widget(toolBar, iClob(menuButton), frameless_WidgetFlag);
807 }
808#endif
809 updatePadding_Window_(d);
776 iWidget *tabsMenu = makeMenu_Widget(d->root, 810 iWidget *tabsMenu = makeMenu_Widget(d->root,
777 (iMenuItem[]){ 811 (iMenuItem[]){
778 { "Close Tab", 0, 0, "tabs.close" }, 812 { "Close Tab", 0, 0, "tabs.close" },
@@ -1195,6 +1229,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
1195 return iTrue; 1229 return iTrue;
1196 } 1230 }
1197 case SDL_WINDOWEVENT_RESIZED: 1231 case SDL_WINDOWEVENT_RESIZED:
1232 updatePadding_Window_(d);
1198 if (d->isMinimized) { 1233 if (d->isMinimized) {
1199 updateRootSize_Window_(d, iTrue); 1234 updateRootSize_Window_(d, iTrue);
1200 return iTrue; 1235 return iTrue;
@@ -1353,7 +1388,7 @@ void draw_Window(iWindow *d) {
1353 /* Clear the window. The clear color is visible as a border around the window 1388 /* Clear the window. The clear color is visible as a border around the window
1354 when the custom frame is being used. */ { 1389 when the custom frame is being used. */ {
1355#if defined (iPlatformAppleMobile) 1390#if defined (iPlatformAppleMobile)
1356 const iColor back = get_Color(uiBackground_ColorId); 1391 const iColor back = get_Color(tmBackground_ColorId);
1357#else 1392#else
1358 const iColor back = get_Color(gotFocus && d->place.snap != maximized_WindowSnap && 1393 const iColor back = get_Color(gotFocus && d->place.snap != maximized_WindowSnap &&
1359 ~winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP 1394 ~winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP