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

Restore egui_plot auto-bounds state after dragging the time cursor in timeseries space views #4270

Merged
merged 18 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading