-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement SmoothScroll #201
Conversation
I tested it in lessons, it's working fine. It does conflict with existing code to scroll with keyboard shortcuts, so that needs fixes. It'd be nice to add keyboard focus and standard web shortcuts to the smooth scroll container. See UICore.gd._input(): if event.is_action_pressed("scroll_up_one_page"):
scroll_container.scroll_vertical -= 800
elif event.is_action_pressed("scroll_down_one_page"):
scroll_container.scroll_vertical += 800
elif event.is_action("scroll_up") and (event as InputEventMouseButton).pressed:
scroll_container.scroll_vertical -= 80
elif event.is_action("scroll_down") and (event as InputEventMouseButton).pressed:
scroll_container.scroll_vertical += 80
elif event.is_action_pressed("scroll_to_top"):
scroll_container.scroll_vertical = 0
elif event.is_action_pressed("scroll_to_bottom"):
scroll_container.scroll_vertical = 1000000 The plugin.gd file also causes an error on load in Godot. @pycbouh could you check this and tell me what you think? I think I'd like to refactor the code to make it match the rest of our codebase, make it a bit easier to read, and maintain it internally. |
With the latest commit, the shortcuts are working again. "The plugin.gd file also causes an error on load in Godot." |
Thanks. The update cleared the error - it was likely just a godot / caching issue so don't worry about it. |
The PR should also fix #114, but I'd need people who face the bug to test this. |
@SpyrexDE are you okay with us refactoring your code? It's about formatting, renaming some variables, replacing some comments with names in code. |
No problem 👍 |
Thanks, I refactored the code, and I'll add the setting shortly |
It's working pretty well by the way, thanks much for the contribution! |
Multiplies the smooth scrolling's velocity
The current implementation of smooth scrolling is a bit limiting, to me. That's because of the use of velocity rather than target scrolling positions. With keyboard shortcuts, we don't have fine control over the scrolling intervals. Now, with the scrolling sensitivity setting, there's no good way to only apply it to scrolling with the mouse/touchpad. I think we could benefit from an implementation that tweens (or rather, probably steers) scrolling to a target position. It would make the overscroll control perhaps slightly more difficult to implement but would make the input more consistent and easier to unify. |
Okay so I gave this idea a spin.You can find the result in commit 54f95dd This prototype removes support for over-drag (it needs to be re-added). However, as mentioned above, it gives us precise control over the scroll level. We can use that to:
This also re-adds support for scrolling with the up and down arrow keys, including support for echo events. Also, over-dragging shouldn't be too hard to achieve, it can leverage the steering equation. @pycbouh could you give this a try when you have a moment and tell me what you think? Current known issues:
|
Looks great! The implementation using a
|
That's also possible with velocity-based scrolling (see velocity_scroll branch): 2022-01-29.15-53-24.mp4
Already implemented in velocity-based scrolling.
Well, scrolling with touchscreens works much differently but is possible to implement.
It's actually the same with velocity-based scrolling, I don't get your point there 🤔 |
Steering is just a different equation that simplifies the code - it's still velocity-based. You just need less code, less state to keep track of. I was not saying other things are not possible, I was saying some weren't implemented in the PR before. The use of steering gives you horizontal + vertical support only with a couple of lines of code - there's no need for extra code or conditions. The less state you have in your code, the less maintenance work you have. For that reason, we favor implementations that reduce the need for extra boolean switches and whatnot. |
The latest commit should address the issues you listed above. I can't reproduce the issue of scrolling past the top, do you still have it? |
You are right, maintainability might be more important at this point.
Unfortunately, yes: 2022-01-29.16-50-14.mp4(It's the same at the bottom) |
Okay, I couldn't reproduce it but I think the code change should've fixed it - I lowered the arrive threshold and moved the distance check to the top of _process. |
yep, works perfectly now 👌 |
After testing smooth scrolling in Brave/Chrome and Firefox, I made the base settings a bit faster to get a bit closer. I'd like your thoughts on that. You can still lower the sensitivity to make it slower. The last commit also makes scrolling to top/bottom about 4x faster. @Xananax @pycbouh when you have a moment I'd also like your feedback on this smooth scrolling feature before merging (no hurry though). |
It definitely feels more like Brave/Chrome and Firefox now but these web browsers have no max scroll speed. It feels a bit undynamic when having a constant velocity while scrolling fast. |
No, it could scale based on the distance to the target. I was seeing firefox's scrolling accelerates when you quickly scroll the mouse wheel. We can try that and see. I need you guys' feedback for that actually, I don't know what feels and works best for other people. |
I agree. Feedback is very important for this kind of thing. I tried it on my touchpad again and it's pretty okay using the lowest scroll speed option. |
I tried a few changes. The latest commit makes speed scale with the distance to the target. I tried with some easing curves but proportional seems to work fine. It makes scroll to top / bottom really snappy. There's also a distance threshold so it doesn't accelerate below a certain scroll amount. Now, please feel free to tweak the constants and settings. It works fine on my computer, with a pretty fast base scroll. I think the SCROLL_INCREMENT could be a bit too high for the average user for instance. Maybe the base speed too. I tend to use fast anims, scroll, key repeat speeds etc. so I'm not the right person to set good default. |
For me, these settings feel good when using a mouse wheel. |
I added damping based on the frequency of mouse wheel events. Because dragging on the touchpad generates many more events than when using the mouse wheel, this helps to make the touchpad scroll more like the mouse in terms of amplitude. What it does is dampen the change in target position with successive events happening in a short time span. Could you try and tell me how it feels for you now? |
It still doesn't feel great. I think that it is not really possible to achieve good touchpad scrolling because of the lack of input information the scroll input event is giving you. For me, the best results are still on the 748c52d commit. |
This reverts commit 812bda5.
Definitely, at some point, this will need work on Godot's side. Especially if some users experience bugs. I reverted the last changes. |
And the comments from reduz... he used to instantly reject some ideas back when Godot didn't have as many contributors and users. These days with proposals things might be different: if enough people vouched for the need for smooth scrolling, or, probably more in line with Godot's philosophy, for improvements that would allow for that (more control on scroll bars, distinguishing touchpad events) that could get accepted. |
Report from my teammate @Xananax. Seems input works differently in different browsers too.
|
My teammate confirmed that without dampening or skipping some input events, this bug #114 still happens. The issues are:
This causes scrolling to be too fast for some people. Dampening like in the previous commit was one option, another is to throttle the input events - discarding a number of them when they occur too fast. |
From @Xananax
|
Okay I'm gonna merge what we have so far as it's an improvement and we'll add input event throttling later to try and fix #114 |
Thanks much for the contribution and testing @SpyrexDE ! |
Please check if the PR fulfills these requirements:
Related issue (if applicable): #164
What kind of change does this PR introduce?
It adds a SmoothScroll addon and implements it's SmoothScrollContainer class by replacing every ScrollContainer with a SmoothScrollContainer.
Does this PR introduce a breaking change?
No.
New feature or change
What is the current behavior?
Jaggy scrolling makes it hard to read and feels unresponsive.
What is the new behavior?
Adjustable, smooth scrolling with some "overdrag" for more responsiveness.
Video footage on YouTube
Other information
Maintainance
I will try my best to maintain this add-on in the future. For any SmoothScroll-related issues please assign me so I get notified.