Skip to content

Commit 0f103c9

Browse files
committed
improve time panel time_ctrl overwrite behavior
1 parent 1b58679 commit 0f103c9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

crates/re_time_panel/src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ impl TimePanel {
6767
time_panel_expanded: bool,
6868
) {
6969
// Naturally, many parts of the time panel need the time control.
70-
// Copy it once, read/edit, and then write back at the end.
71-
let mut time_ctrl = ctx.rec_cfg.time_ctrl.read().clone();
70+
// Copy it once, read/edit, and then write back at the end if there was a change.
71+
let time_ctrl_before = ctx.rec_cfg.time_ctrl.read().clone();
72+
let mut time_ctrl_after = time_ctrl_before.clone();
7273

7374
// this is the size of everything above the central panel (window title bar, top bar on web,
7475
// etc.)
@@ -115,7 +116,7 @@ impl TimePanel {
115116
ui.horizontal(|ui| {
116117
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
117118
ui.visuals_mut().button_frame = true;
118-
self.collapsed_ui(ctx, ui, &mut time_ctrl);
119+
self.collapsed_ui(ctx, ui, &mut time_ctrl_after);
119120
});
120121
} else {
121122
// Expanded:
@@ -129,7 +130,7 @@ impl TimePanel {
129130
ui.horizontal(|ui| {
130131
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
131132
ui.visuals_mut().button_frame = true;
132-
self.top_row_ui(ctx, ui, &mut time_ctrl);
133+
self.top_row_ui(ctx, ui, &mut time_ctrl_after);
133134
});
134135
})
135136
.response
@@ -148,15 +149,20 @@ impl TimePanel {
148149
let mut streams_frame = egui::Frame::default();
149150
streams_frame.inner_margin.left = margin.x;
150151
streams_frame.show(ui, |ui| {
151-
self.expanded_ui(ctx, ui, &mut time_ctrl);
152+
self.expanded_ui(ctx, ui, &mut time_ctrl_after);
152153
});
153154
});
154155
}
155156
},
156157
);
157158

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

162168
#[allow(clippy::unused_self)]

crates/re_viewer_context/src/time_control.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use re_log_types::{Duration, TimeInt, TimeRange, TimeRangeF, TimeReal, TimeType,
66
use crate::NeedsRepaint;
77

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

2222
/// State per timeline.
23-
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)]
23+
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
2424
struct TimeState {
2525
/// The current time (play marker).
2626
time: TimeReal,
@@ -79,7 +79,7 @@ pub enum PlayState {
7979
}
8080

8181
/// Controls the global view and progress of the time.
82-
#[derive(serde::Deserialize, serde::Serialize, Clone)]
82+
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq)]
8383
#[serde(default)]
8484
pub struct TimeControl {
8585
/// Name of the timeline (e.g. "log_time").

0 commit comments

Comments
 (0)