summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-20 10:23:32 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-20 10:23:32 +0300
commitb504d777ac8e134d7223372cb04468cf1895d3ae (patch)
tree268c2d0e818f34c1f68772f3e73fd41d6ede315e /src
parent5f67d1c073d9a4f0b80f5fbd0b8dd851c5d3da8e (diff)
Added tabs to make room for more preferences
The Preferences sheet now has tabs (General, Proxies) so that more options can fit there in the future.
Diffstat (limited to 'src')
-rw-r--r--src/ui/util.c106
-rw-r--r--src/ui/util.h1
-rw-r--r--src/ui/widget.h4
3 files changed, 76 insertions, 35 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index ff6f8822..a47b33c4 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -471,6 +471,15 @@ iWidget *removeTabPage_Widget(iWidget *tabs, size_t index) {
471 return page; 471 return page;
472} 472}
473 473
474void resizeToLargestPage_Widget(iWidget *tabs) {
475 arrange_Widget(tabs);
476 iInt2 largest = zero_I2();
477 iConstForEach(ObjectList, i, children_Widget(findChild_Widget(tabs, "tabs.pages"))) {
478 largest = max_I2(largest, ((const iWidget *) i.object)->rect.size);
479 }
480 setSize_Widget(tabs, addY_I2(largest, height_Widget(findChild_Widget(tabs, "tabs.buttons"))));
481}
482
474iLabelWidget *tabButtonForPage_Widget_(iWidget *tabs, const iWidget *page) { 483iLabelWidget *tabButtonForPage_Widget_(iWidget *tabs, const iWidget *page) {
475 iWidget *buttons = findChild_Widget(tabs, "tabs.buttons"); 484 iWidget *buttons = findChild_Widget(tabs, "tabs.buttons");
476 iForEach(ObjectList, i, buttons->children) { 485 iForEach(ObjectList, i, buttons->children) {
@@ -803,49 +812,76 @@ iWidget *makeToggle_Widget(const char *id) {
803 return toggle; 812 return toggle;
804} 813}
805 814
815static iWidget *appendTwoColumnPage_(iWidget *tabs, const char *title, iWidget **headings,
816 iWidget **values) {
817 iWidget *page = new_Widget();
818 appendTabPage_Widget(tabs, page, title, 0, 0);
819 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
820 *headings = addChildFlags_Widget(
821 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
822 *values = addChildFlags_Widget(
823 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
824 return page;
825}
826
827static void makeTwoColumnHeading_(const char *title, iWidget *headings, iWidget *values) {
828 addChild_Widget(headings,
829 iClob(makeHeading_Widget(format_CStr(uiHeading_ColorEscape "%s", title))));
830 addChild_Widget(values, iClob(makeHeading_Widget("")));
831}
832
833static void expandInputFieldWidth_(iInputWidget *input) {
834 iWidget *page = as_Widget(input)->parent->parent->parent; /* tabs > page > values > input */
835 as_Widget(input)->rect.size.x =
836 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)),
838 right_Rect(bounds_Widget(page)), left_Rect(bounds_Widget(constAs_Widget(input))));
839 fflush(stdout);
840}
841
806iWidget *makePreferences_Widget(void) { 842iWidget *makePreferences_Widget(void) {
807 iWidget *dlg = makeSheet_Widget("prefs"); 843 iWidget *dlg = makeSheet_Widget("prefs");
808 addChildFlags_Widget(dlg, 844 addChildFlags_Widget(dlg,
809 iClob(new_LabelWidget(uiHeading_ColorEscape "PREFERENCES", 0, 0, NULL)), 845 iClob(new_LabelWidget(uiHeading_ColorEscape "PREFERENCES", 0, 0, NULL)),
810 frameless_WidgetFlag); 846 frameless_WidgetFlag);
811 iWidget *page = new_Widget(); 847 iWidget *tabs = makeTabs_Widget(dlg);
812 addChild_Widget(dlg, iClob(page)); 848 iWidget *headings, *values;
813 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 849 /* General preferences. */ {
814 iWidget *headings = addChildFlags_Widget( 850 appendTwoColumnPage_(tabs, "General", &headings, &values);
815 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 851 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:")));
816 iWidget *values = addChildFlags_Widget( 852 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads");
817 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 853 makeTwoColumnHeading_("WINDOW", headings, values);
818 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:")));
819 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads");
820#if defined (iPlatformApple) || defined (iPlatformMSys) 854#if defined (iPlatformApple) || defined (iPlatformMSys)
821 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); 855 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
822 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); 856 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme")));
823#endif 857#endif
824 addChild_Widget(headings, iClob(makeHeading_Widget("Theme:"))); 858 addChild_Widget(headings, iClob(makeHeading_Widget("Theme:")));
825 iWidget *themes = new_Widget(); 859 iWidget *themes = new_Widget();
826 /* Themes. */ { 860 /* Themes. */ {
827 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0"); 861 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0");
828 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Dark", 0, 0, "theme.set arg:1"))), "prefs.theme.1"); 862 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Dark", 0, 0, "theme.set arg:1"))), "prefs.theme.1");
829 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Light", 0, 0, "theme.set arg:2"))), "prefs.theme.2"); 863 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Light", 0, 0, "theme.set arg:2"))), "prefs.theme.2");
830 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure White", 0, 0, "theme.set arg:3"))), "prefs.theme.3"); 864 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure White", 0, 0, "theme.set arg:3"))), "prefs.theme.3");
831 } 865 }
832 addChildFlags_Widget(values, iClob(themes), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); 866 addChildFlags_Widget(values, iClob(themes), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
833 addChild_Widget(headings, iClob(makeHeading_Widget("Retain window size:"))); 867 addChild_Widget(headings, iClob(makeHeading_Widget("Retain window size:")));
834 addChild_Widget(values, iClob(makeToggle_Widget("prefs.retainwindow"))); 868 addChild_Widget(values, iClob(makeToggle_Widget("prefs.retainwindow")));
835 addChild_Widget(headings, iClob(makeHeading_Widget("UI scale factor:"))); 869 addChild_Widget(headings, iClob(makeHeading_Widget("UI scale factor:")));
836 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(8))), "prefs.uiscale"); 870 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(8))), "prefs.uiscale");
837 addChild_Widget(headings, iClob(makeHeading_Widget(uiHeading_ColorEscape "Proxies"))); 871 }
838 addChild_Widget(values, iClob(makeHeading_Widget(""))); 872 /* Proxies. */ {
839 addChild_Widget(headings, iClob(makeHeading_Widget("Gopher proxy:"))); 873 appendTwoColumnPage_(tabs, "Proxies", &headings, &values);
840 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.gopher"); 874 addChild_Widget(headings, iClob(makeHeading_Widget("Gopher proxy:")));
841 addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:"))); 875 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.gopher");
842 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.http"); 876 addChild_Widget(headings, iClob(makeHeading_Widget("HTTP proxy:")));
877 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.proxy.http");
878 }
879 resizeToLargestPage_Widget(tabs);
843 arrange_Widget(dlg); 880 arrange_Widget(dlg);
844 /* Set text input widths. */ { 881 /* Set input field sizes. */ {
845 const int inputWidth = width_Rect(page->rect) - width_Rect(headings->rect); 882 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.downloads"));
846 as_Widget(findChild_Widget(values, "prefs.downloads"))->rect.size.x = inputWidth; 883 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http"));
847 as_Widget(findChild_Widget(values, "prefs.proxy.http"))->rect.size.x = inputWidth; 884 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher"));
848 as_Widget(findChild_Widget(values, "prefs.proxy.gopher"))->rect.size.x = inputWidth;
849 } 885 }
850 iWidget *div = new_Widget(); { 886 iWidget *div = new_Widget(); {
851 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 887 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
diff --git a/src/ui/util.h b/src/ui/util.h
index 5590d008..754310ad 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -136,6 +136,7 @@ iWidget * makeTabs_Widget (iWidget *parent);
136void appendTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods); 136void appendTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods);
137void prependTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods); 137void prependTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods);
138iWidget * removeTabPage_Widget (iWidget *tabs, size_t index); /* returns the page */ 138iWidget * removeTabPage_Widget (iWidget *tabs, size_t index); /* returns the page */
139void resizeToLargestPage_Widget (iWidget *tabs);
139void showTabPage_Widget (iWidget *tabs, const iWidget *page); 140void showTabPage_Widget (iWidget *tabs, const iWidget *page);
140void setTabPageLabel_Widget (iWidget *tabs, const iAnyObject *page, const iString *label); 141void setTabPageLabel_Widget (iWidget *tabs, const iAnyObject *page, const iString *label);
141iWidget * tabPage_Widget (iWidget *tabs, size_t index); 142iWidget * tabPage_Widget (iWidget *tabs, size_t index);
diff --git a/src/ui/widget.h b/src/ui/widget.h
index fa4fbe0f..cc6d774e 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -148,6 +148,10 @@ iLocalDef int width_Widget(const iAnyObject *d) {
148 iAssert(isInstance_Object(d, &Class_Widget)); 148 iAssert(isInstance_Object(d, &Class_Widget));
149 return ((const iWidget *) d)->rect.size.x; 149 return ((const iWidget *) d)->rect.size.x;
150} 150}
151iLocalDef int height_Widget(const iAnyObject *d) {
152 iAssert(isInstance_Object(d, &Class_Widget));
153 return ((const iWidget *) d)->rect.size.y;
154}
151iLocalDef iObjectList *children_Widget(iAnyObject *d) { 155iLocalDef iObjectList *children_Widget(iAnyObject *d) {
152 iAssert(isInstance_Object(d, &Class_Widget)); 156 iAssert(isInstance_Object(d, &Class_Widget));
153 return ((iWidget *) d)->children; 157 return ((iWidget *) d)->children;