Fix nested scrolling (#83)
Add scroll_delta in FrameState to fix nested scrolling. Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
d7e03cb186
commit
46471f930d
2 changed files with 16 additions and 3 deletions
|
@ -230,9 +230,19 @@ impl Prepared {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check that nothing else is being interacted with
|
let max_offset = content_size.y - inner_rect.height();
|
||||||
if ui.rect_contains_mouse(outer_rect) {
|
if ui.rect_contains_mouse(outer_rect) {
|
||||||
state.offset.y -= ui.input().scroll_delta.y;
|
let mut frame_state = ui.ctx().frame_state();
|
||||||
|
let scroll_delta = frame_state.scroll_delta;
|
||||||
|
|
||||||
|
let scrolling_up = state.offset.y > 0.0 && scroll_delta.y > 0.0;
|
||||||
|
let scrolling_down = state.offset.y < max_offset && scroll_delta.y < 0.0;
|
||||||
|
|
||||||
|
if scrolling_up || scrolling_down {
|
||||||
|
state.offset.y -= scroll_delta.y;
|
||||||
|
// Clear scroll delta so no parent scroll will use it.
|
||||||
|
frame_state.scroll_delta = Vec2::zero();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let show_scroll_this_frame = content_is_too_small || always_show_scroll;
|
let show_scroll_this_frame = content_is_too_small || always_show_scroll;
|
||||||
|
@ -286,7 +296,7 @@ impl Prepared {
|
||||||
}
|
}
|
||||||
|
|
||||||
state.offset.y = state.offset.y.max(0.0);
|
state.offset.y = state.offset.y.max(0.0);
|
||||||
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
|
state.offset.y = state.offset.y.min(max_offset);
|
||||||
|
|
||||||
// Avoid frame-delay by calculating a new handle rect:
|
// Avoid frame-delay by calculating a new handle rect:
|
||||||
let mut handle_rect = Rect::from_min_max(
|
let mut handle_rect = Rect::from_min_max(
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub(crate) struct FrameState {
|
||||||
|
|
||||||
/// How much space is used by panels.
|
/// How much space is used by panels.
|
||||||
used_by_panels: Rect,
|
used_by_panels: Rect,
|
||||||
|
pub(crate) scroll_delta: Vec2,
|
||||||
pub(crate) scroll_target: Option<(f32, Align)>,
|
pub(crate) scroll_target: Option<(f32, Align)>,
|
||||||
// TODO: move some things from `Memory` to here
|
// TODO: move some things from `Memory` to here
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,7 @@ impl Default for FrameState {
|
||||||
available_rect: Rect::invalid(),
|
available_rect: Rect::invalid(),
|
||||||
unused_rect: Rect::invalid(),
|
unused_rect: Rect::invalid(),
|
||||||
used_by_panels: Rect::invalid(),
|
used_by_panels: Rect::invalid(),
|
||||||
|
scroll_delta: Vec2::zero(),
|
||||||
scroll_target: None,
|
scroll_target: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +60,7 @@ impl FrameState {
|
||||||
self.available_rect = input.screen_rect();
|
self.available_rect = input.screen_rect();
|
||||||
self.unused_rect = input.screen_rect();
|
self.unused_rect = input.screen_rect();
|
||||||
self.used_by_panels = Rect::nothing();
|
self.used_by_panels = Rect::nothing();
|
||||||
|
self.scroll_delta = input.scroll_delta;
|
||||||
self.scroll_target = None;
|
self.scroll_target = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue