diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-23 08:06:52 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-23 08:06:52 +0300 |
commit | ec5b815078eea53751a0b732268bc92e28a50ed5 (patch) | |
tree | fbf6e5381a2c9acca2d3db597258770bf07fbce9 | |
parent | 5b34ee8697c5da2a8c0b2fc0cec4120e18d5954d (diff) |
InputWidget: Per-pixel scrolling
-rw-r--r-- | src/ui/inputwidget.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index eb4cd0cf..6c84b161 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -451,7 +451,8 @@ static const iInputLine *findLineByWrapY_InputWidget_(const iInputWidget *d, int | |||
451 | 451 | ||
452 | static int visLineOffsetY_InputWidget_(const iInputWidget *d) { | 452 | static int visLineOffsetY_InputWidget_(const iInputWidget *d) { |
453 | const iInputLine *line = findLineByWrapY_InputWidget_(d, d->visWrapLines.start); | 453 | const iInputLine *line = findLineByWrapY_InputWidget_(d, d->visWrapLines.start); |
454 | return (line->wrapLines.start - d->visWrapLines.start) * lineHeight_Text(d->font); | 454 | return (line->wrapLines.start - d->visWrapLines.start) * lineHeight_Text(d->font) - |
455 | d->wheelAccum; | ||
455 | } | 456 | } |
456 | 457 | ||
457 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ | 458 | static const iChar sensitiveChar_ = 0x25cf; /* black circle */ |
@@ -1855,6 +1856,17 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const | |||
1855 | return ignored_EventResult; | 1856 | return ignored_EventResult; |
1856 | } | 1857 | } |
1857 | 1858 | ||
1859 | static void clampWheelAccum_InputWidget_(iInputWidget *d, int wheel) { | ||
1860 | if (wheel > 0 && d->visWrapLines.start == 0) { | ||
1861 | d->wheelAccum = 0; | ||
1862 | refresh_Widget(d); | ||
1863 | } | ||
1864 | else if (wheel < 0 && d->visWrapLines.end >= lastLine_InputWidget_(d)->wrapLines.end) { | ||
1865 | d->wheelAccum = 0; | ||
1866 | refresh_Widget(d); | ||
1867 | } | ||
1868 | } | ||
1869 | |||
1858 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | 1870 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { |
1859 | iWidget *w = as_Widget(d); | 1871 | iWidget *w = as_Widget(d); |
1860 | /* Resize according to width immediately. */ | 1872 | /* Resize according to width immediately. */ |
@@ -1956,24 +1968,26 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1956 | const int lineHeight = lineHeight_Text(d->font); | 1968 | const int lineHeight = lineHeight_Text(d->font); |
1957 | if (isPerPixel_MouseWheelEvent(&ev->wheel)) { | 1969 | if (isPerPixel_MouseWheelEvent(&ev->wheel)) { |
1958 | d->wheelAccum -= ev->wheel.y; | 1970 | d->wheelAccum -= ev->wheel.y; |
1971 | refresh_Widget(d); | ||
1959 | } | 1972 | } |
1960 | else { | 1973 | else { |
1961 | d->wheelAccum -= ev->wheel.y * 3 * lineHeight; | 1974 | d->wheelAccum -= ev->wheel.y * 3 * lineHeight; |
1962 | } | 1975 | } |
1976 | clampWheelAccum_InputWidget_(d, ev->wheel.y); | ||
1963 | int lineDelta = d->wheelAccum / lineHeight; | 1977 | int lineDelta = d->wheelAccum / lineHeight; |
1964 | if (lineDelta < 0) { | 1978 | if (lineDelta < 0) { |
1965 | lineDelta = iMax(lineDelta, -d->visWrapLines.start); | 1979 | lineDelta = iMax(lineDelta, -d->visWrapLines.start); |
1966 | if (!lineDelta) d->wheelAccum = 0; | 1980 | if (!lineDelta) d->wheelAccum = 0; |
1967 | } | 1981 | } |
1968 | else if (lineDelta > 0) { | 1982 | else if (lineDelta > 0) { |
1969 | lineDelta = iMin(lineDelta, | 1983 | lineDelta = iMin(lineDelta, lastLine_InputWidget_(d)->wrapLines.end - d->visWrapLines.end); |
1970 | lastLine_InputWidget_(d)->wrapLines.end - d->visWrapLines.end); | ||
1971 | if (!lineDelta) d->wheelAccum = 0; | 1984 | if (!lineDelta) d->wheelAccum = 0; |
1972 | } | 1985 | } |
1973 | if (lineDelta) { | 1986 | if (lineDelta) { |
1974 | d->wheelAccum -= lineDelta * lineHeight; | 1987 | d->wheelAccum -= lineDelta * lineHeight; |
1975 | d->visWrapLines.start += lineDelta; | 1988 | d->visWrapLines.start += lineDelta; |
1976 | d->visWrapLines.end += lineDelta; | 1989 | d->visWrapLines.end += lineDelta; |
1990 | clampWheelAccum_InputWidget_(d, ev->wheel.y); | ||
1977 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; | 1991 | d->inFlags |= needUpdateBuffer_InputWidgetFlag; |
1978 | refresh_Widget(d); | 1992 | refresh_Widget(d); |
1979 | return true_EventResult; | 1993 | return true_EventResult; |