diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-24 17:50:44 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-24 17:50:44 +0200 |
commit | fd17eeda7afc59a3e6613aeb28727248732351e9 (patch) | |
tree | e5d6defb65df3a3cabd1f1401742232c3fa8e03c /src | |
parent | 5f9199d081a47241fefed7b2af1f53f4995b62ab (diff) |
Source Sans Pro and Iosevka as font options
Allow the UI and monospace fonts to be used as page content fonts.
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 35 | ||||
-rw-r--r-- | src/ui/text.c | 20 | ||||
-rw-r--r-- | src/ui/text.h | 2 | ||||
-rw-r--r-- | src/ui/util.c | 29 |
4 files changed, 67 insertions, 19 deletions
@@ -987,18 +987,27 @@ static void updatePrefsThemeButtons_(iWidget *d) { | |||
987 | } | 987 | } |
988 | } | 988 | } |
989 | 989 | ||
990 | static void updateColorThemeButton_(iLabelWidget *button, int theme) { | 990 | static void updateDropdownSelection_(iLabelWidget *dropButton, const char *selectedCommand) { |
991 | const char *mode = strstr(cstr_String(id_Widget(as_Widget(button))), ".dark") ? "dark" : "light"; | 991 | iForEach(ObjectList, i, children_Widget(findChild_Widget(as_Widget(dropButton), "menu"))) { |
992 | const char *command = format_CStr("doctheme.%s.set arg:%d", mode, theme); | ||
993 | iForEach(ObjectList, i, children_Widget(findChild_Widget(as_Widget(button), "menu"))) { | ||
994 | iLabelWidget *item = i.object; | 992 | iLabelWidget *item = i.object; |
995 | if (!cmp_String(command_LabelWidget(item), command)) { | 993 | const iBool isSelected = endsWith_String(command_LabelWidget(item), selectedCommand); |
996 | updateText_LabelWidget(button, text_LabelWidget(item)); | 994 | setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected); |
997 | break; | 995 | if (isSelected) { |
996 | updateText_LabelWidget(dropButton, text_LabelWidget(item)); | ||
998 | } | 997 | } |
999 | } | 998 | } |
1000 | } | 999 | } |
1001 | 1000 | ||
1001 | static void updateColorThemeButton_(iLabelWidget *button, int theme) { | ||
1002 | // const char *mode = strstr(cstr_String(id_Widget(as_Widget(button))), ".dark") | ||
1003 | // ? "dark" : "light"; | ||
1004 | updateDropdownSelection_(button, format_CStr(".set arg:%d", theme)); | ||
1005 | } | ||
1006 | |||
1007 | static void updateFontButton_(iLabelWidget *button, int font) { | ||
1008 | updateDropdownSelection_(button, format_CStr(".set arg:%d", font)); | ||
1009 | } | ||
1010 | |||
1002 | static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | 1011 | static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { |
1003 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { | 1012 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { |
1004 | setUiScale_Window(get_Window(), | 1013 | setUiScale_Window(get_Window(), |
@@ -1050,6 +1059,14 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
1050 | updateColorThemeButton_(findChild_Widget(d, "prefs.doctheme.light"), arg_Command(cmd)); | 1059 | updateColorThemeButton_(findChild_Widget(d, "prefs.doctheme.light"), arg_Command(cmd)); |
1051 | return iFalse; | 1060 | return iFalse; |
1052 | } | 1061 | } |
1062 | else if (equal_Command(cmd, "font.set")) { | ||
1063 | updateFontButton_(findChild_Widget(d, "prefs.font"), arg_Command(cmd)); | ||
1064 | return iFalse; | ||
1065 | } | ||
1066 | else if (equal_Command(cmd, "headingfont.set")) { | ||
1067 | updateFontButton_(findChild_Widget(d, "prefs.headingfont"), arg_Command(cmd)); | ||
1068 | return iFalse; | ||
1069 | } | ||
1053 | else if (equal_Command(cmd, "prefs.ostheme.changed")) { | 1070 | else if (equal_Command(cmd, "prefs.ostheme.changed")) { |
1054 | postCommandf_App("ostheme arg:%d", arg_Command(cmd)); | 1071 | postCommandf_App("ostheme arg:%d", arg_Command(cmd)); |
1055 | } | 1072 | } |
@@ -1518,7 +1535,7 @@ iBool handleCommand_App(const char *cmd) { | |||
1518 | } | 1535 | } |
1519 | else if (equal_Command(cmd, "preferences")) { | 1536 | else if (equal_Command(cmd, "preferences")) { |
1520 | iWidget *dlg = makePreferences_Widget(); | 1537 | iWidget *dlg = makePreferences_Widget(); |
1521 | updatePrefsThemeButtons_(dlg); | 1538 | updatePrefsThemeButtons_(dlg); |
1522 | setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir); | 1539 | setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir); |
1523 | setToggle_Widget(findChild_Widget(dlg, "prefs.hoverlink"), d->prefs.hoverLink); | 1540 | setToggle_Widget(findChild_Widget(dlg, "prefs.hoverlink"), d->prefs.hoverLink); |
1524 | setToggle_Widget(findChild_Widget(dlg, "prefs.smoothscroll"), d->prefs.smoothScrolling); | 1541 | setToggle_Widget(findChild_Widget(dlg, "prefs.smoothscroll"), d->prefs.smoothScrolling); |
@@ -1554,6 +1571,8 @@ iBool handleCommand_App(const char *cmd) { | |||
1554 | setToggle_Widget(findChild_Widget(dlg, "prefs.centershort"), d->prefs.centerShortDocs); | 1571 | setToggle_Widget(findChild_Widget(dlg, "prefs.centershort"), d->prefs.centerShortDocs); |
1555 | updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.dark"), d->prefs.docThemeDark); | 1572 | updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.dark"), d->prefs.docThemeDark); |
1556 | updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.light"), d->prefs.docThemeLight); | 1573 | updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.light"), d->prefs.docThemeLight); |
1574 | updateFontButton_(findChild_Widget(dlg, "prefs.font"), d->prefs.font); | ||
1575 | updateFontButton_(findChild_Widget(dlg, "prefs.headingfont"), d->prefs.headingFont); | ||
1557 | setFlags_Widget( | 1576 | setFlags_Widget( |
1558 | findChild_Widget( | 1577 | findChild_Widget( |
1559 | dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))), | 1578 | dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))), |
diff --git a/src/ui/text.c b/src/ui/text.c index 6f6a52ed..d3b8df37 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -232,6 +232,18 @@ static void initFonts_Text_(iText *d) { | |||
232 | italicFont = &fontLiterataLightItalicopsz10_Embedded; | 232 | italicFont = &fontLiterataLightItalicopsz10_Embedded; |
233 | lightFont = &fontLiterataExtraLightopsz18_Embedded; | 233 | lightFont = &fontLiterataExtraLightopsz18_Embedded; |
234 | } | 234 | } |
235 | else if (d->contentFont == sourceSansPro_TextFont) { | ||
236 | regularFont = &fontSourceSansProRegular_Embedded; | ||
237 | italicFont = &fontFiraSansItalic_Embedded; | ||
238 | lightFont = &fontFiraSansLight_Embedded; | ||
239 | lightScaling = 0.85f; | ||
240 | } | ||
241 | else if (d->contentFont == iosevka_TextFont) { | ||
242 | regularFont = &fontIosevkaTermExtended_Embedded; | ||
243 | italicFont = &fontIosevkaTermExtended_Embedded; | ||
244 | lightFont = &fontIosevkaTermExtended_Embedded; | ||
245 | scaling = lightScaling = 0.866f; | ||
246 | } | ||
235 | if (d->headingFont == firaSans_TextFont) { | 247 | if (d->headingFont == firaSans_TextFont) { |
236 | h12Font = &fontFiraSansBold_Embedded; | 248 | h12Font = &fontFiraSansBold_Embedded; |
237 | h3Font = &fontFiraSansRegular_Embedded; | 249 | h3Font = &fontFiraSansRegular_Embedded; |
@@ -246,6 +258,14 @@ static void initFonts_Text_(iText *d) { | |||
246 | h12Font = &fontLiterataBoldopsz36_Embedded; | 258 | h12Font = &fontLiterataBoldopsz36_Embedded; |
247 | h3Font = &fontLiterataRegularopsz14_Embedded; | 259 | h3Font = &fontLiterataRegularopsz14_Embedded; |
248 | } | 260 | } |
261 | else if (d->headingFont == sourceSansPro_TextFont) { | ||
262 | h12Font = &fontSourceSansProBold_Embedded; | ||
263 | h3Font = &fontSourceSansProRegular_Embedded; | ||
264 | } | ||
265 | else if (d->headingFont == iosevka_TextFont) { | ||
266 | h12Font = &fontIosevkaTermExtended_Embedded; | ||
267 | h3Font = &fontIosevkaTermExtended_Embedded; | ||
268 | } | ||
249 | #if defined (iPlatformAppleMobile) | 269 | #if defined (iPlatformAppleMobile) |
250 | const float uiSize = fontSize_UI * 1.1f; | 270 | const float uiSize = fontSize_UI * 1.1f; |
251 | #else | 271 | #else |
diff --git a/src/ui/text.h b/src/ui/text.h index 55524db1..f696b2e3 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -148,6 +148,8 @@ enum iTextFont { | |||
148 | firaSans_TextFont, | 148 | firaSans_TextFont, |
149 | literata_TextFont, | 149 | literata_TextFont, |
150 | tinos_TextFont, | 150 | tinos_TextFont, |
151 | sourceSansPro_TextFont, | ||
152 | iosevka_TextFont, | ||
151 | }; | 153 | }; |
152 | 154 | ||
153 | extern int gap_Text; /* affected by content font size */ | 155 | extern int gap_Text; /* affected by content font size */ |
diff --git a/src/ui/util.c b/src/ui/util.c index 4f0cb2fa..d255bde4 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1144,14 +1144,21 @@ static void addRadioButton_(iWidget *parent, const char *id, const char *label, | |||
1144 | 1144 | ||
1145 | static void addFontButtons_(iWidget *parent, const char *id) { | 1145 | static void addFontButtons_(iWidget *parent, const char *id) { |
1146 | const char *fontNames[] = { | 1146 | const char *fontNames[] = { |
1147 | "Nunito", "Fira Sans", "Literata", "Tinos" | 1147 | "Nunito", "Fira Sans", "Literata", "Tinos", "Source Sans Pro", "Iosevka" |
1148 | }; | 1148 | }; |
1149 | iArray *items = new_Array(sizeof(iMenuItem)); | ||
1149 | iForIndices(i, fontNames) { | 1150 | iForIndices(i, fontNames) { |
1150 | addRadioButton_(parent, | 1151 | pushBack_Array(items, |
1151 | format_CStr("prefs.%s.%u", id, i), | 1152 | &(iMenuItem){ fontNames[i], 0, 0, format_CStr("!%s.set arg:%d", id, i) }); |
1152 | fontNames[i], | ||
1153 | format_CStr("%s.set arg:%u", id, i)); | ||
1154 | } | 1153 | } |
1154 | // addRadioButton_(parent, | ||
1155 | // format_CStr("prefs.%s.%u", id, i), | ||
1156 | // fontNames[i], | ||
1157 | // format_CStr("%s.set arg:%u", id, i)); | ||
1158 | iLabelWidget *button = makeMenuButton_LabelWidget("Source Sans Pro", data_Array(items), size_Array(items)); | ||
1159 | setId_Widget(as_Widget(button), format_CStr("prefs.%s", id)); | ||
1160 | addChild_Widget(parent, iClob(button)); | ||
1161 | delete_Array(items); | ||
1155 | } | 1162 | } |
1156 | 1163 | ||
1157 | iWidget *makePreferences_Widget(void) { | 1164 | iWidget *makePreferences_Widget(void) { |
@@ -1243,13 +1250,13 @@ iWidget *makePreferences_Widget(void) { | |||
1243 | /* Fonts. */ { | 1250 | /* Fonts. */ { |
1244 | iWidget *fonts; | 1251 | iWidget *fonts; |
1245 | addChild_Widget(headings, iClob(makeHeading_Widget("Heading font:"))); | 1252 | addChild_Widget(headings, iClob(makeHeading_Widget("Heading font:"))); |
1246 | fonts = new_Widget(); | 1253 | // fonts = new_Widget(); |
1247 | addFontButtons_(fonts, "headingfont"); | 1254 | addFontButtons_(values, "headingfont"); |
1248 | addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | 1255 | // addChildFlags_Widget(values, iClob(fonts), 0); //arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); |
1249 | addChild_Widget(headings, iClob(makeHeading_Widget("Body font:"))); | 1256 | addChild_Widget(headings, iClob(makeHeading_Widget("Body font:"))); |
1250 | fonts = new_Widget(); | 1257 | // fonts = new_Widget(); |
1251 | addFontButtons_(fonts, "font"); | 1258 | addFontButtons_(values, "font"); |
1252 | addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | 1259 | // addChildFlags_Widget(values, iClob(fonts), 0); //arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); |
1253 | addChild_Widget(headings, iClob(makeHeading_Widget("Monospace body:"))); | 1260 | addChild_Widget(headings, iClob(makeHeading_Widget("Monospace body:"))); |
1254 | iWidget *mono = new_Widget(); | 1261 | iWidget *mono = new_Widget(); |
1255 | /* TODO: Needs labels! */ | 1262 | /* TODO: Needs labels! */ |