Skip to content
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

Fix: scroll_with_delta() for ScrollArea::vertical() and ScrollArea::horizontal() #4893

Closed
wants to merge 4 commits into from

Conversation

rustbasic
Copy link
Contributor

Fix: scroll_with_delta() for ScrollArea::vertical() and ScrollArea::horizontal()

We need to do this in order for ScrollArea::vertical() and ScrollArea::horizontal() to work even where they are divided or nested.

Pull requests :

@rustbasic rustbasic changed the title Update scroll_area.rs Fix: scroll_with_delta() for ScrollArea::vertical() and ScrollArea::horizontal() Jul 31, 2024
// We always take both scroll targets regardless of which scroll axes are enabled. This
// is to avoid them leaking to other scroll areas.
let scroll_target = content_ui
.ctx()
.frame_state_mut(|state| state.scroll_target[d].take());

if scroll_enabled[d] {
let (scroll_delta_0, scroll_delta_1) = content_ui.ctx().frame_state_mut(|state| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be solved by using less lines of code if wanted

let (mut delta, mut animation) = content_ui.ctx().frame_state_mut(|state| {
                    (
                        -std::mem::take(&mut state.scroll_delta.0[d]),
                        std::mem::take(&mut state.scroll_delta.1),
                    )
                });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using - here is bad for readability.

It's okay to do let (scroll_delta, scroll_animation), but since it's only used temporarily, it's not a big problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right

@rustbasic rustbasic closed this Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants