From e3dd6f32dd9a46cac6193e8d05048127c652fb80 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:01:20 +0100 Subject: [PATCH] Restore `egui_plot` auto-bounds state after dragging the time cursor in timeseries space views (#4270) ### What * Fixes https://github.com/rerun-io/rerun/issues/4246 * Depends on https://github.com/emilk/egui/pull/3586 * Blocked on #4111 ![Export-1701442441839](https://github.com/rerun-io/rerun/assets/49431240/d02f7d64-801a-4fe4-8ec1-20524ba78bd5) ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4270) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4270) - [Docs preview](https://rerun.io/preview/2706326572e06cf2623136a62fee75d75b490fdd/docs) - [Examples preview](https://rerun.io/preview/2706326572e06cf2623136a62fee75d75b490fdd/examples) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) --------- Co-authored-by: Andreas Reich Co-authored-by: Emil Ernerfeldt --- .../src/space_view_class.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/re_space_view_time_series/src/space_view_class.rs b/crates/re_space_view_time_series/src/space_view_class.rs index 6f2df44303ef..ebb5cc6666b4 100644 --- a/crates/re_space_view_time_series/src/space_view_class.rs +++ b/crates/re_space_view_time_series/src/space_view_class.rs @@ -17,8 +17,14 @@ use crate::view_part_system::{PlotSeriesKind, TimeSeriesSystem}; #[derive(Clone, Default)] pub struct TimeSeriesSpaceViewState { - /// track across frames when the user moves the time cursor + /// Is the user dragging the cursor this frame? is_dragging_time_cursor: bool, + + /// Was the user dragging the cursor last frame? + was_dragging_time_cursor: bool, + + /// State of egui_plot's auto bounds before the user started dragging the time cursor. + saved_auto_bounds: egui::Vec2b, } impl SpaceViewState for TimeSeriesSpaceViewState { @@ -272,11 +278,18 @@ impl SpaceViewClass for TimeSeriesSpaceView { } if state.is_dragging_time_cursor { + if !state.was_dragging_time_cursor { + state.saved_auto_bounds = plot_ui.auto_bounds(); + } // Freeze any change to the plot boundaries to avoid weird interaction with the time // cursor. plot_ui.set_plot_bounds(plot_ui.plot_bounds()); + } else if state.was_dragging_time_cursor { + plot_ui.set_auto_bounds(state.saved_auto_bounds); } + state.was_dragging_time_cursor = state.is_dragging_time_cursor; + // decide if the time cursor should be displayed, and if where current_time .map(|current_time| (current_time - time_offset) as f64)