Skip to content

Commit 4666ea1

Browse files
authored
Draw loop selection highlight on the collapsed timeline (#11203)
1 parent 7550a74 commit 4666ea1

File tree

2 files changed

+64
-20
lines changed

2 files changed

+64
-20
lines changed

crates/viewer/re_time_panel/src/time_panel.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,14 @@ impl TimePanel {
13571357
);
13581358
}
13591359

1360+
time_selection_ui::collapsed_loop_selection_ui(
1361+
time_ctrl,
1362+
&painter,
1363+
&time_ranges_ui,
1364+
ui,
1365+
time_range_rect,
1366+
);
1367+
13601368
painter.hline(
13611369
time_range_rect.x_range(),
13621370
time_range_rect.center().y,
@@ -1480,19 +1488,13 @@ fn paint_range_highlight(
14801488
painter: &egui::Painter,
14811489
rect: Rect,
14821490
) {
1483-
let x_from = time_ranges_ui.x_from_time_f32(highlighted_range.min().into());
1484-
let x_to = time_ranges_ui.x_from_time_f32(highlighted_range.max().into());
1485-
1486-
if let (Some(x_from), Some(x_to)) = (x_from, x_to) {
1487-
let visible_history_area_rect =
1488-
Rect::from_x_y_ranges(x_from..=x_to, rect.y_range()).intersect(rect);
1489-
1490-
painter.rect_filled(
1491-
visible_history_area_rect,
1492-
0.0,
1493-
painter.ctx().tokens().extreme_fg_color.gamma_multiply(0.1),
1494-
);
1495-
}
1491+
time_selection_ui::paint_timeline_range(
1492+
highlighted_range,
1493+
time_ranges_ui,
1494+
painter,
1495+
rect,
1496+
painter.ctx().tokens().extreme_fg_color.gamma_multiply(0.1),
1497+
);
14961498
}
14971499

14981500
fn help(os: egui::os::OperatingSystem) -> Help {

crates/viewer/re_time_panel/src/time_selection_ui.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
1-
use egui::{CursorIcon, Id, NumExt as _, Rect};
1+
use egui::{Color32, CursorIcon, Id, NumExt as _, Rect};
22

3-
use re_log_types::{AbsoluteTimeRangeF, Duration, TimeInt, TimeReal, TimeType};
3+
use re_log_types::{AbsoluteTimeRange, AbsoluteTimeRangeF, Duration, TimeInt, TimeReal, TimeType};
44
use re_ui::UiExt as _;
55
use re_viewer_context::{Looping, TimeControl};
66

77
use super::time_ranges_ui::TimeRangesUi;
88

9+
/// Paints a rect on the timeline given a time range.
10+
pub fn paint_timeline_range(
11+
highlighted_range: AbsoluteTimeRange,
12+
time_ranges_ui: &TimeRangesUi,
13+
painter: &egui::Painter,
14+
rect: Rect,
15+
color: Color32,
16+
) {
17+
let x_from = time_ranges_ui.x_from_time_f32(highlighted_range.min().into());
18+
let x_to = time_ranges_ui.x_from_time_f32(highlighted_range.max().into());
19+
20+
if let (Some(x_from), Some(x_to)) = (x_from, x_to) {
21+
let visible_history_area_rect =
22+
Rect::from_x_y_ranges(x_from..=x_to, rect.y_range()).intersect(rect);
23+
24+
painter.rect_filled(visible_history_area_rect, 0.0, color);
25+
}
26+
}
27+
28+
fn loop_selection_color(time_ctrl: &TimeControl, tokens: &re_ui::DesignTokens) -> Color32 {
29+
// Display in a brighter color when active
30+
if time_ctrl.looping() == Looping::Selection {
31+
tokens.loop_selection_color
32+
} else {
33+
tokens.loop_selection_color.gamma_multiply(0.7)
34+
}
35+
}
36+
37+
pub fn collapsed_loop_selection_ui(
38+
time_ctrl: &TimeControl,
39+
painter: &egui::Painter,
40+
time_ranges_ui: &TimeRangesUi,
41+
ui: &egui::Ui,
42+
time_range_rect: Rect,
43+
) {
44+
if let Some(loop_range) = time_ctrl.loop_selection() {
45+
paint_timeline_range(
46+
loop_range.to_int(),
47+
time_ranges_ui,
48+
painter,
49+
time_range_rect,
50+
loop_selection_color(time_ctrl, ui.tokens()),
51+
);
52+
}
53+
}
54+
955
pub fn loop_selection_ui(
1056
time_ctrl: &mut TimeControl,
1157
time_ranges_ui: &TimeRangesUi,
@@ -28,11 +74,7 @@ pub fn loop_selection_ui(
2874

2975
let is_active = time_ctrl.looping() == Looping::Selection;
3076

31-
let selection_color = if is_active {
32-
tokens.loop_selection_color
33-
} else {
34-
tokens.loop_selection_color.gamma_multiply(0.7)
35-
};
77+
let selection_color = loop_selection_color(time_ctrl, tokens);
3678

3779
let pointer_pos = ui.input(|i| i.pointer.hover_pos());
3880
let is_pointer_in_timeline =

0 commit comments

Comments
 (0)