Skip to content

Commit 76629b9

Browse files
authored
Fix links for custom timelines (#11333)
1 parent dfe4820 commit 76629b9

File tree

7 files changed

+90
-18
lines changed

7 files changed

+90
-18
lines changed

crates/viewer/re_global_context/src/command_sender.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ pub enum SystemCommand {
112112
store_id: StoreId,
113113
timeline: re_chunk::Timeline,
114114
time: Option<re_log_types::TimeReal>,
115+
116+
/// If this is true the timeline will persist even if it is invalid at the moment.
117+
pending: bool,
115118
},
116119

117120
/// Set the loop selection for the given timeline.

crates/viewer/re_test_context/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ impl TestContext {
569569
store_id,
570570
timeline: re_chunk::Timeline::new(timeline, timecell.typ()),
571571
time: Some(timecell.as_i64().into()),
572+
pending: true,
572573
});
573574
}
574575
}
@@ -617,13 +618,18 @@ impl TestContext {
617618
store_id: rec_id,
618619
timeline,
619620
time,
621+
pending,
620622
} => {
621623
assert_eq!(
622624
&rec_id,
623625
self.store_hub.lock().active_recording().unwrap().store_id()
624626
);
625627
let mut time_ctrl = self.recording_config.time_ctrl.write();
626-
time_ctrl.set_timeline(timeline);
628+
if pending {
629+
time_ctrl.set_pending_timeline(timeline);
630+
} else {
631+
time_ctrl.set_timeline(timeline);
632+
}
627633
if let Some(time) = time {
628634
time_ctrl.set_time(time);
629635
}

crates/viewer/re_time_panel/src/time_panel.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,30 @@ impl TimePanel {
395395
) {
396396
re_tracing::profile_function!();
397397

398+
if time_ctrl.is_pending() {
399+
ui.loading_screen_ui(|ui| {
400+
ui.label(
401+
egui::RichText::from(format!(
402+
"Waiting for timeline: {}",
403+
time_ctrl.timeline().name()
404+
))
405+
.heading()
406+
.strong(),
407+
);
408+
if ui
409+
.button(
410+
egui::RichText::new("Go to default timeline")
411+
.color(ui.style().visuals.weak_text_color()),
412+
)
413+
.clicked()
414+
{
415+
time_ctrl.set_timeline(*time_ctrl.timeline());
416+
}
417+
});
418+
419+
return;
420+
}
421+
398422
// |timeline |
399423
// ------------------------------------
400424
// tree |streams |

crates/viewer/re_ui/src/ui_ext.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -784,22 +784,29 @@ pub trait UiExt {
784784
response
785785
}
786786

787+
fn loading_screen_ui<R>(&mut self, add_contents: impl FnOnce(&mut egui::Ui) -> R) -> R {
788+
self.ui_mut().center("loading spinner", |ui| {
789+
ui.vertical_centered(|ui| {
790+
ui.spinner();
791+
add_contents(ui)
792+
})
793+
.inner
794+
})
795+
}
796+
787797
fn loading_screen(
788798
&mut self,
789799
header: impl Into<egui::RichText>,
790800
source: impl Into<egui::RichText>,
791801
) {
792-
self.ui_mut().center("loading spinner", |ui| {
793-
ui.vertical_centered(|ui| {
794-
ui.spinner();
795-
ui.label(
796-
header
797-
.into()
798-
.heading()
799-
.color(ui.style().visuals.weak_text_color()),
800-
);
801-
ui.strong(source);
802-
});
802+
self.loading_screen_ui(|ui| {
803+
ui.label(
804+
header
805+
.into()
806+
.heading()
807+
.color(ui.style().visuals.weak_text_color()),
808+
);
809+
ui.strong(source);
803810
});
804811
}
805812

crates/viewer/re_view_dataframe/src/dataframe_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ impl egui_table::TableDelegate for DataframeTableDelegate<'_> {
377377
store_id: self.ctx.store_id().clone(),
378378
timeline: descr.timeline(),
379379
time: None,
380+
pending: false,
380381
},
381382
);
382383
}

crates/viewer/re_viewer/src/app.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,11 +900,16 @@ impl App {
900900
store_id,
901901
timeline,
902902
time,
903+
pending,
903904
} => {
904905
if let Some(rec_cfg) = self.recording_config_mut(store_hub, &store_id) {
905906
let mut time_ctrl = rec_cfg.time_ctrl.write();
906907

907-
time_ctrl.set_timeline(timeline);
908+
if pending {
909+
time_ctrl.set_pending_timeline(timeline);
910+
} else {
911+
time_ctrl.set_timeline(timeline);
912+
}
908913

909914
if let Some(time) = time {
910915
time_ctrl.set_time(time);
@@ -1142,6 +1147,7 @@ impl App {
11421147
store_id,
11431148
timeline: re_chunk::Timeline::new(timeline, timecell.typ()),
11441149
time: Some(timecell.as_i64().into()),
1150+
pending: true,
11451151
});
11461152
}
11471153
}

crates/viewer/re_viewer_context/src/time_control.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub enum PlayState {
103103
enum ActiveTimeline {
104104
Auto(Timeline),
105105
UserEdited(Timeline),
106+
Pending(Timeline),
106107
}
107108

108109
impl std::ops::Deref for ActiveTimeline {
@@ -111,7 +112,7 @@ impl std::ops::Deref for ActiveTimeline {
111112
#[inline]
112113
fn deref(&self) -> &Self::Target {
113114
match self {
114-
Self::Auto(t) | Self::UserEdited(t) => t,
115+
Self::Auto(t) | Self::UserEdited(t) | Self::Pending(t) => t,
115116
}
116117
}
117118
}
@@ -569,10 +570,25 @@ impl TimeControl {
569570
false
570571
}
571572

572-
// If the timeline is auto refresh it every frame, otherwise only pick a new one if invalid.
573-
if matches!(self.timeline, ActiveTimeline::Auto(_))
574-
|| !is_timeline_valid(self.timeline(), times_per_timeline)
575-
{
573+
let reset_timeline = match &self.timeline {
574+
// If the timeline is auto refresh it every frame.
575+
ActiveTimeline::Auto(_) => true,
576+
// If it's user edited, refresh it if it's invalid.
577+
ActiveTimeline::UserEdited(timeline) => {
578+
!is_timeline_valid(timeline, times_per_timeline)
579+
}
580+
// If it's pending never automatically refresh it.
581+
ActiveTimeline::Pending(timeline) => {
582+
// If the pending timeline is valid, it shouldn't be pending anymore.
583+
if is_timeline_valid(timeline, times_per_timeline) {
584+
self.set_timeline(*timeline);
585+
}
586+
587+
false
588+
}
589+
};
590+
591+
if reset_timeline {
576592
self.timeline =
577593
ActiveTimeline::Auto(default_timeline(times_per_timeline.timelines_with_stats()));
578594
}
@@ -593,6 +609,10 @@ impl TimeControl {
593609
self.timeline = ActiveTimeline::UserEdited(timeline);
594610
}
595611

612+
pub fn set_pending_timeline(&mut self, timeline: Timeline) {
613+
self.timeline = ActiveTimeline::Pending(timeline);
614+
}
615+
596616
/// The current time.
597617
pub fn time(&self) -> Option<TimeReal> {
598618
self.states
@@ -695,6 +715,11 @@ impl TimeControl {
695715
}
696716
}
697717

718+
/// Is the active timeline pending?
719+
pub fn is_pending(&self) -> bool {
720+
matches!(self.timeline, ActiveTimeline::Pending(_))
721+
}
722+
698723
pub fn set_timeline_and_time(&mut self, timeline: Timeline, time: impl Into<TimeReal>) {
699724
self.timeline = ActiveTimeline::UserEdited(timeline);
700725
self.set_time(time);

0 commit comments

Comments
 (0)