From 1137e9ab552ed2fecb019cc5574826f1dcce5cb7 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 5 Apr 2021 14:26:49 +0300 Subject: Added option to disable bold links IssueID #233 --- src/app.c | 21 +++++++++++++++++++++ src/gmdocument.c | 13 +++++++++---- src/prefs.c | 2 ++ src/prefs.h | 2 ++ src/ui/util.c | 53 +++++++++++++++++++++++++++++++++++++---------------- 5 files changed, 71 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 54f35373..5cfa8af1 100644 --- a/src/app.c +++ b/src/app.c @@ -226,6 +226,8 @@ static iString *serializePrefs_App_(const iApp *d) { /* TODO: Set up an array of booleans in Prefs and do these in a loop. */ appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini); appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher); + appendFormat_String(str, "prefs.boldlink.dark.changed arg:%d\n", d->prefs.boldLinkDark); + appendFormat_String(str, "prefs.boldlink.light.changed arg:%d\n", d->prefs.boldLinkLight); appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph); appendFormat_String(str, "prefs.plaintext.wrap.changed arg:%d\n", d->prefs.plainTextWrap); appendFormat_String(str, "prefs.sideicon.changed arg:%d\n", d->prefs.sideIcon); @@ -1697,6 +1699,19 @@ iBool handleCommand_App(const char *cmd) { postCommand_App("window.unfreeze"); return iTrue; } + else if (equal_Command(cmd, "prefs.boldlink.dark.changed") || + equal_Command(cmd, "prefs.boldlink.light.changed")) { + const iBool isSet = (arg_Command(cmd) != 0); + if (startsWith_CStr(cmd, "prefs.boldlink.dark")) { + d->prefs.boldLinkDark = isSet; + } + else { + d->prefs.boldLinkLight = isSet; + } + resetFonts_Text(); /* clear the glyph cache */ + postCommand_App("font.changed"); + return iTrue; + } else if (equal_Command(cmd, "prefs.biglede.changed")) { d->prefs.bigFirstParagraph = arg_Command(cmd) != 0; postCommand_App("document.layout.changed"); @@ -1938,6 +1953,12 @@ iBool handleCommand_App(const char *cmd) { setFlags_Widget(findChild_Widget(dlg, "prefs.mono.gopher"), selected_WidgetFlag, d->prefs.monospaceGopher); + setFlags_Widget(findChild_Widget(dlg, "prefs.boldlink.dark"), + selected_WidgetFlag, + d->prefs.boldLinkDark); + setFlags_Widget(findChild_Widget(dlg, "prefs.boldlink.light"), + selected_WidgetFlag, + d->prefs.boldLinkLight); setFlags_Widget( findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)), selected_WidgetFlag, diff --git a/src/gmdocument.c b/src/gmdocument.c index 184951d3..2a31fe77 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -336,8 +336,11 @@ static void alignDecoration_GmRun_(iGmRun *run, iBool isCentered) { } static void doLayout_GmDocument_(iGmDocument *d) { - const iBool isMono = isForcedMonospace_GmDocument_(d); - const iBool isNarrow = d->size.x < 90 * gap_Text; + const iPrefs *prefs = prefs_App(); + const iBool isMono = isForcedMonospace_GmDocument_(d); + const iBool isNarrow = d->size.x < 90 * gap_Text; + const iBool isDarkBg = isDark_GmDocumentTheme( + isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); /* TODO: Collect these parameters into a GmTheme. */ const int fonts[max_GmLineType] = { isMono ? regularMonospace_FontId : paragraph_FontId, @@ -347,7 +350,10 @@ static void doLayout_GmDocument_(iGmDocument *d) { heading1_FontId, heading2_FontId, heading3_FontId, - isMono ? regularMonospace_FontId : bold_FontId, + isMono ? regularMonospace_FontId + : ((isDarkBg && prefs->boldLinkDark) || (!isDarkBg && prefs->boldLinkLight)) + ? bold_FontId + : paragraph_FontId, }; static const int colors[max_GmLineType] = { tmParagraph_ColorId, @@ -376,7 +382,6 @@ static void doLayout_GmDocument_(iGmDocument *d) { static const char *quote = "\u201c"; static const char *magnifyingGlass = "\U0001f50d"; static const char *pointingFinger = "\U0001f449"; - const iPrefs *prefs = prefs_App(); clear_Array(&d->layout); clearLinks_GmDocument_(d); clear_Array(&d->headings); diff --git a/src/prefs.c b/src/prefs.c index bb0bb3ee..4c1d8dc2 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -47,6 +47,8 @@ void init_Prefs(iPrefs *d) { d->headingFont = nunito_TextFont; d->monospaceGemini = iFalse; d->monospaceGopher = iFalse; + d->boldLinkDark = iTrue; + d->boldLinkLight = iTrue; d->lineWidth = 38; d->bigFirstParagraph = iTrue; d->quoteIcon = iTrue; diff --git a/src/prefs.h b/src/prefs.h index 232c6fc3..6be7fd41 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -71,6 +71,8 @@ struct Impl_Prefs { enum iTextFont headingFont; iBool monospaceGemini; iBool monospaceGopher; + iBool boldLinkDark; + iBool boldLinkLight; int lineWidth; iBool bigFirstParagraph; iBool quoteIcon; diff --git a/src/ui/util.c b/src/ui/util.c index 4793f447..cdc58154 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1933,7 +1933,7 @@ iWidget *makePreferences_Widget(void) { setBackgroundColor_Widget(findChild_Widget(tabs, "tabs.buttons"), uiBackgroundSidebar_ColorId); setId_Widget(tabs, "prefs.tabs"); iWidget *headings, *values; - const int lineGap = lineHeight_Text(uiLabel_FontId); + const int bigGap = lineHeight_Text(uiLabel_FontId) * 3 / 4; /* General preferences. */ { appendTwoColumnPage_(tabs, "${heading.prefs.general}", '1', &headings, &values); #if defined (LAGRANGE_DOWNLOAD_EDIT) @@ -1942,8 +1942,8 @@ iWidget *makePreferences_Widget(void) { #endif addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.searchurl}"))); setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.searchurl"); - addChild_Widget(headings, iClob(makePadding_Widget(lineGap))); - addChild_Widget(values, iClob(makePadding_Widget(lineGap))); + addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); + addChild_Widget(values, iClob(makePadding_Widget(bigGap))); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}"))); addChild_Widget(values, iClob(makeToggle_Widget("prefs.collapsepreonload"))); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.plaintext.wrap}"))); @@ -1952,8 +1952,8 @@ iWidget *makePreferences_Widget(void) { addChild_Widget(values, iClob(makeToggle_Widget("prefs.centershort"))); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.hoverlink}"))); addChild_Widget(values, iClob(makeToggle_Widget("prefs.hoverlink"))); - addChild_Widget(headings, iClob(makePadding_Widget(lineGap))); - addChild_Widget(values, iClob(makePadding_Widget(lineGap))); + addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); + addChild_Widget(values, iClob(makePadding_Widget(bigGap))); /* UI languages. */ { iArray *uiLangs = collectNew_Array(sizeof(iMenuItem)); const iMenuItem langItems[] = { @@ -2076,17 +2076,36 @@ iWidget *makePreferences_Widget(void) { addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.font}"))); addFontButtons_(values, "font"); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.mono}"))); - iWidget *mono = new_Widget(); - iWidget *tog; - setTextCStr_LabelWidget( - addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gemini"))), "${prefs.mono.gemini}"); - setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); - updateSize_LabelWidget((iLabelWidget *) tog); - setTextCStr_LabelWidget( - addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gopher"))), "${prefs.mono.gopher}"); - setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); - updateSize_LabelWidget((iLabelWidget *) tog); + iWidget *mono = new_Widget(); { + iWidget *tog; + setTextCStr_LabelWidget( + addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gemini"))), + "${prefs.mono.gemini}"); + setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); + updateSize_LabelWidget((iLabelWidget *) tog); + setTextCStr_LabelWidget( + addChild_Widget(mono, tog = iClob(makeToggle_Widget("prefs.mono.gopher"))), + "${prefs.mono.gopher}"); + setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); + updateSize_LabelWidget((iLabelWidget *) tog); + } addChildFlags_Widget(values, iClob(mono), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); + addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.boldlink}"))); + iWidget *boldLink = new_Widget(); { + /* TODO: Add a utility function for this type of toggles? (also for above) */ + iWidget *tog; + setTextCStr_LabelWidget( + addChild_Widget(boldLink, tog = iClob(makeToggle_Widget("prefs.boldlink.dark"))), + "${prefs.boldlink.dark}"); + setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); + updateSize_LabelWidget((iLabelWidget *) tog); + setTextCStr_LabelWidget( + addChild_Widget(boldLink, tog = iClob(makeToggle_Widget("prefs.boldlink.light"))), + "${prefs.boldlink.light}"); + setFlags_Widget(tog, fixedWidth_WidgetFlag, iFalse); + updateSize_LabelWidget((iLabelWidget *) tog); + } + addChildFlags_Widget(values, iClob(boldLink), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); } makeTwoColumnHeading_("${heading.prefs.paragraph}", headings, values); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.linewidth}"))); @@ -2108,7 +2127,9 @@ iWidget *makePreferences_Widget(void) { addChildFlags_Widget(values, iClob(quote), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.biglede}"))); addChild_Widget(values, iClob(makeToggle_Widget("prefs.biglede"))); - makeTwoColumnHeading_("${heading.prefs.widelayout}", headings, values); +// makeTwoColumnHeading_("${heading.prefs.widelayout}", headings, values); + addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); + addChild_Widget(values, iClob(makePadding_Widget(bigGap))); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.sideicon}"))); addChild_Widget(values, iClob(makeToggle_Widget("prefs.sideicon"))); } -- cgit v1.2.3