-
-
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 scrollable alignment option #1912
Conversation
3e0b189
to
cdd2a39
Compare
e1445be
to
bd4cad9
Compare
bd4cad9
to
d79cedd
Compare
Let's tackle use cases directly instead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 🎉 I imagine this will be very useful for chat clients; especially when loading message history.
I have made some changes here and there to make things a bit more type-safe and disambiguate offset
from translation
. I have also made the fields in Viewport
private again, since I'm not sure which use cases warrant exposing those. Hopefully we can tackle them directly!
Let's merge this! 🥳
@hecrj I was using the bounds & content_bounds fields for calculating the new absolute offset needed to keep the scrollable anchored in the correct location when toggling between start / end alignments. This is needed in a chat application, consider the following. We use end alignment by default so new messages show up. When scrolling up from the bottom, we convert to start alignment so new messages don't change the position of the viewport. When swapping alignments, we need to issue See https://github.com/squidowl/halloy/blob/caa024de2962d9646d62c34bcf565b1c7e9056b8/src/buffer/scroll_view.rs#L298-L305 for how we do this. So I guess a direct use-case solution might be to expose a |
@tarkah I think we can expose a |
I don't believe this works because Since |
@tarkah In the snippet you shared, it seems the only thing we'd need to expose is It seems you are computing the alignment from the Am I missing something? |
Having that exposed is all I need. However, this isn't the scroll translation, it's the max scroll height. When flipping between alignments, I take max scroll height minus current absolute offset to match the change in alignment. |
It's not, my bad! I think a simple |
This PR adds a new
Alignment
option to both directions of the scrollable.It's sometimes preferred to have the content aligned to the end of the scrollable by default, where the offsets are based on the end of the scrollable. New content getting added will cause the scrollable to expand up instead of down.
Alignment::End
enables this behavior.