From bc2f7406f6e573c486cd3e6b7460ff13d1b9eba1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Wed, 25 May 2022 14:07:18 +0300
Subject: [PATCH 1/1] Improving overflow scrolling for desktop
This will require some fixing on mobile, later.
src/ui/root.c | 5 ++++-
src/ui/widget.c | 31 ++++++++++++++++++++-----------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/ui/root.c b/src/ui/root.c
index 7637d842..6f2868b7 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -2160,7 +2160,10 @@ iRect visibleRect_Root(const iRoot *d) {
#endif
#if defined (iPlatformDesktop)
/* Apply the usable bounds of the display. */
returned here seem incorrect sometimes (infrequently). */
const float ratio = d->window->pixelRatio;
SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(d->window->win), &usable);
iInt2 winPos;
diff --git a/src/ui/widget.c b/src/ui/widget.c
index addab9f0..ef2ac868 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -1291,19 +1291,25 @@ iBool scrollOverflow_Widget(iWidget *d, int delta) {
}
iRect bounds = boundsWithoutVisualOffset_Widget(d);
const iRect winRect = visibleRect_Root(d->root);
+// const int yTop = iMaxi(0, top_Rect(winRect));
+// const int yBottom = bottom_Rect(winRect);
iRangei validPosRange = { bottom_Rect(winRect) - height_Rect(bounds),
iMaxi(0, top_Rect(winRect)) };
validPosRange.start = validPosRange.end; /* no room to scroll */
+// if (validPosRange.end < validPosRange.start) {
+// validPosRange.end = validPosRange.start; /* no room to scroll */
+// }
+// if ((!isTopOver && delta < 0) || (!isBottomOver && delta > 0)) {
+// delta = 0;
+// }
if (delta) {
if (delta < 0 && bounds.pos.y < validPosRange.start) {
delta = 0;
}
if (delta > 0 && bounds.pos.y > validPosRange.end) {
delta = 0;
}
//printf("delta:%d validPosRange:%d...%d\n", delta, validPosRange.start, validPosRange.end); fflush(stdout);
+// if (delta < 0 && bounds.pos.y < validPosRange.start) {
+// delta = 0;
+// }
+// if (delta > 0 && bounds.pos.y > validPosRange.end) {
+// delta = 0;
+// }
+// printf("delta:%d validPosRange:%d...%d\n", delta, validPosRange.start, validPosRange.end); fflush(stdout);
bounds.pos.y += delta;
if (delta < 0) {
bounds.pos.y = iMax(bounds.pos.y, validPosRange.start);
@@ -1316,7 +1322,10 @@ iBool scrollOverflow_Widget(iWidget *d, int delta) {
}
}
else {
bounds.pos.y = iClamp(bounds.pos.y, validPosRange.start, validPosRange.end);
/* TODO: This is used on mobile. */
+// printf("clamping validPosRange:%d...%d\n", validPosRange.start, validPosRange.end); fflush(stdout);
+// bounds.pos.y = iClamp(bounds.pos.y, validPosRange.start, validPosRange.end);
}
const iInt2 newPos = windowToInner_Widget(d->parent, bounds.pos);
if (!isEqual_I2(newPos, d->rect.pos)) {
--
2.25.1
text/plain
This content has been proxied by September (3851b).