summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-26 12:56:07 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-26 12:56:07 +0300
commit790a2c49a0290ce872ec8929b063337eacde9880 (patch)
treed4bcc54ece3b4bec58fad9f1920ed2ca0c70c6b8
parent84d3089735bd81a9d628acf416b481f2535765cf (diff)
Preferences: Added side icon, hover outline
-rw-r--r--src/app.c14
-rw-r--r--src/prefs.c2
-rw-r--r--src/prefs.h2
-rw-r--r--src/ui/documentwidget.c65
-rw-r--r--src/ui/util.c5
5 files changed, 55 insertions, 33 deletions
diff --git a/src/app.c b/src/app.c
index 81fe67af..d1732bf9 100644
--- a/src/app.c
+++ b/src/app.c
@@ -169,6 +169,8 @@ static iString *serializePrefs_App_(const iApp *d) {
169 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent); 169 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
170 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); 170 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth);
171 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph); 171 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph);
172 appendFormat_String(str, "prefs.sideicon.changed arg:%d\n", d->prefs.sideIcon);
173 appendFormat_String(str, "prefs.hoveroutline.changed arg:%d\n", d->prefs.hoverOutline);
172 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme); 174 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme);
173 appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme); 175 appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme);
174 appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f)); 176 appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f));
@@ -868,6 +870,16 @@ iBool handleCommand_App(const char *cmd) {
868 postCommand_App("document.layout.changed"); 870 postCommand_App("document.layout.changed");
869 return iTrue; 871 return iTrue;
870 } 872 }
873 else if (equal_Command(cmd, "prefs.sideicon.changed")) {
874 d->prefs.sideIcon = arg_Command(cmd) != 0;
875 refresh_App();
876 return iTrue;
877 }
878 else if (equal_Command(cmd, "prefs.hoveroutline.changed")) {
879 d->prefs.hoverOutline = arg_Command(cmd) != 0;
880 refresh_App();
881 return iTrue;
882 }
871 else if (equal_Command(cmd, "saturation.set")) { 883 else if (equal_Command(cmd, "saturation.set")) {
872 d->prefs.saturation = (float) arg_Command(cmd) / 100.0f; 884 d->prefs.saturation = (float) arg_Command(cmd) / 100.0f;
873 postCommandf_App("theme.changed auto:1"); 885 postCommandf_App("theme.changed auto:1");
@@ -982,6 +994,7 @@ iBool handleCommand_App(const char *cmd) {
982 iWidget *dlg = makePreferences_Widget(); 994 iWidget *dlg = makePreferences_Widget();
983 updatePrefsThemeButtons_(dlg); 995 updatePrefsThemeButtons_(dlg);
984 setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir); 996 setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir);
997 setToggle_Widget(findChild_Widget(dlg, "prefs.hoveroutline"), d->prefs.hoverOutline);
985 setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->prefs.useSystemTheme); 998 setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->prefs.useSystemTheme);
986 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize); 999 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize);
987 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"), 1000 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"),
@@ -994,6 +1007,7 @@ iBool handleCommand_App(const char *cmd) {
994 selected_WidgetFlag, 1007 selected_WidgetFlag,
995 iTrue); 1008 iTrue);
996 setToggle_Widget(findChild_Widget(dlg, "prefs.biglede"), d->prefs.bigFirstParagraph); 1009 setToggle_Widget(findChild_Widget(dlg, "prefs.biglede"), d->prefs.bigFirstParagraph);
1010 setToggle_Widget(findChild_Widget(dlg, "prefs.sideicon"), d->prefs.sideIcon);
997 setFlags_Widget( 1011 setFlags_Widget(
998 findChild_Widget( 1012 findChild_Widget(
999 dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))), 1013 dlg, format_CStr("prefs.saturation.%d", (int) (d->prefs.saturation * 3.99f))),
diff --git a/src/prefs.c b/src/prefs.c
index 9b77b4f2..af481233 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -9,6 +9,8 @@ void init_Prefs(iPrefs *d) {
9 d->font = nunito_TextFont; 9 d->font = nunito_TextFont;
10 d->lineWidth = 40; 10 d->lineWidth = 40;
11 d->bigFirstParagraph = iTrue; 11 d->bigFirstParagraph = iTrue;
12 d->sideIcon = iTrue;
13 d->hoverOutline = iFalse;
12 d->docThemeDark = colorfulDark_GmDocumentTheme; 14 d->docThemeDark = colorfulDark_GmDocumentTheme;
13 d->docThemeLight = white_GmDocumentTheme; 15 d->docThemeLight = white_GmDocumentTheme;
14 d->saturation = 1.0f; 16 d->saturation = 1.0f;
diff --git a/src/prefs.h b/src/prefs.h
index 42ccff85..324fb6fd 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -23,6 +23,8 @@ struct Impl_Prefs {
23 int lineWidth; 23 int lineWidth;
24 iBool bigFirstParagraph; 24 iBool bigFirstParagraph;
25 iBool forceLineWrap; 25 iBool forceLineWrap;
26 iBool sideIcon;
27 iBool hoverOutline;
26 enum iGmDocumentTheme docThemeDark; 28 enum iGmDocumentTheme docThemeDark;
27 enum iGmDocumentTheme docThemeLight; 29 enum iGmDocumentTheme docThemeLight;
28 float saturation; 30 float saturation;
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 0079465f..ec6288d5 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -133,7 +133,7 @@ struct Impl_OutlineItem {
133 iRangecc text; 133 iRangecc text;
134 int font; 134 int font;
135 iRect rect; 135 iRect rect;
136 int seenColor; 136 int seenColor; /* TODO: not used */
137 int sepColor; 137 int sepColor;
138}; 138};
139 139
@@ -2058,13 +2058,15 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
2058// drawRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, red_ColorId); 2058// drawRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, red_ColorId);
2059} 2059}
2060 2060
2061static void drawSideRect_(iPaint *p, iRect rect, int thickness) { 2061static int drawSideRect_(iPaint *p, iRect rect) { //}, int thickness) {
2062 if (equal_Color(get_Color(tmBannerBackground_ColorId), get_Color(tmBackground_ColorId))) { 2062 int bg = tmBannerBackground_ColorId;
2063 drawRectThickness_Paint(p, rect, thickness, tmBannerIcon_ColorId); 2063 int fg = tmBannerIcon_ColorId;
2064 } 2064 if (equal_Color(get_Color(bg), get_Color(tmBackground_ColorId))) {
2065 else { 2065 bg = tmBannerIcon_ColorId;
2066 fillRect_Paint(p, rect, tmBannerBackground_ColorId); 2066 fg = tmBannerBackground_ColorId;
2067 } 2067 }
2068 fillRect_Paint(p, rect, bg);
2069 return fg;
2068} 2070}
2069 2071
2070static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) { 2072static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
@@ -2079,7 +2081,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
2079 iPaint p; 2081 iPaint p;
2080 init_Paint(&p); 2082 init_Paint(&p);
2081 setClip_Paint(&p, bounds); 2083 setClip_Paint(&p, bounds);
2082 if (avail > minBannerSize) { 2084 if (prefs_App()->sideIcon && avail > minBannerSize) {
2083 if (banner && opacity > 0) { 2085 if (banner && opacity > 0) {
2084 setOpacity_Text(opacity); 2086 setOpacity_Text(opacity);
2085 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); 2087 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
@@ -2088,16 +2090,16 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
2088 p.alpha = opacity * 255; 2090 p.alpha = opacity * 255;
2089 //int offset = iMax(0, bottom_Rect(banner->visBounds) - d->scrollY); 2091 //int offset = iMax(0, bottom_Rect(banner->visBounds) - d->scrollY);
2090 rect.pos.y += height_Rect(bounds) / 2 - rect.size.y / 2 - (banner ? banner->visBounds.size.y / 2 : 0); // offset; 2092 rect.pos.y += height_Rect(bounds) / 2 - rect.size.y / 2 - (banner ? banner->visBounds.size.y / 2 : 0); // offset;
2091 drawSideRect_(&p, rect, gap_UI / 2); 2093 int fg = drawSideRect_(&p, rect); //, gap_UI / 2);
2092 if (equal_Color(get_Color(tmBannerBackground_ColorId), get_Color(tmBackground_ColorId))) { 2094// if (equal_Color(get_Color(tmBannerBackground_ColorId), get_Color(tmBackground_ColorId))) {
2093 drawRectThickness_Paint(&p, rect, gap_UI / 2, tmBannerIcon_ColorId); 2095// drawRectThickness_Paint(&p, rect, gap_UI / 2, tmBannerIcon_ColorId);
2094 } 2096// }
2095 else { 2097// else {
2096 fillRect_Paint(&p, rect, tmBannerBackground_ColorId); 2098// fillRect_Paint(&p, rect, tmBannerBackground_ColorId);
2097 } 2099// }
2098 iString str; 2100 iString str;
2099 initUnicodeN_String(&str, &icon, 1); 2101 initUnicodeN_String(&str, &icon, 1);
2100 drawCentered_Text(banner_FontId, rect, iTrue, tmBannerIcon_ColorId, "%s", cstr_String(&str)); 2102 drawCentered_Text(banner_FontId, rect, iTrue, fg, "%s", cstr_String(&str));
2101#if 0 2103#if 0
2102 if (avail >= minBannerSize * 2) { 2104 if (avail >= minBannerSize * 2) {
2103 const char *endp; 2105 const char *endp;
@@ -2139,7 +2141,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
2139 } 2141 }
2140 /* Outline on the right side. */ 2142 /* Outline on the right side. */
2141 const float outlineOpacity = value_Anim(&d->outlineOpacity); 2143 const float outlineOpacity = value_Anim(&d->outlineOpacity);
2142 if (!isEmpty_Array(&d->outline) && outlineOpacity > 0.0f) { 2144 if (prefs_App()->hoverOutline && !isEmpty_Array(&d->outline) && outlineOpacity > 0.0f) {
2143// const int font = uiLabel_FontId; 2145// const int font = uiLabel_FontId;
2144 //iRect outlineRect = initCorners_Rect(topRight_Rect(docBounds), bottomRight_Rect(bounds)); 2146 //iRect outlineRect = initCorners_Rect(topRight_Rect(docBounds), bottomRight_Rect(bounds));
2145 //const int excess = width_Rect(outlineRect) - 75 * gap_UI; 2147 //const int excess = width_Rect(outlineRect) - 75 * gap_UI;
@@ -2170,26 +2172,23 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
2170 setOpacity_Text(outlineOpacity); 2172 setOpacity_Text(outlineOpacity);
2171 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); 2173 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
2172 p.alpha = outlineOpacity * 255; 2174 p.alpha = outlineOpacity * 255;
2173 drawSideRect_( 2175 iRect outlineFrame = {
2174 &p, 2176 addY_I2(pos, -outlinePadding_DocumentWidget_ * gap_UI / 2),
2175 (iRect){ addY_I2(pos, -outlinePadding_DocumentWidget_ * gap_UI / 2), 2177 init_I2(outWidth, outHeight + outlinePadding_DocumentWidget_ * gap_UI * 1.5f)
2176 init_I2(outWidth, outHeight + outlinePadding_DocumentWidget_ * gap_UI * 1.5f) }, 2178 };
2177 1); 2179 fillRect_Paint(&p, outlineFrame, tmBannerBackground_ColorId);
2180 const int textFg = drawSideRect_(&p, outlineFrame); //, 1);
2178 iConstForEach(Array, i, &d->outline) { 2181 iConstForEach(Array, i, &d->outline) {
2179 const iOutlineItem *item = i.value; 2182 const iOutlineItem *item = i.value;
2180 iInt2 visPos = addX_I2(add_I2(pos, item->rect.pos), outlinePadding_DocumentWidget_ * gap_UI); 2183 iInt2 visPos = addX_I2(add_I2(pos, item->rect.pos), outlinePadding_DocumentWidget_ * gap_UI);
2181// visPos.y -= scroll;
2182// if (item->sepColor != none_ColorId) {
2183// drawHLine_Paint(&p, addY_I2(visPos, -gap_UI), outWidth, item->sepColor);
2184// }
2185// drawRect_Paint(&p, (iRect){ visPos, item->rect.size }, red_ColorId);
2186 const iBool isVisible = d->lastVisibleRun && d->lastVisibleRun->text.start >= item->text.start; 2184 const iBool isVisible = d->lastVisibleRun && d->lastVisibleRun->text.start >= item->text.start;
2187 drawWrapRange_Text(item->font, 2185 const int fg = index_ArrayConstIterator(&i) == 0 || isVisible ? textFg
2188 visPos, 2186 : tmQuoteIcon_ColorId;
2189 innerWidth - left_Rect(item->rect), 2187 drawWrapRange_Text(
2190 index_ArrayConstIterator(&i) == 0 || isVisible ? item->seenColor 2188 item->font, visPos, innerWidth - left_Rect(item->rect), fg, item->text);
2191 : tmQuoteIcon_ColorId, 2189 if (left_Rect(item->rect) > 0) {
2192 item->text); 2190 drawRange_Text(item->font, addX_I2(visPos, -3 * gap_UI), fg, range_CStr("\u2013"));
2191 }
2193 } 2192 }
2194 setOpacity_Text(1.0f); 2193 setOpacity_Text(1.0f);
2195 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); 2194 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE);
diff --git a/src/ui/util.c b/src/ui/util.c
index 27bac834..e106bfff 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -898,6 +898,8 @@ iWidget *makePreferences_Widget(void) {
898 appendTwoColumnPage_(tabs, "General", '1', &headings, &values); 898 appendTwoColumnPage_(tabs, "General", '1', &headings, &values);
899 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:"))); 899 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:")));
900 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); 900 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads");
901 addChild_Widget(headings, iClob(makeHeading_Widget("Outline on scrollbar:")));
902 addChild_Widget(values, iClob(makeToggle_Widget("prefs.hoveroutline")));
901 makeTwoColumnHeading_("WINDOW", headings, values); 903 makeTwoColumnHeading_("WINDOW", headings, values);
902#if defined (iPlatformApple) || defined (iPlatformMSys) 904#if defined (iPlatformApple) || defined (iPlatformMSys)
903 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); 905 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
@@ -939,6 +941,9 @@ iWidget *makePreferences_Widget(void) {
939 addChildFlags_Widget(values, iClob(widths), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); 941 addChildFlags_Widget(values, iClob(widths), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
940 addChild_Widget(headings, iClob(makeHeading_Widget("Big 1st paragaph:"))); 942 addChild_Widget(headings, iClob(makeHeading_Widget("Big 1st paragaph:")));
941 addChild_Widget(values, iClob(makeToggle_Widget("prefs.biglede"))); 943 addChild_Widget(values, iClob(makeToggle_Widget("prefs.biglede")));
944 makeTwoColumnHeading_("WIDE LAYOUT", headings, values);
945 addChild_Widget(headings, iClob(makeHeading_Widget("Site icon:")));
946 addChild_Widget(values, iClob(makeToggle_Widget("prefs.sideicon")));
942 } 947 }
943 /* Colors. */ { 948 /* Colors. */ {
944 appendTwoColumnPage_(tabs, "Colors", '3', &headings, &values); 949 appendTwoColumnPage_(tabs, "Colors", '3', &headings, &values);