From 790a2c49a0290ce872ec8929b063337eacde9880 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi
Date: Sat, 26 Sep 2020 12:56:07 +0300
Subject: [PATCH 1/1] Preferences: Added side icon, hover outline
src/app.c | 14 +++++++++
src/prefs.c | 2 ++
src/prefs.h | 2 ++
src/ui/documentwidget.c | 65 ++++++++++++++++++++---------------------
src/ui/util.c | 5 ++++
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) {
appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth);
appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph);
appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme);
appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme);
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) {
postCommand_App("document.layout.changed");
return iTrue;
}
d->prefs.sideIcon = arg_Command(cmd) != 0;
refresh_App();
return iTrue;
d->prefs.hoverOutline = arg_Command(cmd) != 0;
refresh_App();
return iTrue;
else if (equal_Command(cmd, "saturation.set")) {
d->prefs.saturation = (float) arg_Command(cmd) / 100.0f;
postCommandf_App("theme.changed auto:1");
@@ -982,6 +994,7 @@ iBool handleCommand_App(const char *cmd) {
iWidget *dlg = makePreferences_Widget();
updatePrefsThemeButtons_(dlg);
setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir);
setToggle_Widget(findChild_Widget(dlg, "prefs.hoveroutline"), d->prefs.hoverOutline);
setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->prefs.useSystemTheme);
setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize);
setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"),
@@ -994,6 +1007,7 @@ iBool handleCommand_App(const char *cmd) {
selected_WidgetFlag,
iTrue);
setToggle_Widget(findChild_Widget(dlg, "prefs.biglede"), d->prefs.bigFirstParagraph);
setToggle_Widget(findChild_Widget(dlg, "prefs.sideicon"), d->prefs.sideIcon);
setFlags_Widget(
findChild_Widget(
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) {
d->font = nunito_TextFont;
d->lineWidth = 40;
d->bigFirstParagraph = iTrue;
d->docThemeDark = colorfulDark_GmDocumentTheme;
d->docThemeLight = white_GmDocumentTheme;
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 {
int lineWidth;
iBool bigFirstParagraph;
iBool forceLineWrap;
enum iGmDocumentTheme docThemeDark;
enum iGmDocumentTheme docThemeLight;
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 {
iRangecc text;
int font;
iRect rect;
int sepColor;
};
@@ -2058,13 +2058,15 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
// drawRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, red_ColorId);
}
-static void drawSideRect_(iPaint *p, iRect rect, int thickness) {
drawRectThickness_Paint(p, rect, thickness, tmBannerIcon_ColorId);
fillRect_Paint(p, rect, tmBannerBackground_ColorId);
+static int drawSideRect_(iPaint *p, iRect rect) { //}, int thickness) {
bg = tmBannerIcon_ColorId;
fg = tmBannerBackground_ColorId;
}
}
static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
@@ -2079,7 +2081,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
iPaint p;
init_Paint(&p);
setClip_Paint(&p, bounds);
if (banner && opacity > 0) {
setOpacity_Text(opacity);
SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
@@ -2088,16 +2090,16 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
p.alpha = opacity * 255;
//int offset = iMax(0, bottom_Rect(banner->visBounds) - d->scrollY);
rect.pos.y += height_Rect(bounds) / 2 - rect.size.y / 2 - (banner ? banner->visBounds.size.y / 2 : 0); // offset;
drawSideRect_(&p, rect, gap_UI / 2);
if (equal_Color(get_Color(tmBannerBackground_ColorId), get_Color(tmBackground_ColorId))) {
drawRectThickness_Paint(&p, rect, gap_UI / 2, tmBannerIcon_ColorId);
}
else {
fillRect_Paint(&p, rect, tmBannerBackground_ColorId);
}
int fg = drawSideRect_(&p, rect); //, gap_UI / 2);
+// if (equal_Color(get_Color(tmBannerBackground_ColorId), get_Color(tmBackground_ColorId))) {
+// drawRectThickness_Paint(&p, rect, gap_UI / 2, tmBannerIcon_ColorId);
+// }
+// else {
+// fillRect_Paint(&p, rect, tmBannerBackground_ColorId);
+// }
iString str;
initUnicodeN_String(&str, &icon, 1);
drawCentered_Text(banner_FontId, rect, iTrue, tmBannerIcon_ColorId, "%s", cstr_String(&str));
drawCentered_Text(banner_FontId, rect, iTrue, fg, "%s", cstr_String(&str));
#if 0
if (avail >= minBannerSize * 2) {
const char *endp;
@@ -2139,7 +2141,7 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
}
/* Outline on the right side. */
const float outlineOpacity = value_Anim(&d->outlineOpacity);
// const int font = uiLabel_FontId;
//iRect outlineRect = initCorners_Rect(topRight_Rect(docBounds), bottomRight_Rect(bounds));
//const int excess = width_Rect(outlineRect) - 75 * gap_UI;
@@ -2170,26 +2172,23 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) {
setOpacity_Text(outlineOpacity);
SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
p.alpha = outlineOpacity * 255;
drawSideRect_(
&p,
(iRect){ addY_I2(pos, -outlinePadding_DocumentWidget_ * gap_UI / 2),
init_I2(outWidth, outHeight + outlinePadding_DocumentWidget_ * gap_UI * 1.5f) },
1);
iRect outlineFrame = {
addY_I2(pos, -outlinePadding_DocumentWidget_ * gap_UI / 2),
init_I2(outWidth, outHeight + outlinePadding_DocumentWidget_ * gap_UI * 1.5f)
};
fillRect_Paint(&p, outlineFrame, tmBannerBackground_ColorId);
const int textFg = drawSideRect_(&p, outlineFrame); //, 1);
iConstForEach(Array, i, &d->outline) {
const iOutlineItem *item = i.value;
iInt2 visPos = addX_I2(add_I2(pos, item->rect.pos), outlinePadding_DocumentWidget_ * gap_UI);
-// visPos.y -= scroll;
-// if (item->sepColor != none_ColorId) {
-// drawHLine_Paint(&p, addY_I2(visPos, -gap_UI), outWidth, item->sepColor);
-// }
-// drawRect_Paint(&p, (iRect){ visPos, item->rect.size }, red_ColorId);
const iBool isVisible = d->lastVisibleRun && d->lastVisibleRun->text.start >= item->text.start;
drawWrapRange_Text(item->font,
visPos,
innerWidth - left_Rect(item->rect),
index_ArrayConstIterator(&i) == 0 || isVisible ? item->seenColor
: tmQuoteIcon_ColorId,
item->text);
const int fg = index_ArrayConstIterator(&i) == 0 || isVisible ? textFg
: tmQuoteIcon_ColorId;
drawWrapRange_Text(
item->font, visPos, innerWidth - left_Rect(item->rect), fg, item->text);
if (left_Rect(item->rect) > 0) {
drawRange_Text(item->font, addX_I2(visPos, -3 * gap_UI), fg, range_CStr("\u2013"));
}
}
setOpacity_Text(1.0f);
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) {
appendTwoColumnPage_(tabs, "General", '1', &headings, &values);
addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:")));
setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads");
addChild_Widget(headings, iClob(makeHeading_Widget("Outline on scrollbar:")));
addChild_Widget(values, iClob(makeToggle_Widget("prefs.hoveroutline")));
makeTwoColumnHeading_("WINDOW", headings, values);
#if defined (iPlatformApple) || defined (iPlatformMSys)
addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
@@ -939,6 +941,9 @@ iWidget *makePreferences_Widget(void) {
addChildFlags_Widget(values, iClob(widths), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
addChild_Widget(headings, iClob(makeHeading_Widget("Big 1st paragaph:")));
addChild_Widget(values, iClob(makeToggle_Widget("prefs.biglede")));
makeTwoColumnHeading_("WIDE LAYOUT", headings, values);
addChild_Widget(headings, iClob(makeHeading_Widget("Site icon:")));
addChild_Widget(values, iClob(makeToggle_Widget("prefs.sideicon")));
}
/* Colors. */ {
appendTwoColumnPage_(tabs, "Colors", '3', &headings, &values);
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).