diff options
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 41b8f65c..564cf785 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -438,7 +438,7 @@ iInt2 delta_Click(const iClick *d) { | |||
438 | iWidget *makePadding_Widget(int size) { | 438 | iWidget *makePadding_Widget(int size) { |
439 | iWidget *pad = new_Widget(); | 439 | iWidget *pad = new_Widget(); |
440 | setId_Widget(pad, "padding"); | 440 | setId_Widget(pad, "padding"); |
441 | setSize_Widget(pad, init1_I2(size)); | 441 | setFixedSize_Widget(pad, init1_I2(size)); |
442 | return pad; | 442 | return pad; |
443 | } | 443 | } |
444 | 444 | ||
@@ -463,7 +463,7 @@ iWidget *makeHDiv_Widget(void) { | |||
463 | 463 | ||
464 | iWidget *addAction_Widget(iWidget *parent, int key, int kmods, const char *command) { | 464 | iWidget *addAction_Widget(iWidget *parent, int key, int kmods, const char *command) { |
465 | iLabelWidget *action = newKeyMods_LabelWidget("", key, kmods, command); | 465 | iLabelWidget *action = newKeyMods_LabelWidget("", key, kmods, command); |
466 | setSize_Widget(as_Widget(action), zero_I2()); | 466 | setFixedSize_Widget(as_Widget(action), zero_I2()); |
467 | addChildFlags_Widget(parent, iClob(action), hidden_WidgetFlag); | 467 | addChildFlags_Widget(parent, iClob(action), hidden_WidgetFlag); |
468 | return as_Widget(action); | 468 | return as_Widget(action); |
469 | } | 469 | } |
@@ -856,16 +856,23 @@ iWidget *removeTabPage_Widget(iWidget *tabs, size_t index) { | |||
856 | } | 856 | } |
857 | 857 | ||
858 | void resizeToLargestPage_Widget(iWidget *tabs) { | 858 | void resizeToLargestPage_Widget(iWidget *tabs) { |
859 | // puts("RESIZE TO LARGEST PAGE ..."); | ||
860 | iWidget *pages = findChild_Widget(tabs, "tabs.pages"); | ||
861 | iForEach(ObjectList, i, children_Widget(pages)) { | ||
862 | setMinSize_Widget(i.object, zero_I2()); | ||
863 | // resetSize_Widget(i.object); | ||
864 | } | ||
859 | arrange_Widget(tabs); | 865 | arrange_Widget(tabs); |
860 | iInt2 largest = zero_I2(); | 866 | iInt2 largest = zero_I2(); |
861 | iWidget *pages = findChild_Widget(tabs, "tabs.pages"); | 867 | iConstForEach(ObjectList, j, children_Widget(pages)) { |
862 | iConstForEach(ObjectList, i, children_Widget(pages)) { | 868 | const iWidget *page = constAs_Widget(j.object); |
863 | largest = max_I2(largest, ((const iWidget *) i.object)->rect.size); | 869 | largest = max_I2(largest, page->rect.size); |
864 | } | 870 | } |
865 | iForEach(ObjectList, j, children_Widget(pages)) { | 871 | iForEach(ObjectList, k, children_Widget(pages)) { |
866 | setSize_Widget(j.object, largest); | 872 | setMinSize_Widget(k.object, largest); |
867 | } | 873 | } |
868 | setSize_Widget(tabs, addY_I2(largest, height_Widget(findChild_Widget(tabs, "tabs.buttons")))); | 874 | setFixedSize_Widget(tabs, addY_I2(largest, height_Widget(findChild_Widget(tabs, "tabs.buttons")))); |
875 | // puts("... DONE WITH RESIZE TO LARGEST PAGE"); | ||
869 | } | 876 | } |
870 | 877 | ||
871 | iLabelWidget *tabButtonForPage_Widget_(iWidget *tabs, const iWidget *page) { | 878 | iLabelWidget *tabButtonForPage_Widget_(iWidget *tabs, const iWidget *page) { |
@@ -1012,7 +1019,7 @@ static void updateSheetPanelMetrics_(iWidget *sheet) { | |||
1012 | setSize_Widget(pad, init1_I2(naviHeight)); | 1019 | setSize_Widget(pad, init1_I2(naviHeight)); |
1013 | } | 1020 | } |
1014 | #endif | 1021 | #endif |
1015 | setSize_Widget(navi, init_I2(-1, naviHeight)); | 1022 | setFixedSize_Widget(navi, init_I2(-1, naviHeight)); |
1016 | } | 1023 | } |
1017 | 1024 | ||
1018 | static iBool slidePanelHandler_(iWidget *d, const char *cmd) { | 1025 | static iBool slidePanelHandler_(iWidget *d, const char *cmd) { |
@@ -1786,12 +1793,16 @@ static iBool toggleHandler_(iWidget *d, const char *cmd) { | |||
1786 | isSelected_Widget(d) ? 1 : 0)); | 1793 | isSelected_Widget(d) ? 1 : 0)); |
1787 | return iTrue; | 1794 | return iTrue; |
1788 | } | 1795 | } |
1796 | else if (equal_Command(cmd, "lang.changed")) { | ||
1797 | /* TODO: Measure labels again. */ | ||
1798 | } | ||
1789 | return iFalse; | 1799 | return iFalse; |
1790 | } | 1800 | } |
1791 | 1801 | ||
1792 | iWidget *makeToggle_Widget(const char *id) { | 1802 | iWidget *makeToggle_Widget(const char *id) { |
1793 | iWidget *toggle = as_Widget(new_LabelWidget("${toggle.yes}", "toggle")); /* "YES" for sizing */ | 1803 | iWidget *toggle = as_Widget(new_LabelWidget("${toggle.yes}", "toggle")); /* "YES" for sizing */ |
1794 | setId_Widget(toggle, id); | 1804 | setId_Widget(toggle, id); |
1805 | /* TODO: Measure both labels and use the larger of the two. */ | ||
1795 | updateTextCStr_LabelWidget((iLabelWidget *) toggle, "${toggle.no}"); /* actual initial value */ | 1806 | updateTextCStr_LabelWidget((iLabelWidget *) toggle, "${toggle.no}"); /* actual initial value */ |
1796 | setFlags_Widget(toggle, fixedWidth_WidgetFlag, iTrue); | 1807 | setFlags_Widget(toggle, fixedWidth_WidgetFlag, iTrue); |
1797 | setCommandHandler_Widget(toggle, toggleHandler_); | 1808 | setCommandHandler_Widget(toggle, toggleHandler_); |
@@ -1879,6 +1890,36 @@ static int cmp_MenuItem_(const void *e1, const void *e2) { | |||
1879 | } | 1890 | } |
1880 | #endif | 1891 | #endif |
1881 | 1892 | ||
1893 | void updatePreferencesLayout_Widget(iWidget *prefs) { | ||
1894 | if (!prefs) return; | ||
1895 | /* Doing manual layout here because the widget arranging logic isn't sophisticated enough. */ | ||
1896 | /* TODO: Make the arranging more sophisticated to automate this. */ | ||
1897 | static const char *inputIds[] = { | ||
1898 | "prefs.searchurl", | ||
1899 | "prefs.downloads", | ||
1900 | "prefs.ca.file", | ||
1901 | "prefs.ca.path", | ||
1902 | "prefs.proxy.gemini", | ||
1903 | "prefs.proxy.gopher", | ||
1904 | "prefs.proxy.http" | ||
1905 | }; | ||
1906 | iWidget *tabs = findChild_Widget(prefs, "prefs.tabs"); | ||
1907 | /* Input fields expand to the right edge. */ | ||
1908 | /* TODO: Add an arrangement flag for this. */ | ||
1909 | iForIndices(i, inputIds) { | ||
1910 | iInputWidget *input = findChild_Widget(tabs, inputIds[i]); | ||
1911 | if (input) { | ||
1912 | as_Widget(input)->rect.size.x = 0; | ||
1913 | } | ||
1914 | } | ||
1915 | as_Widget(findChild_Widget(prefs, "bindings"))->rect.size.x = 0; | ||
1916 | resizeToLargestPage_Widget(tabs); | ||
1917 | arrange_Widget(prefs); | ||
1918 | iForIndices(i, inputIds) { | ||
1919 | expandInputFieldWidth_(findChild_Widget(tabs, inputIds[i])); | ||
1920 | } | ||
1921 | } | ||
1922 | |||
1882 | iWidget *makePreferences_Widget(void) { | 1923 | iWidget *makePreferences_Widget(void) { |
1883 | iWidget *dlg = makeSheet_Widget("prefs"); | 1924 | iWidget *dlg = makeSheet_Widget("prefs"); |
1884 | addChildFlags_Widget(dlg, | 1925 | addChildFlags_Widget(dlg, |
@@ -2021,7 +2062,7 @@ iWidget *makePreferences_Widget(void) { | |||
2021 | addChildFlags_Widget(values, iClob(sats), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | 2062 | addChildFlags_Widget(values, iClob(sats), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); |
2022 | } | 2063 | } |
2023 | /* Layout. */ { | 2064 | /* Layout. */ { |
2024 | appendTwoColumnPage_(tabs, "${heading.prefs.style}", '4', &headings, &values); | 2065 | setId_Widget(appendTwoColumnPage_(tabs, "${heading.prefs.style}", '4', &headings, &values), "prefs.page.style"); |
2025 | makeTwoColumnHeading_("${heading.prefs.fonts}", headings, values); | 2066 | makeTwoColumnHeading_("${heading.prefs.fonts}", headings, values); |
2026 | /* Fonts. */ { | 2067 | /* Fonts. */ { |
2027 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.headingfont}"))); | 2068 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.headingfont}"))); |
@@ -2096,22 +2137,13 @@ iWidget *makePreferences_Widget(void) { | |||
2096 | appendFramelessTabPage_(tabs, iClob(bind), "${heading.prefs.keys}", '6', KMOD_PRIMARY); | 2137 | appendFramelessTabPage_(tabs, iClob(bind), "${heading.prefs.keys}", '6', KMOD_PRIMARY); |
2097 | } | 2138 | } |
2098 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); | 2139 | addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); |
2099 | resizeToLargestPage_Widget(tabs); | 2140 | updatePreferencesLayout_Widget(dlg); |
2100 | arrange_Widget(dlg); | ||
2101 | /* Set input field sizes. */ { | ||
2102 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.searchurl")); | ||
2103 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.downloads")); | ||
2104 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.ca.file")); | ||
2105 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.ca.path")); | ||
2106 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gemini")); | ||
2107 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher")); | ||
2108 | expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http")); | ||
2109 | } | ||
2110 | addChild_Widget(dlg, | 2141 | addChild_Widget(dlg, |
2111 | iClob(makeDialogButtons_Widget( | 2142 | iClob(makeDialogButtons_Widget( |
2112 | (iMenuItem[]){ { "${dismiss}", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1))); | 2143 | (iMenuItem[]){ { "${dismiss}", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1))); |
2113 | addChild_Widget(get_Window()->root, iClob(dlg)); | 2144 | addChild_Widget(get_Window()->root, iClob(dlg)); |
2114 | finalizeSheet_Widget(dlg); | 2145 | finalizeSheet_Widget(dlg); |
2146 | //printTree_Widget(dlg); | ||
2115 | return dlg; | 2147 | return dlg; |
2116 | } | 2148 | } |
2117 | 2149 | ||