Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Restart command and keyboard shortcut for moving time to start of timeline #1802

Merged
merged 6 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum Command {
PlaybackTogglePlayPause,
PlaybackStepBack,
PlaybackStepForward,
PlaybackRestart,
}

impl Command {
Expand Down Expand Up @@ -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"),
}
}

Expand Down Expand Up @@ -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)),
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum TimeControlCommand {
TogglePlayPause,
StepBack,
StepForward,
Restart,
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -341,6 +342,9 @@ impl App {
Command::PlaybackStepForward => {
self.run_time_control_command(TimeControlCommand::StepForward);
}
Command::PlaybackRestart => {
self.run_time_control_command(TimeControlCommand::Restart);
}
}
}

Expand All @@ -362,6 +366,9 @@ impl App {
TimeControlCommand::StepForward => {
time_ctrl.step_time_fwd(times_per_timeline);
}
TimeControlCommand::Restart => {
time_ctrl.restart(times_per_timeline);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/re_viewer/src/misc/time_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ impl TimeControl {
}
}

pub fn restart(&mut self, times_per_timeline: &TimesPerTimeline) {
emilk marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down