From c3a13db54cb3c6be89eff279487a95d9561d012f Mon Sep 17 00:00:00 2001 From: h3mosphere <129932586+h3mosphere@users.noreply.github.com> Date: Sat, 15 Apr 2023 18:57:44 +1000 Subject: [PATCH] Add Restart command and keyboard shortcut for moving time to start of timeline (#1802) * Add Restart button to timeline UI. This sets the timeline back to zero. * Adds Restart Command & Timeline Command * Adds Ctrl-Shift-Space keyboard modifier * Remove restart button from timeline UI. * Use cmd(Key::LeftArrow) as key combo for restart timeline. * Add TimeControl::restart to restart the current timeline. * Use this from the kb_shortcut function * fix some code nits --------- Co-authored-by: Emil Ernerfeldt --- crates/re_ui/src/command.rs | 3 +++ crates/re_viewer/src/app.rs | 7 +++++++ crates/re_viewer/src/misc/time_control.rs | 8 ++++++++ 3 files changed, 18 insertions(+) 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 {