diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-20 13:51:21 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-20 13:51:21 +0300 |
commit | 1323d511ad8f0c2697a8a933c721087197224072 (patch) | |
tree | c6dc47a04ce2961438bf616f30c83b5293aad8fd /src/ui/util.c | |
parent | b504d777ac8e134d7223372cb04468cf1895d3ae (diff) |
Centering widgets and sheet contents
Added a new arrange flag for centering a child horizontally.
The two-column layout in Preferences has expanding vertical paddings so the page contents are vertically centered.
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index a47b33c4..51c83a8b 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -474,9 +474,13 @@ iWidget *removeTabPage_Widget(iWidget *tabs, size_t index) { | |||
474 | void resizeToLargestPage_Widget(iWidget *tabs) { | 474 | void resizeToLargestPage_Widget(iWidget *tabs) { |
475 | arrange_Widget(tabs); | 475 | arrange_Widget(tabs); |
476 | iInt2 largest = zero_I2(); | 476 | iInt2 largest = zero_I2(); |
477 | iConstForEach(ObjectList, i, children_Widget(findChild_Widget(tabs, "tabs.pages"))) { | 477 | iWidget *pages = findChild_Widget(tabs, "tabs.pages"); |
478 | iConstForEach(ObjectList, i, children_Widget(pages)) { | ||
478 | largest = max_I2(largest, ((const iWidget *) i.object)->rect.size); | 479 | largest = max_I2(largest, ((const iWidget *) i.object)->rect.size); |
479 | } | 480 | } |
481 | iForEach(ObjectList, j, children_Widget(pages)) { | ||
482 | setSize_Widget(j.object, largest); | ||
483 | } | ||
480 | setSize_Widget(tabs, addY_I2(largest, height_Widget(findChild_Widget(tabs, "tabs.buttons")))); | 484 | setSize_Widget(tabs, addY_I2(largest, height_Widget(findChild_Widget(tabs, "tabs.buttons")))); |
481 | } | 485 | } |
482 | 486 | ||
@@ -602,16 +606,17 @@ iWidget *makeSheet_Widget(const char *id) { | |||
602 | mouseModal_WidgetFlag | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | | 606 | mouseModal_WidgetFlag | keepOnTop_WidgetFlag | arrangeVertical_WidgetFlag | |
603 | arrangeSize_WidgetFlag, | 607 | arrangeSize_WidgetFlag, |
604 | iTrue); | 608 | iTrue); |
609 | setFlags2_Widget(sheet, centerHorizontal_WidgetFlag2, iTrue); | ||
605 | return sheet; | 610 | return sheet; |
606 | } | 611 | } |
607 | 612 | ||
608 | void centerSheet_Widget(iWidget *sheet) { | 613 | void centerSheet_Widget(iWidget *sheet) { |
609 | arrange_Widget(sheet); | 614 | arrange_Widget(sheet->parent); |
610 | const iInt2 rootSize = rootSize_Window(get_Window()); | 615 | // const iInt2 rootSize = rootSize_Window(get_Window()); |
611 | const iInt2 orig = localCoord_Widget( | 616 | // const iInt2 orig = localCoord_Widget( |
612 | sheet->parent, | 617 | // sheet->parent, |
613 | init_I2(rootSize.x / 2 - sheet->rect.size.x / 2, bounds_Widget(sheet).pos.y)); | 618 | // init_I2(rootSize.x / 2 - sheet->rect.size.x / 2, bounds_Widget(sheet).pos.y)); |
614 | sheet->rect.pos = orig; | 619 | // sheet->rect.pos = orig; |
615 | postRefresh_App(); | 620 | postRefresh_App(); |
616 | } | 621 | } |
617 | 622 | ||
@@ -815,12 +820,17 @@ iWidget *makeToggle_Widget(const char *id) { | |||
815 | static iWidget *appendTwoColumnPage_(iWidget *tabs, const char *title, iWidget **headings, | 820 | static iWidget *appendTwoColumnPage_(iWidget *tabs, const char *title, iWidget **headings, |
816 | iWidget **values) { | 821 | iWidget **values) { |
817 | iWidget *page = new_Widget(); | 822 | iWidget *page = new_Widget(); |
818 | appendTabPage_Widget(tabs, page, title, 0, 0); | 823 | setFlags_Widget(page, arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag | |
819 | setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); | 824 | resizeHeightOfChildren_WidgetFlag, iTrue); |
825 | addChildFlags_Widget(page, iClob(new_Widget()), expand_WidgetFlag); | ||
826 | iWidget *columns = new_Widget(); | ||
827 | addChildFlags_Widget(page, iClob(columns), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | ||
820 | *headings = addChildFlags_Widget( | 828 | *headings = addChildFlags_Widget( |
821 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); | 829 | columns, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); |
822 | *values = addChildFlags_Widget( | 830 | *values = addChildFlags_Widget( |
823 | page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); | 831 | columns, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); |
832 | addChildFlags_Widget(page, iClob(new_Widget()), expand_WidgetFlag); | ||
833 | appendTabPage_Widget(tabs, page, title, 0, 0); | ||
824 | return page; | 834 | return page; |
825 | } | 835 | } |
826 | 836 | ||
@@ -831,7 +841,7 @@ static void makeTwoColumnHeading_(const char *title, iWidget *headings, iWidget | |||
831 | } | 841 | } |
832 | 842 | ||
833 | static void expandInputFieldWidth_(iInputWidget *input) { | 843 | static void expandInputFieldWidth_(iInputWidget *input) { |
834 | iWidget *page = as_Widget(input)->parent->parent->parent; /* tabs > page > values > input */ | 844 | iWidget *page = as_Widget(input)->parent->parent->parent->parent; /* tabs > page > values > input */ |
835 | as_Widget(input)->rect.size.x = | 845 | as_Widget(input)->rect.size.x = |
836 | right_Rect(bounds_Widget(page)) - left_Rect(bounds_Widget(constAs_Widget(input))); | 846 | right_Rect(bounds_Widget(page)) - left_Rect(bounds_Widget(constAs_Widget(input))); |
837 | printf("expand to %s, %d - %d\n", cstr_String(id_Widget(page)), | 847 | printf("expand to %s, %d - %d\n", cstr_String(id_Widget(page)), |