-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add methods to control Scrollable
programmatically
#607
Conversation
4730e65
to
20529ec
Compare
4c57afd
to
34b381c
Compare
34b381c
to
e84b213
Compare
98fe127
to
38b0171
Compare
b1b5f8b
to
dec0e0a
Compare
|
Haha, same. It's why I implemented this feature in the first place :D |
I've also found myself needing this, as I am implementing a search results list and need to scroll so that the result focused after a |
In the meantime here's a disgusting hack to self.scroll = unsafe {
let mut tmp = std::mem::transmute::<_, (Option<f32>, f32)>(self.scroll);
tmp.1 = 999999.0;
std::mem::transmute::<_, scrollable::State>(tmp)
}; (Assuming Caveat: Dirty, disgusting, unsafe, brittle, use at your own risk. |
dec0e0a
to
21e8ad5
Compare
e850e80
to
73750fc
Compare
73750fc
to
cc80110
Compare
cc80110
to
5a376ae
Compare
О! That's just what I need! Thank you! |
…e cases, add snap_to_bottom by default
5a376ae
to
f7d6e40
Compare
I made some changes that I believe simplify everything overall. Specifically:
I have also updated the Let me know what you think! |
Looks nice! Deferring the computation is nice, I like that. Can it be merged soon then? |
@yusdacra Yes! Let's merge and fix any potential issues and implement new use cases as they come up. |
Thank you everyone! 🎉 |
This PR adds methods:
snap_to_bottom
andon_scroll
toScrollable
snap_to_bottom
takes a bool and if true makes theScrollable
snap to bottom when the user scrolls to bottom. If the contents of theScrollable
change, it will automatically snap to bottom. Whenever the user scrolls up it will stop snapping to bottom. By default aScrollable
won't snap to bottom.on_scroll
takes a function whose arguments are twof32
s and produces aMessage
. First argument is to pass the currentoffset
of theScrollable
to provide the user with "where is thisScrollable
at right now" and second argument is to pass the previousoffset
of theScrollable
to provide the user with "where was thisScrollable
before this scroll event".scroll_to_percentage
andscroll_to_bottom
toscrollable::State
scroll_to_percentage
takes a value between0.0
and1.0
. It marks theScrollable
to scroll to the specified percentage in the nextdraw
call.scroll_to_bottom
is just a shorthand forscroll_to_percentage(1.0)
.This should fix #307
I wonder what people think about this so please post your thoughts!