Skip to content

Commit

Permalink
improve time panel time_ctrl overwrite behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Nov 29, 2023
1 parent 925994e commit 357b024
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 deletions crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ impl TimePanel {
time_panel_expanded: bool,
) {
// Naturally, many parts of the time panel need the time control.
// Copy it once, read/edit, and then write back at the end.
let mut time_ctrl = ctx.rec_cfg.time_ctrl.read().clone();
// Copy it once, read/edit, and then write back at the end if there was a change.
let time_ctrl_before = ctx.rec_cfg.time_ctrl.read().clone();
let mut time_ctrl_after = time_ctrl_before.clone();

// this is the size of everything above the central panel (window title bar, top bar on web,
// etc.)
Expand Down Expand Up @@ -115,7 +116,7 @@ impl TimePanel {
ui.horizontal(|ui| {
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
ui.visuals_mut().button_frame = true;
self.collapsed_ui(ctx, ui, &mut time_ctrl);
self.collapsed_ui(ctx, ui, &mut time_ctrl_after);
});
} else {
// Expanded:
Expand All @@ -129,7 +130,7 @@ impl TimePanel {
ui.horizontal(|ui| {
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
ui.visuals_mut().button_frame = true;
self.top_row_ui(ctx, ui, &mut time_ctrl);
self.top_row_ui(ctx, ui, &mut time_ctrl_after);
});
})
.response
Expand All @@ -148,15 +149,20 @@ impl TimePanel {
let mut streams_frame = egui::Frame::default();
streams_frame.inner_margin.left = margin.x;
streams_frame.show(ui, |ui| {
self.expanded_ui(ctx, ui, &mut time_ctrl);
self.expanded_ui(ctx, ui, &mut time_ctrl_after);
});
});
}
},
);

// Apply potential changes of the time control:
*ctx.rec_cfg.time_ctrl.write() = time_ctrl;
// Apply time control if there were any changes.
// This means that if anyone else meanwhile changed the time control, these changes are lost now.
// At least though we don't overwrite them if we didn't change anything at all.
// Since changes on the time control via the time panel are rare, this should be fine.
if time_ctrl_before != time_ctrl_after {
*ctx.rec_cfg.time_ctrl.write() = time_ctrl_after;
}
}

#[allow(clippy::unused_self)]
Expand Down
6 changes: 3 additions & 3 deletions crates/re_viewer_context/src/time_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use re_log_types::{Duration, TimeInt, TimeRange, TimeRangeF, TimeReal, TimeType,
use crate::NeedsRepaint;

/// The time range we are currently zoomed in on.
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
pub struct TimeView {
/// Where start of the range.
pub min: TimeReal,
Expand All @@ -20,7 +20,7 @@ pub struct TimeView {
}

/// State per timeline.
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
struct TimeState {
/// The current time (play marker).
time: TimeReal,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub enum PlayState {
}

/// Controls the global view and progress of the time.
#[derive(serde::Deserialize, serde::Serialize, Clone)]
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq)]
#[serde(default)]
pub struct TimeControl {
/// Name of the timeline (e.g. "log_time").
Expand Down

0 comments on commit 357b024

Please sign in to comment.