diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-23 21:40:41 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-23 21:40:41 +0200 |
commit | bb9a22212f83e55ebaf601a65251ccb3caf86fab (patch) | |
tree | 166aa0e7a0351b7a68d40e65b2a61afa0da51d37 /src/ui/util.c | |
parent | 35496f8a9c9cc0098210349d5c7fda3492ffd9c8 (diff) |
UI language preference; switching at runtime
IssueID #192
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 94690bc6..8c0b0138 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1679,14 +1679,13 @@ iWidget *makeQuestion_Widget(const char *title, const char *msg, | |||
1679 | 1679 | ||
1680 | void setToggle_Widget(iWidget *d, iBool active) { | 1680 | void setToggle_Widget(iWidget *d, iBool active) { |
1681 | if (d) { | 1681 | if (d) { |
1682 | const char *YES = cstr_Lang("toggle.yes"); | ||
1683 | const char *NO = cstr_Lang("toggle.no"); | ||
1684 | setFlags_Widget(d, selected_WidgetFlag, active); | 1682 | setFlags_Widget(d, selected_WidgetFlag, active); |
1685 | iLabelWidget *label = (iLabelWidget *) d; | 1683 | iLabelWidget *label = (iLabelWidget *) d; |
1686 | if (!cmp_String(text_LabelWidget(label), YES) || | 1684 | if (!cmp_String(text_LabelWidget(label), cstr_Lang("toggle.yes")) || |
1687 | !cmp_String(text_LabelWidget(label), NO)) { | 1685 | !cmp_String(text_LabelWidget(label), cstr_Lang("toggle.no"))) { |
1688 | updateText_LabelWidget((iLabelWidget *) d, | 1686 | updateText_LabelWidget( |
1689 | collectNewCStr_String(isSelected_Widget(d) ? YES : NO)); | 1687 | (iLabelWidget *) d, |
1688 | collectNewCStr_String(isSelected_Widget(d) ? "${toggle.yes}" : "${toggle.no}")); | ||
1690 | } | 1689 | } |
1691 | else { | 1690 | else { |
1692 | refresh_Widget(d); | 1691 | refresh_Widget(d); |
@@ -1707,9 +1706,10 @@ static iBool toggleHandler_(iWidget *d, const char *cmd) { | |||
1707 | } | 1706 | } |
1708 | 1707 | ||
1709 | iWidget *makeToggle_Widget(const char *id) { | 1708 | iWidget *makeToggle_Widget(const char *id) { |
1710 | iWidget *toggle = as_Widget(new_LabelWidget("YES", "toggle")); /* "YES" for sizing */ | 1709 | iWidget *toggle = as_Widget(new_LabelWidget("${toggle.yes}", "toggle")); /* "YES" for sizing */ |
1711 | setId_Widget(toggle, id); | 1710 | setId_Widget(toggle, id); |
1712 | updateTextCStr_LabelWidget((iLabelWidget *) toggle, "NO"); /* actual initial value */ | 1711 | updateTextCStr_LabelWidget((iLabelWidget *) toggle, "${toggle.no}"); /* actual initial value */ |
1712 | setFlags_Widget(toggle, fixedWidth_WidgetFlag, iTrue); | ||
1713 | setCommandHandler_Widget(toggle, toggleHandler_); | 1713 | setCommandHandler_Widget(toggle, toggleHandler_); |
1714 | return toggle; | 1714 | return toggle; |
1715 | } | 1715 | } |
@@ -1787,6 +1787,11 @@ static void addFontButtons_(iWidget *parent, const char *id) { | |||
1787 | delete_Array(items); | 1787 | delete_Array(items); |
1788 | } | 1788 | } |
1789 | 1789 | ||
1790 | static int cmp_MenuItem_(const void *e1, const void *e2) { | ||
1791 | const iMenuItem *a = e1, *b = e2; | ||
1792 | return iCmpStr(a->label, b->label); | ||
1793 | } | ||
1794 | |||
1790 | iWidget *makePreferences_Widget(void) { | 1795 | iWidget *makePreferences_Widget(void) { |
1791 | iWidget *dlg = makeSheet_Widget("prefs"); | 1796 | iWidget *dlg = makeSheet_Widget("prefs"); |
1792 | addChildFlags_Widget(dlg, | 1797 | addChildFlags_Widget(dlg, |
@@ -1820,6 +1825,36 @@ iWidget *makePreferences_Widget(void) { | |||
1820 | } | 1825 | } |
1821 | /* Window. */ { | 1826 | /* Window. */ { |
1822 | appendTwoColumnPage_(tabs, "${heading.prefs.interface}", '2', &headings, &values); | 1827 | appendTwoColumnPage_(tabs, "${heading.prefs.interface}", '2', &headings, &values); |
1828 | /* UI languages. */ { | ||
1829 | iArray *uiLangs = collectNew_Array(sizeof(iMenuItem)); | ||
1830 | const iMenuItem langItems[] = { | ||
1831 | { "${lang.en}", 0, 0, "uilang id:en" }, | ||
1832 | { "${lang.fi}", 0, 0, "uilang id:fi" }, | ||
1833 | }; | ||
1834 | pushBackN_Array(uiLangs, langItems, iElemCount(langItems)); | ||
1835 | sort_Array(uiLangs, cmp_MenuItem_); | ||
1836 | /* TODO: Add an arrange flag for resizing parent to widest child. */ | ||
1837 | int widest = 0; | ||
1838 | size_t widestPos = iInvalidPos; | ||
1839 | iConstForEach(Array, i, uiLangs) { | ||
1840 | const int width = | ||
1841 | advance_Text(uiLabel_FontId, | ||
1842 | translateCStr_Lang(((const iMenuItem *) i.value)->label)) | ||
1843 | .x; | ||
1844 | if (widestPos == iInvalidPos || width > widest) { | ||
1845 | widest = width; | ||
1846 | widestPos = index_ArrayConstIterator(&i); | ||
1847 | } | ||
1848 | } | ||
1849 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.uilang}"))); | ||
1850 | setId_Widget(addChildFlags_Widget(values, | ||
1851 | iClob(makeMenuButton_LabelWidget( | ||
1852 | value_Array(uiLangs, widestPos, iMenuItem).label, | ||
1853 | data_Array(uiLangs), | ||
1854 | size_Array(uiLangs))), | ||
1855 | 0), | ||
1856 | "prefs.uilang"); | ||
1857 | } | ||
1823 | #if defined (iPlatformApple) || defined (iPlatformMSys) | 1858 | #if defined (iPlatformApple) || defined (iPlatformMSys) |
1824 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.ostheme}"))); | 1859 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.ostheme}"))); |
1825 | addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); | 1860 | addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); |
@@ -1898,11 +1933,15 @@ iWidget *makePreferences_Widget(void) { | |||
1898 | addFontButtons_(values, "font"); | 1933 | addFontButtons_(values, "font"); |
1899 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.mono}"))); | 1934 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.mono}"))); |
1900 | iWidget *mono = new_Widget(); | 1935 | iWidget *mono = new_Widget(); |
1901 | /* TODO: Needs labels! */ | 1936 | iWidget *tog; |
1902 | setTextCStr_LabelWidget( | 1937 | setTextCStr_LabelWidget( |
1903 | addChild_Widget(mono, iClob(makeToggle_Widget("prefs.mono.gemini"))), "${prefs.mono.gemini}"); | 1938 | addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gemini"))), "${prefs.mono.gemini}"); |
1939 | setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); | ||
1940 | updateSize_LabelWidget((iLabelWidget *) tog); | ||
1904 | setTextCStr_LabelWidget( | 1941 | setTextCStr_LabelWidget( |
1905 | addChild_Widget(mono, iClob(makeToggle_Widget("prefs.mono.gopher"))), "${prefs.mono.gopher}"); | 1942 | addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gopher"))), "${prefs.mono.gopher}"); |
1943 | setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); | ||
1944 | updateSize_LabelWidget((iLabelWidget *) tog); | ||
1906 | addChildFlags_Widget(values, iClob(mono), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | 1945 | addChildFlags_Widget(values, iClob(mono), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); |
1907 | } | 1946 | } |
1908 | makeTwoColumnHeading_("${heading.prefs.paragraph}", headings, values); | 1947 | makeTwoColumnHeading_("${heading.prefs.paragraph}", headings, values); |