Skip to content

Commit

Permalink
Added an option to disable smooth scrolling
Browse files Browse the repository at this point in the history
IssueID #27
  • Loading branch information
skyjake committed Nov 6, 2020
1 parent a4a7a75 commit 6ffe005
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static iString *serializePrefs_App_(const iApp *d) {
appendFormat_String(str, "font.set arg:%d\n", d->prefs.font);
appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont);
appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling);
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, "prefs.sideicon.changed arg:%d\n", d->prefs.sideIcon);
Expand Down Expand Up @@ -735,6 +736,8 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) {
cstr_String(text_InputWidget(findChild_Widget(d, "prefs.downloads"))));
postCommandf_App("window.retain arg:%d",
isSelected_Widget(findChild_Widget(d, "prefs.retainwindow")));
postCommandf_App("smoothscroll arg:%d",
isSelected_Widget(findChild_Widget(d, "prefs.smoothscroll")));
postCommandf_App("ostheme arg:%d",
isSelected_Widget(findChild_Widget(d, "prefs.ostheme")));
postCommandf_App("proxy.http address:%s",
Expand Down Expand Up @@ -942,6 +945,10 @@ iBool handleCommand_App(const char *cmd) {
postCommand_App("window.unfreeze");
return iTrue;
}
else if (equal_Command(cmd, "smoothscroll")) {
d->prefs.smoothScrolling = arg_Command(cmd);
return iTrue;
}
else if (equal_Command(cmd, "forcewrap.toggle")) {
d->prefs.forceLineWrap = !d->prefs.forceLineWrap;
updateSize_DocumentWidget(document_App());
Expand Down Expand Up @@ -1119,6 +1126,7 @@ iBool handleCommand_App(const char *cmd) {
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.smoothscroll"), d->prefs.smoothScrolling);
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"),
Expand Down
1 change: 1 addition & 0 deletions src/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void init_Prefs(iPrefs *d) {
d->useSystemTheme = iTrue;
d->retainWindowSize = iTrue;
d->zoomPercent = 100;
d->smoothScrolling = iTrue;
d->forceLineWrap = iFalse;
d->quoteIcon = iTrue;
d->font = nunito_TextFont;
Expand Down
3 changes: 2 additions & 1 deletion src/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ iDeclareType(Prefs)
struct Impl_Prefs {
int dialogTab;
iBool retainWindowSize;
float uiScale;
float uiScale;
int zoomPercent;
iBool smoothScrolling;
iBool useSystemTheme;
enum iColorTheme theme;
iString gopherProxy;
Expand Down
10 changes: 9 additions & 1 deletion src/ui/documentwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ static void refreshWhileScrolling_DocumentWidget_(iAny *ptr) {
}

static void smoothScroll_DocumentWidget_(iDocumentWidget *d, int offset, int duration) {
if (!prefs_App()->smoothScrolling) {
duration = 0; /* always instant */
}
int destY = targetValue_Anim(&d->scrollY) + offset;
if (destY < 0) {
destY = 0;
Expand All @@ -958,7 +961,12 @@ static void smoothScroll_DocumentWidget_(iDocumentWidget *d, int offset, int dur
else {
destY = 0;
}
setValueEased_Anim(&d->scrollY, destY, duration);
if (duration) {
setValueEased_Anim(&d->scrollY, destY, duration);
}
else {
setValue_Anim(&d->scrollY, destY, 0);
}
updateVisible_DocumentWidget_(d);
refresh_Widget(as_Widget(d));
if (duration > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/ui/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static float valueAt_Anim_(const iAnim *d, const uint32_t now) {
void setValue_Anim(iAnim *d, float to, uint32_t span) {
if (span == 0) {
d->from = d->to = to;
d->when = d->due = SDL_GetTicks();
d->when = d->due = frameTime_Window(get_Window()); /* effectively in the past */
}
else if (fabsf(to - d->to) > 0.00001f) {
const uint32_t now = SDL_GetTicks();
Expand Down Expand Up @@ -997,6 +997,8 @@ iWidget *makePreferences_Widget(void) {
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")));
addChild_Widget(headings, iClob(makeHeading_Widget("Smooth scrolling:")));
addChild_Widget(values, iClob(makeToggle_Widget("prefs.smoothscroll")));
makeTwoColumnHeading_("WINDOW", headings, values);
#if defined (iPlatformApple) || defined (iPlatformMSys)
addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
Expand Down

0 comments on commit 6ffe005

Please sign in to comment.