From 232ddee30e2b8185b874f0a4c8f0018f2bba8156 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:31:45 +0900 Subject: [PATCH 1/3] Update scroll_area.rs --- crates/egui/src/containers/scroll_area.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index ab7da8aff29..9301a6abe55 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -817,15 +817,7 @@ 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)); - 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 @@ -833,6 +825,17 @@ impl Prepared { .pass_state_mut(|state| state.scroll_target[d].take()); if scroll_enabled[d] { + let (scroll_delta_0, scroll_delta_1) = content_ui.ctx().pass_state_mut(|state| { + ( + std::mem::take(&mut state.scroll_delta.0[d]), + std::mem::take(&mut 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_0; + let mut animation = scroll_delta_1; + if let Some(target) = scroll_target { let pass_state::ScrollTarget { range, From 2ba378d76b499b977223d407caa15983997305ac Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:51:14 +0900 Subject: [PATCH 2/3] Update scroll_area.rs --- crates/egui/src/containers/scroll_area.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 9301a6abe55..eeb654a940e 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -878,10 +878,10 @@ impl Prepared { if !animated { state.offset[d] = target_offset; - } else if let Some(animation) = &mut state.offset_target[d] { + } else if let Some(scroll_to_target) = &mut state.offset_target[d] { // For instance: the user is continuously calling `ui.scroll_to_cursor`, // so we don't want to reset the animation, but perhaps update the target: - animation.target_offset = target_offset; + scroll_to_target.target_offset = target_offset; } else { // The further we scroll, the more time we take. let now = ui.input(|i| i.time); From 3db13c1b213bcd6b2b413e45d356a4eefc3430f8 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:52:57 +0900 Subject: [PATCH 3/3] Update scroll_area.rs --- crates/egui/src/containers/scroll_area.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 5f1755adb8b..dc2f78445a0 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -886,10 +886,8 @@ impl Prepared { if !animated { state.offset[d] = target_offset; - } else if let Some(scroll_to_target) = &mut state.offset_target[d] { - // For instance: the user is continuously calling `ui.scroll_to_cursor`, - // so we don't want to reset the animation, but perhaps update the target: - scroll_to_target.target_offset = target_offset; + } else if let Some(_scroll_to_target) = &mut state.offset_target[d] { + // Probably in the middle of animation process. } else { // The further we scroll, the more time we take. let now = ui.input(|i| i.time);