diff --git a/crates/re_ui/src/command.rs b/crates/re_ui/src/command.rs index 196f74e7d72c..55f1aa2a430a 100644 --- a/crates/re_ui/src/command.rs +++ b/crates/re_ui/src/command.rs @@ -45,6 +45,7 @@ pub enum Command { PlaybackTogglePlayPause, PlaybackStepBack, PlaybackStepForward, + PlaybackRestart, } impl Command { @@ -124,6 +125,7 @@ impl Command { "Step time forward", "Move the time marker to the next point in time with any data", ), + Command::PlaybackRestart => ("Restart", "Restart from beginning of timeline"), } } @@ -183,6 +185,7 @@ impl Command { Command::PlaybackTogglePlayPause => Some(key(Key::Space)), Command::PlaybackStepBack => Some(key(Key::ArrowLeft)), Command::PlaybackStepForward => Some(key(Key::ArrowRight)), + Command::PlaybackRestart => Some(cmd(Key::ArrowLeft)), } } diff --git a/crates/re_viewer/src/app.rs b/crates/re_viewer/src/app.rs index 41ebad070304..092c612305bd 100644 --- a/crates/re_viewer/src/app.rs +++ b/crates/re_viewer/src/app.rs @@ -36,6 +36,7 @@ enum TimeControlCommand { TogglePlayPause, StepBack, StepForward, + Restart, } // ---------------------------------------------------------------------------- @@ -341,6 +342,9 @@ impl App { Command::PlaybackStepForward => { self.run_time_control_command(TimeControlCommand::StepForward); } + Command::PlaybackRestart => { + self.run_time_control_command(TimeControlCommand::Restart); + } } } @@ -362,6 +366,9 @@ impl App { TimeControlCommand::StepForward => { time_ctrl.step_time_fwd(times_per_timeline); } + TimeControlCommand::Restart => { + time_ctrl.restart(times_per_timeline); + } } } diff --git a/crates/re_viewer/src/misc/time_control.rs b/crates/re_viewer/src/misc/time_control.rs index 836f2a7bfd3a..e9839cefec45 100644 --- a/crates/re_viewer/src/misc/time_control.rs +++ b/crates/re_viewer/src/misc/time_control.rs @@ -293,6 +293,14 @@ impl TimeControl { } } + pub fn restart(&mut self, times_per_timeline: &TimesPerTimeline) { + if let Some(time_points) = times_per_timeline.get(&self.timeline) { + if let Some(state) = self.states.get_mut(&self.timeline) { + state.time = min(time_points).into(); + } + } + } + pub fn toggle_play_pause(&mut self, times_per_timeline: &TimesPerTimeline) { #[allow(clippy::collapsible_else_if)] if self.playing {