Skip to content

Commit

Permalink
Hide time controls if there is only one time point on a timeline (#7241)
Browse files Browse the repository at this point in the history
This happens all the time for our snippets:

See for instance https://rerun.io/docs/reference/types/archetypes/image
where the time controls look buggy at the moment:


![timecontrols](https://github.com/user-attachments/assets/408451a8-8bb2-42c5-a323-237ace2dcf1c)
  • Loading branch information
emilk authored Aug 23, 2024
1 parent 15b3c3d commit 8466198
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions crates/viewer/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,23 @@ impl TimePanel {
) {
ui.spacing_mut().item_spacing.x = 18.0; // from figma

let has_any_data_on_timeline = entity_db.has_any_data_on_timeline(time_ctrl.timeline());
let time_range = entity_db.time_range_for(time_ctrl.timeline());
let has_more_than_one_time_point =
time_range.map_or(false, |time_range| time_range.min() != time_range.max());

if ui.max_rect().width() < 600.0 && has_any_data_on_timeline {
if ui.max_rect().width() < 600.0 && has_more_than_one_time_point {
// Responsive ui for narrow screens, e.g. mobile. Split the controls into two rows.
ui.vertical(|ui| {
ui.horizontal(|ui| {
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, times_per_timeline, ui);
if has_more_than_one_time_point {
ui.horizontal(|ui| {
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, times_per_timeline, ui);

if has_any_data_on_timeline {
self.time_control_ui.playback_speed_ui(time_ctrl, ui);
self.time_control_ui.fps_ui(time_ctrl, ui);
}
});
});
}
ui.horizontal(|ui| {
self.time_control_ui.timeline_selector_ui(
time_ctrl,
Expand All @@ -302,12 +304,16 @@ impl TimePanel {
} else {
// One row:
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, times_per_timeline, ui);

if has_more_than_one_time_point {
self.time_control_ui
.play_pause_ui(time_ctrl, times_per_timeline, ui);
}

self.time_control_ui
.timeline_selector_ui(time_ctrl, times_per_timeline, ui);

if has_any_data_on_timeline {
if has_more_than_one_time_point {
self.time_control_ui.playback_speed_ui(time_ctrl, ui);
self.time_control_ui.fps_ui(time_ctrl, ui);
}
Expand Down Expand Up @@ -993,16 +999,19 @@ fn collapsed_time_marker_and_time(
) {
let timeline = time_ctrl.timeline();

if !entity_db.has_any_data_on_timeline(timeline) {
let Some(time_range) = entity_db.time_range_for(timeline) else {
// We have no data on this timeline
return;
}

let space_needed_for_current_time = match timeline.typ() {
re_chunk_store::TimeType::Time => 220.0,
re_chunk_store::TimeType::Sequence => 100.0,
};

{
if time_range.min() == time_range.max() {
// Only one time point - showing a slider that can't be moved is just annoying
} else {
let space_needed_for_current_time = match timeline.typ() {
re_chunk_store::TimeType::Time => 220.0,
re_chunk_store::TimeType::Sequence => 100.0,
};

let mut time_range_rect = ui.available_rect_before_wrap();
time_range_rect.max.x -= space_needed_for_current_time;

Expand Down

0 comments on commit 8466198

Please sign in to comment.