mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Fix ScrollArea failure by handling horizontal and vertical scrolling separately in the missing place (#8275)
Fix ScrollArea failure by handling horizontal and vertical scrolling separately in the missing place Everywhere in `ScrollArea`, horizontal and vertical scrolling are handled separately. However, because there is a single place where they are not handled separately, when trying to process horizontal and vertical scrolls independently, one of the dimensions fails to scroll. This Pull Request ensures that horizontal and vertical scrolling are handled separately in this area, just like in the rest of the codebase. * Closes #5289 * Closes #5307 * Closes #8274
This commit is contained in:
@@ -1081,17 +1081,9 @@ impl Prepared {
|
||||
|
||||
let content_size = content_ui.min_size();
|
||||
|
||||
let scroll_delta = content_ui
|
||||
.ctx()
|
||||
.pass_state_mut(|state| std::mem::take(&mut state.scroll_delta));
|
||||
|
||||
let mut had_explicit_scroll_adjustment = Vec2b::FALSE;
|
||||
|
||||
for d in 0..2 {
|
||||
// PassState::scroll_delta is inverted from the way we apply the delta, so we need to negate it.
|
||||
let mut delta = -scroll_delta.0[d];
|
||||
let mut animation = scroll_delta.1;
|
||||
|
||||
// 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
|
||||
@@ -1099,6 +1091,17 @@ impl Prepared {
|
||||
.pass_state_mut(|state| state.scroll_target[d].take());
|
||||
|
||||
if direction_enabled[d] {
|
||||
let (scroll_delta, scroll_animation) = content_ui.ctx().pass_state_mut(|state| {
|
||||
(
|
||||
std::mem::take(&mut state.scroll_delta.0[d]),
|
||||
state.scroll_delta.1,
|
||||
)
|
||||
});
|
||||
|
||||
// PassState::scroll_delta is inverted from the way we apply the delta, so we need to negate it.
|
||||
let mut delta = -scroll_delta;
|
||||
let mut animation = scroll_animation;
|
||||
|
||||
if let Some(target) = scroll_target {
|
||||
let pass_state::ScrollTarget {
|
||||
range,
|
||||
@@ -1132,8 +1135,8 @@ impl Prepared {
|
||||
0.0
|
||||
};
|
||||
|
||||
delta += delta_update;
|
||||
animation = animation_update;
|
||||
delta += delta_update;
|
||||
}
|
||||
|
||||
if delta != 0.0 {
|
||||
@@ -1157,12 +1160,12 @@ impl Prepared {
|
||||
}
|
||||
ui.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
if delta != 0.0 {
|
||||
had_explicit_scroll_adjustment[d] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restore scroll target meant for ScrollAreas up the stack (if any)
|
||||
ui.ctx().pass_state_mut(|state| {
|
||||
|
||||
Reference in New Issue
Block a user