summaryrefslogtreecommitdiff
path: root/src/ui/root.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-27 13:25:44 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-27 13:25:44 +0300
commit379c1f8befcc30b72f0b50dcbd653704348e4761 (patch)
treea43c0d30f39e592237bf7f3b9c8fca26434128d0 /src/ui/root.c
parent3846778c99d9efca609b7cb216cb71c675f036b0 (diff)
UI root sizing is independent of window sizing
Diffstat (limited to 'src/ui/root.c')
-rw-r--r--src/ui/root.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index bd7d07a1..375107c9 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -522,14 +522,14 @@ static int navBarAvailableSpace_(iWidget *navBar) {
522 return avail; 522 return avail;
523} 523}
524 524
525iBool isNarrow_Window(const iWindow *d) { 525iBool isNarrow_Root(const iRoot *d) {
526 return width_Rect(safeRootRect_Window(d)) / gap_UI < 140; 526 return width_Rect(safeRect_Root(d)) / gap_UI < 140;
527} 527}
528 528
529static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { 529static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
530 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "metrics.changed")) { 530 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "metrics.changed")) {
531 const iBool isPhone = deviceType_App() == phone_AppDeviceType; 531 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
532 const iBool isNarrow = !isPhone && isNarrow_Window(get_Window()); 532 const iBool isNarrow = !isPhone && isNarrow_Root(get_Root());
533 /* Adjust navbar padding. */ { 533 /* Adjust navbar padding. */ {
534 int hPad = isPhone && isPortrait_App() ? 0 : (isPhone || isNarrow) ? gap_UI / 2 534 int hPad = isPhone && isPortrait_App() ? 0 : (isPhone || isNarrow) ? gap_UI / 2
535 : gap_UI * 3 / 2; 535 : gap_UI * 3 / 2;
@@ -769,7 +769,7 @@ static iBool handleToolBarCommands_(iWidget *toolBar, const char *cmd) {
769 // setFlags_Widget(findChild_Widget(toolBar, "toolbar.view"), noBackground_WidgetFlag, 769 // setFlags_Widget(findChild_Widget(toolBar, "toolbar.view"), noBackground_WidgetFlag,
770 // isVisible); 770 // isVisible);
771 /* If a sidebar hasn't been shown yet, it's height is zero. */ 771 /* If a sidebar hasn't been shown yet, it's height is zero. */
772 const int viewHeight = rootSize_Window(get_Window()).y; 772 const int viewHeight = size_Root(get_Root()).y;
773 if (arg_Command(cmd) >= 0) { 773 if (arg_Command(cmd) >= 0) {
774 postCommandf_App("sidebar.mode arg:%d show:1", arg_Command(cmd)); 774 postCommandf_App("sidebar.mode arg:%d show:1", arg_Command(cmd));
775 if (!isVisible) { 775 if (!isVisible) {
@@ -798,14 +798,14 @@ static iBool handleToolBarCommands_(iWidget *toolBar, const char *cmd) {
798 // setFlags_Widget(findChild_Widget(toolBar, "toolbar.ident"), noBackground_WidgetFlag, 798 // setFlags_Widget(findChild_Widget(toolBar, "toolbar.ident"), noBackground_WidgetFlag,
799 // isVisible); 799 // isVisible);
800 /* If a sidebar hasn't been shown yet, it's height is zero. */ 800 /* If a sidebar hasn't been shown yet, it's height is zero. */
801 const int viewHeight = rootSize_Window(get_Window()).y; 801 const int viewHeight = size_Root(get_Root()).y;
802 if (isVisible) { 802 if (isVisible) {
803 dismissSidebar_(sidebar2, NULL); 803 dismissSidebar_(sidebar2, NULL);
804 } 804 }
805 else { 805 else {
806 postCommand_App("sidebar2.mode arg:3 show:1"); 806 postCommand_App("sidebar2.mode arg:3 show:1");
807 int offset = height_Widget(sidebar2); 807 int offset = height_Widget(sidebar2);
808 if (offset == 0) offset = rootSize_Window(get_Window()).y; 808 if (offset == 0) offset = size_Root(get_Root()).y;
809 setVisualOffset_Widget(sidebar2, offset, 0, 0); 809 setVisualOffset_Widget(sidebar2, offset, 0, 0);
810 setVisualOffset_Widget(sidebar2, 0, 400, easeOut_AnimFlag | softer_AnimFlag); 810 setVisualOffset_Widget(sidebar2, 0, 400, easeOut_AnimFlag | softer_AnimFlag);
811 } 811 }
@@ -1240,7 +1240,7 @@ void showToolbars_Root(iRoot *d, iBool show) {
1240 if (isLandscape_App()) return; 1240 if (isLandscape_App()) return;
1241 iWidget *toolBar = findChild_Widget(d->widget, "toolbar"); 1241 iWidget *toolBar = findChild_Widget(d->widget, "toolbar");
1242 if (!toolBar) return; 1242 if (!toolBar) return;
1243 const int height = rootSize_Window(get_Window()).y - top_Rect(boundsWithoutVisualOffset_Widget(toolBar)); 1243 const int height = size_Root(d).y - top_Rect(boundsWithoutVisualOffset_Widget(toolBar));
1244 if (show && !isVisible_Widget(toolBar)) { 1244 if (show && !isVisible_Widget(toolBar)) {
1245 setFlags_Widget(toolBar, hidden_WidgetFlag, iFalse); 1245 setFlags_Widget(toolBar, hidden_WidgetFlag, iFalse);
1246 setVisualOffset_Widget(toolBar, 0, 200, easeOut_AnimFlag); 1246 setVisualOffset_Widget(toolBar, 0, 200, easeOut_AnimFlag);
@@ -1254,3 +1254,27 @@ void showToolbars_Root(iRoot *d, iBool show) {
1254 } 1254 }
1255} 1255}
1256 1256
1257iInt2 size_Root(const iRoot *d) {
1258 return d && d->widget ? d->widget->rect.size : zero_I2();
1259}
1260
1261iRect rect_Root(const iRoot *d) {
1262 if (d && d->widget) {
1263 return d->widget->rect;
1264 }
1265 return zero_Rect();
1266}
1267
1268iRect safeRect_Root(const iRoot *d) {
1269 iRect rect = { zero_I2(), size_Root(d) };
1270#if defined (iPlatformAppleMobile)
1271 float left, top, right, bottom;
1272 safeAreaInsets_iOS(&left, &top, &right, &bottom);
1273 adjustEdges_Rect(&rect, top, -right, -bottom, left);
1274#endif
1275 return rect;
1276}
1277
1278iInt2 visibleSize_Root(const iRoot *d) {
1279 return addY_I2(size_Root(d), -get_Window()->keyboardHeight);
1280}