From fd17eeda7afc59a3e6613aeb28727248732351e9 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 24 Feb 2021 17:50:44 +0200 Subject: Source Sans Pro and Iosevka as font options Allow the UI and monospace fonts to be used as page content fonts. --- src/app.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/app.c') diff --git a/src/app.c b/src/app.c index 929cc8a2..c04347b0 100644 --- a/src/app.c +++ b/src/app.c @@ -987,18 +987,27 @@ static void updatePrefsThemeButtons_(iWidget *d) { } } -static void updateColorThemeButton_(iLabelWidget *button, int theme) { - const char *mode = strstr(cstr_String(id_Widget(as_Widget(button))), ".dark") ? "dark" : "light"; - const char *command = format_CStr("doctheme.%s.set arg:%d", mode, theme); - iForEach(ObjectList, i, children_Widget(findChild_Widget(as_Widget(button), "menu"))) { +static void updateDropdownSelection_(iLabelWidget *dropButton, const char *selectedCommand) { + iForEach(ObjectList, i, children_Widget(findChild_Widget(as_Widget(dropButton), "menu"))) { iLabelWidget *item = i.object; - if (!cmp_String(command_LabelWidget(item), command)) { - updateText_LabelWidget(button, text_LabelWidget(item)); - break; + const iBool isSelected = endsWith_String(command_LabelWidget(item), selectedCommand); + setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected); + if (isSelected) { + updateText_LabelWidget(dropButton, text_LabelWidget(item)); } } } +static void updateColorThemeButton_(iLabelWidget *button, int theme) { +// const char *mode = strstr(cstr_String(id_Widget(as_Widget(button))), ".dark") +// ? "dark" : "light"; + updateDropdownSelection_(button, format_CStr(".set arg:%d", theme)); +} + +static void updateFontButton_(iLabelWidget *button, int font) { + updateDropdownSelection_(button, format_CStr(".set arg:%d", font)); +} + static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { setUiScale_Window(get_Window(), @@ -1050,6 +1059,14 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { updateColorThemeButton_(findChild_Widget(d, "prefs.doctheme.light"), arg_Command(cmd)); return iFalse; } + else if (equal_Command(cmd, "font.set")) { + updateFontButton_(findChild_Widget(d, "prefs.font"), arg_Command(cmd)); + return iFalse; + } + else if (equal_Command(cmd, "headingfont.set")) { + updateFontButton_(findChild_Widget(d, "prefs.headingfont"), arg_Command(cmd)); + return iFalse; + } else if (equal_Command(cmd, "prefs.ostheme.changed")) { postCommandf_App("ostheme arg:%d", arg_Command(cmd)); } @@ -1518,7 +1535,7 @@ iBool handleCommand_App(const char *cmd) { } else if (equal_Command(cmd, "preferences")) { iWidget *dlg = makePreferences_Widget(); - updatePrefsThemeButtons_(dlg); + updatePrefsThemeButtons_(dlg); setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir); setToggle_Widget(findChild_Widget(dlg, "prefs.hoverlink"), d->prefs.hoverLink); setToggle_Widget(findChild_Widget(dlg, "prefs.smoothscroll"), d->prefs.smoothScrolling); @@ -1554,6 +1571,8 @@ iBool handleCommand_App(const char *cmd) { setToggle_Widget(findChild_Widget(dlg, "prefs.centershort"), d->prefs.centerShortDocs); updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.dark"), d->prefs.docThemeDark); updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.light"), d->prefs.docThemeLight); + updateFontButton_(findChild_Widget(dlg, "prefs.font"), d->prefs.font); + updateFontButton_(findChild_Widget(dlg, "prefs.headingfont"), d->prefs.headingFont); setFlags_Widget( findChild_Widget( dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))), -- cgit v1.2.3