-
Notifications
You must be signed in to change notification settings - Fork 413
/
Copy pathlib.rs
1351 lines (1175 loc) · 46.7 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Rerun Time Panel
//!
//! This crate provides a panel that shows allows to control time & timelines,
//! as well as all necessary ui elements that make it up.
mod data_density_graph;
mod paint_ticks;
mod time_axis;
mod time_control_ui;
mod time_ranges_ui;
mod time_selection_ui;
use egui::emath::Rangef;
use egui::{pos2, Color32, CursorIcon, NumExt, Painter, PointerButton, Rect, Shape, Ui, Vec2};
use re_entity_db::{EntityTree, InstancePath, TimeHistogram};
use re_log_types::{
external::re_types_core::ComponentName, ComponentPath, EntityPath, EntityPathPart, TimeInt,
TimeRange, TimeReal,
};
use re_ui::list_item::{ListItem, WidthAllocationMode};
use re_viewer_context::{
HoverHighlight, Item, RecordingConfig, TimeControl, TimeView, ViewerContext,
};
use time_axis::TimelineAxis;
use time_control_ui::TimeControlUi;
use time_ranges_ui::TimeRangesUi;
#[derive(Clone)]
struct TimePanelItem {
pub entity_path: EntityPath,
pub component_name: Option<ComponentName>,
}
impl TimePanelItem {
pub fn entity_path(entity_path: EntityPath) -> Self {
Self {
entity_path,
component_name: None,
}
}
pub fn component_path(component_path: ComponentPath) -> Self {
let ComponentPath {
entity_path,
component_name,
} = component_path;
Self {
entity_path,
component_name: Some(component_name),
}
}
pub fn to_item(&self) -> Item {
let Self {
entity_path,
component_name,
} = self;
if let Some(component_name) = component_name {
Item::ComponentPath(ComponentPath::new(entity_path.clone(), *component_name))
} else {
Item::InstancePath(None, InstancePath::entity_splat(entity_path.clone()))
}
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
enum TimePanelSource {
#[default]
Recording,
Blueprint,
}
impl From<TimePanelSource> for egui::Id {
fn from(source: TimePanelSource) -> Self {
match source {
TimePanelSource::Recording => "recording".into(),
TimePanelSource::Blueprint => "blueprint".into(),
}
}
}
/// A panel that shows entity names to the left, time on the top.
///
/// This includes the timeline controls and streams view.
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)]
pub struct TimePanel {
data_density_graph_painter: data_density_graph::DataDensityGraphPainter,
/// Width of the entity name columns previous frame.
prev_col_width: f32,
/// The right side of the entity name column; updated during its painting.
#[serde(skip)]
next_col_right: f32,
/// The time axis view, regenerated each frame.
#[serde(skip)]
time_ranges_ui: TimeRangesUi,
/// Ui elements for controlling time.
time_control_ui: TimeControlUi,
/// Which source is the time panel controlling
source: TimePanelSource,
}
impl Default for TimePanel {
fn default() -> Self {
Self {
data_density_graph_painter: Default::default(),
prev_col_width: 400.0,
next_col_right: 0.0,
time_ranges_ui: Default::default(),
time_control_ui: TimeControlUi,
source: TimePanelSource::Recording,
}
}
}
impl TimePanel {
pub fn new_blueprint_panel() -> Self {
TimePanel {
source: TimePanelSource::Blueprint,
..Default::default()
}
}
pub fn show_panel(
&mut self,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
rec_cfg: &RecordingConfig,
ui: &mut egui::Ui,
time_panel_expanded: bool,
) {
// Naturally, many parts of the time panel need the time control.
// Copy it once, read/edit, and then write back at the end if there was a change.
let time_ctrl_before = rec_cfg.time_ctrl.read().clone();
let mut time_ctrl_after = time_ctrl_before.clone();
// this is the size of everything above the central panel (window title bar, top bar on web,
// etc.)
let screen_header_height = ui.cursor().top();
let top_bar_height = 28.0;
let margin = ctx.re_ui.bottom_panel_margin();
let mut panel_frame = ctx.re_ui.bottom_panel_frame();
if time_panel_expanded {
// Since we use scroll bars we want to fill the whole vertical space downwards:
panel_frame.inner_margin.bottom = 0.0;
// Similarly, let the data get close to the right edge:
panel_frame.inner_margin.right = 0.0;
}
let window_height = ui.ctx().screen_rect().height();
let id: egui::Id = self.source.into();
let collapsed = egui::TopBottomPanel::bottom(id.with("time_panel_collapsed"))
.resizable(false)
.show_separator_line(false)
.frame(panel_frame)
.default_height(44.0);
let min_height = 150.0;
let min_top_space = 150.0 + screen_header_height;
let expanded = egui::TopBottomPanel::bottom(id.with("time_panel_expanded"))
.resizable(true)
.show_separator_line(false)
.frame(panel_frame)
.min_height(min_height)
.max_height((window_height - min_top_space).at_least(min_height).round())
.default_height((0.25 * window_height).clamp(min_height, 250.0).round());
egui::TopBottomPanel::show_animated_between_inside(
ui,
time_panel_expanded,
collapsed,
expanded,
|ui: &mut egui::Ui, expansion: f32| {
if expansion < 1.0 {
// Collapsed or animating
ui.horizontal(|ui| {
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
ui.visuals_mut().button_frame = true;
self.collapsed_ui(ctx, entity_db, ui, &mut time_ctrl_after);
});
} else {
// Expanded:
ui.vertical(|ui| {
// Add back the margin we removed from the panel:
let mut top_row_frame = egui::Frame::default();
top_row_frame.inner_margin.right = margin.x;
top_row_frame.inner_margin.bottom = margin.y;
let top_row_rect = top_row_frame
.show(ui, |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().interact_size = Vec2::splat(top_bar_height);
ui.visuals_mut().button_frame = true;
self.top_row_ui(ctx, entity_db, ui, &mut time_ctrl_after);
});
})
.response
.rect;
// Draw separator between top bar and the rest:
ui.painter().hline(
0.0..=top_row_rect.right(),
top_row_rect.bottom(),
ui.visuals().widgets.noninteractive.bg_stroke,
);
ui.spacing_mut().scroll.bar_outer_margin = 4.0; // needed, because we have no panel margin on the right side.
// Add extra margin on the left which was intentionally missing on the controls.
let mut streams_frame = egui::Frame::default();
streams_frame.inner_margin.left = margin.x;
streams_frame.show(ui, |ui| {
self.expanded_ui(ctx, entity_db, ui, &mut time_ctrl_after);
});
});
}
},
);
// Apply time control if there were any changes.
// This means that if anyone else meanwhile changed the time control, these changes are lost now.
// At least though we don't overwrite them if we didn't change anything at all.
// Since changes on the time control via the time panel are rare, this should be fine.
if time_ctrl_before != time_ctrl_after {
*rec_cfg.time_ctrl.write() = time_ctrl_after;
}
}
#[allow(clippy::unused_self)]
fn collapsed_ui(
&mut self,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
ui: &mut egui::Ui,
time_ctrl: &mut TimeControl,
) {
ui.spacing_mut().item_spacing.x = 18.0; // from figma
if ui.max_rect().width() < 600.0 {
// Responsive ui for narrow screens, e.g. mobile. Split the controls into two rows.
ui.vertical(|ui| {
ui.horizontal(|ui| {
let re_ui = &ctx.re_ui;
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, re_ui, times_per_timeline, ui);
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,
entity_db.times_per_timeline(),
ui,
);
collapsed_time_marker_and_time(ui, ctx, entity_db, time_ctrl);
});
});
} else {
// One row:
let re_ui = &ctx.re_ui;
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, re_ui, times_per_timeline, ui);
self.time_control_ui
.timeline_selector_ui(time_ctrl, times_per_timeline, ui);
self.time_control_ui.playback_speed_ui(time_ctrl, ui);
self.time_control_ui.fps_ui(time_ctrl, ui);
collapsed_time_marker_and_time(ui, ctx, entity_db, time_ctrl);
}
}
fn expanded_ui(
&mut self,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
ui: &mut egui::Ui,
time_ctrl: &mut TimeControl,
) {
re_tracing::profile_function!();
self.data_density_graph_painter.begin_frame(ui.ctx());
// |timeline |
// ------------------------------------
// tree |streams |
// | . . . . . . |
// | . . . . |
// ▲
// └ tree_max_y (= time_x_left)
self.next_col_right = ui.min_rect().left(); // next_col_right will expand during the call
let time_x_left =
(ui.min_rect().left() + self.prev_col_width + ui.spacing().item_spacing.x)
.at_most(ui.max_rect().right() - 100.0)
.at_least(80.); // cover the empty recording case
// Where the time will be shown.
let time_bg_x_range = Rangef::new(time_x_left, ui.max_rect().right());
let time_fg_x_range = {
// Painting to the right of the scroll bar (if any) looks bad:
let right = ui.max_rect().right() - ui.spacing_mut().scroll.bar_outer_margin;
debug_assert!(time_x_left < right);
Rangef::new(time_x_left, right)
};
let side_margin = 26.0; // chosen so that the scroll bar looks approximately centered in the default gap
self.time_ranges_ui = initialize_time_ranges_ui(
entity_db,
time_ctrl,
Rangef::new(
time_fg_x_range.min + side_margin,
time_fg_x_range.max - side_margin,
),
time_ctrl.time_view(),
);
let full_y_range = Rangef::new(ui.min_rect().bottom(), ui.max_rect().bottom());
let timeline_rect = {
let top = ui.min_rect().bottom();
let size = egui::vec2(self.prev_col_width, 28.0);
ui.allocate_ui_with_layout(size, egui::Layout::top_down(egui::Align::LEFT), |ui| {
ui.set_min_size(size);
ui.style_mut().wrap = Some(false);
ui.add_space(4.0); // hack to vertically center the text
if self.source == TimePanelSource::Blueprint {
ui.strong("Blueprint Streams");
} else {
ui.strong("Streams");
}
})
.response
.on_hover_text(
"A hierarchical view of the paths used during logging.\n\
\n\
On the right you can see when there was a log event for a stream.",
);
let bottom = ui.min_rect().bottom();
Rect::from_x_y_ranges(time_fg_x_range, top..=bottom)
};
let streams_rect = Rect::from_x_y_ranges(
time_fg_x_range,
timeline_rect.bottom()..=ui.max_rect().bottom(),
);
// includes the timeline and streams areas.
let time_bg_area_rect = Rect::from_x_y_ranges(time_bg_x_range, full_y_range);
let time_fg_area_rect = Rect::from_x_y_ranges(time_fg_x_range, full_y_range);
let time_bg_area_painter = ui.painter().with_clip_rect(time_bg_area_rect);
let time_area_painter = ui.painter().with_clip_rect(time_fg_area_rect);
if let Some(highlighted_range) = time_ctrl.highlighted_range {
paint_range_highlight(
highlighted_range,
&self.time_ranges_ui,
ui.painter(),
time_fg_area_rect,
);
}
ui.painter().hline(
0.0..=ui.max_rect().right(),
timeline_rect.bottom(),
ui.visuals().widgets.noninteractive.bg_stroke,
);
paint_ticks::paint_time_ranges_and_ticks(
&self.time_ranges_ui,
ui,
&time_area_painter,
timeline_rect.top()..=timeline_rect.bottom(),
time_ctrl.time_type(),
ctx.app_options.time_zone,
);
paint_time_ranges_gaps(
&self.time_ranges_ui,
ctx.re_ui,
ui,
&time_bg_area_painter,
full_y_range,
);
time_selection_ui::loop_selection_ui(
entity_db,
time_ctrl,
&self.time_ranges_ui,
ui,
&time_bg_area_painter,
&timeline_rect,
);
let time_area_response = interact_with_streams_rect(
&self.time_ranges_ui,
time_ctrl,
ui,
&time_bg_area_rect,
&streams_rect,
);
// Don't draw on top of the time ticks
let lower_time_area_painter = ui.painter().with_clip_rect(Rect::from_x_y_ranges(
time_fg_x_range,
ui.min_rect().bottom()..=ui.max_rect().bottom(),
));
// All the entity rows and their data density graphs:
self.tree_ui(
ctx,
entity_db,
time_ctrl,
&time_area_response,
&lower_time_area_painter,
time_x_left,
ui,
);
{
// Paint a shadow between the stream names on the left
// and the data on the right:
let shadow_width = 30.0;
// In the design the shadow starts under the time markers.
//let shadow_y_start =
// timeline_rect.bottom() + ui.visuals().widgets.noninteractive.bg_stroke.width;
// This looks great but only if there are still time markers.
// When they move to the right (or have a cut) one expects the shadow to go all the way up.
// But that's quite complicated so let's have the shadow all the way
let shadow_y_start = full_y_range.min;
let shadow_y_end = full_y_range.max;
let rect = egui::Rect::from_x_y_ranges(
time_x_left..=(time_x_left + shadow_width),
shadow_y_start..=shadow_y_end,
);
ctx.re_ui
.draw_shadow_line(ui, rect, egui::Direction::LeftToRight);
}
// Put time-marker on top and last, so that you can always drag it
time_marker_ui(
&self.time_ranges_ui,
time_ctrl,
ctx.re_ui,
ui,
&time_area_painter,
&timeline_rect,
);
self.time_ranges_ui.snap_time_control(time_ctrl);
// remember where to show the time for next frame:
self.prev_col_width = self.next_col_right - ui.min_rect().left();
}
// All the entity rows and their data density graphs:
#[allow(clippy::too_many_arguments)]
fn tree_ui(
&mut self,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
time_ctrl: &mut TimeControl,
time_area_response: &egui::Response,
time_area_painter: &egui::Painter,
tree_max_y: f32,
ui: &mut egui::Ui,
) {
re_tracing::profile_function!();
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
// We turn off `drag_to_scroll` so that the `ScrollArea` don't steal input from
// the earlier `interact_with_time_area`.
// We implement drag-to-scroll manually instead!
.drag_to_scroll(false)
.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0; // no spacing needed for ListItems
if time_area_response.dragged_by(PointerButton::Primary) {
ui.scroll_with_delta(Vec2::Y * time_area_response.drag_delta().y);
}
// Show "/" on top?
let show_root = false;
if show_root {
self.show_tree(
ctx,
time_ctrl,
time_area_response,
time_area_painter,
tree_max_y,
None,
entity_db.tree(),
ui,
"/",
);
} else {
self.show_children(
ctx,
time_ctrl,
time_area_response,
time_area_painter,
tree_max_y,
entity_db.tree(),
ui,
);
}
});
}
#[allow(clippy::too_many_arguments)]
fn show_tree(
&mut self,
ctx: &ViewerContext<'_>,
time_ctrl: &mut TimeControl,
time_area_response: &egui::Response,
time_area_painter: &egui::Painter,
tree_max_y: f32,
last_path_part: Option<&EntityPathPart>,
tree: &EntityTree,
ui: &mut egui::Ui,
show_root_as: &str,
) {
let tree_has_data_in_current_timeline = time_ctrl.tree_has_data_in_current_timeline(tree);
let store = match self.source {
TimePanelSource::Recording => ctx.entity_db.store(),
TimePanelSource::Blueprint => ctx.store_context.blueprint.store(),
};
// The last part of the path component
let text = if let Some(last_path_part) = last_path_part {
let stem = last_path_part.ui_string();
if tree.is_leaf() {
stem
} else {
format!("{stem}/") // show we have children with a /
}
} else {
show_root_as.to_owned()
};
let collapsing_header_id = ui.make_persistent_id(&tree.path);
let default_open = tree.path.len() <= 1 && !tree.is_leaf();
let item = TimePanelItem::entity_path(tree.path.clone());
let is_selected = ctx.selection().contains_item(&item.to_item());
let is_item_hovered = ctx
.selection_state()
.highlight_for_ui_element(&item.to_item())
== HoverHighlight::Hovered;
let clip_rect_save = ui.clip_rect();
let mut clip_rect = clip_rect_save;
clip_rect.max.x = tree_max_y;
ui.set_clip_rect(clip_rect);
let re_ui::list_item::ShowCollapsingResponse {
item_response: response,
body_response,
} = ListItem::new(ctx.re_ui, text)
.width_allocation_mode(WidthAllocationMode::Compact)
.selected(is_selected)
.force_hovered(is_item_hovered)
.show_collapsing(ui, collapsing_header_id, default_open, |_, ui| {
self.show_children(
ctx,
time_ctrl,
time_area_response,
time_area_painter,
tree_max_y,
tree,
ui,
);
});
ui.set_clip_rect(clip_rect_save);
let response = response.on_hover_ui(|ui| {
re_data_ui::item_ui::entity_hover_card_ui(
ui,
ctx,
&time_ctrl.current_query(),
store,
&tree.path,
);
});
ctx.select_hovered_on_click(&response, item.to_item());
let is_closed = body_response.is_none();
let response_rect = response.rect;
self.next_col_right = self.next_col_right.max(response_rect.right());
// From the left of the label, all the way to the right-most of the time panel
let full_width_rect = Rect::from_x_y_ranges(
response_rect.left()..=ui.max_rect().right(),
response_rect.y_range(),
);
let is_visible = ui.is_rect_visible(full_width_rect);
// ----------------------------------------------
// show the data in the time area:
if is_visible && tree_has_data_in_current_timeline {
let row_rect =
Rect::from_x_y_ranges(time_area_response.rect.x_range(), response_rect.y_range());
highlight_timeline_row(ui, ctx, time_area_painter, &item.to_item(), &row_rect);
// show the density graph only if that item is closed
if is_closed {
let empty = re_entity_db::TimeHistogram::default();
let num_messages_at_time = tree
.subtree
.time_histogram
.get(time_ctrl.timeline())
.unwrap_or(&empty);
data_density_graph::data_density_graph_ui(
&mut self.data_density_graph_painter,
ctx,
time_ctrl,
store,
time_area_response,
time_area_painter,
ui,
tree.num_timeless_messages_recursive() as usize,
num_messages_at_time,
row_rect,
&self.time_ranges_ui,
&item,
);
}
}
}
#[allow(clippy::too_many_arguments)]
fn show_children(
&mut self,
ctx: &ViewerContext<'_>,
time_ctrl: &mut TimeControl,
time_area_response: &egui::Response,
time_area_painter: &egui::Painter,
tree_max_y: f32,
tree: &EntityTree,
ui: &mut egui::Ui,
) {
for (last_component, child) in &tree.children {
self.show_tree(
ctx,
time_ctrl,
time_area_response,
time_area_painter,
tree_max_y,
Some(last_component),
child,
ui,
"/",
);
}
// If this is an entity:
if !tree.entity.components.is_empty() {
let clip_rect_save = ui.clip_rect();
for component_name in re_data_ui::ui_visible_components(tree.entity.components.keys()) {
let data = &tree.entity.components[&component_name];
let component_has_data_in_current_timeline =
time_ctrl.component_has_data_in_current_timeline(data);
let component_path = ComponentPath::new(tree.path.clone(), component_name);
let short_component_name = component_path.component_name.short_name();
let item = TimePanelItem::component_path(component_path);
let mut clip_rect = clip_rect_save;
clip_rect.max.x = tree_max_y;
ui.set_clip_rect(clip_rect);
let response = ListItem::new(ctx.re_ui, short_component_name)
.selected(ctx.selection().contains_item(&item.to_item()))
.width_allocation_mode(WidthAllocationMode::Compact)
.force_hovered(
ctx.selection_state()
.highlight_for_ui_element(&item.to_item())
== HoverHighlight::Hovered,
)
.with_icon_fn(|_, ui, rect, visual| {
ui.painter()
.circle_filled(rect.center(), 2.0, visual.text_color());
})
.show(ui);
ui.set_clip_rect(clip_rect_save);
ctx.select_hovered_on_click(&response, item.to_item());
let response_rect = response.rect;
let timeline = time_ctrl.timeline();
let empty_messages_over_time = TimeHistogram::default();
let messages_over_time = data.get(timeline).unwrap_or(&empty_messages_over_time);
// `data.times` does not contain timeless. Need to add those manually:
let total_num_messages =
messages_over_time.total_count() + data.num_timeless_messages();
response.on_hover_ui(|ui| {
if total_num_messages == 0 {
ui.label(ctx.re_ui.warning_text(format!(
"No event logged on timeline {:?}",
timeline.name()
)));
} else {
ui.label(format!("Number of events: {total_num_messages}"));
}
});
self.next_col_right = self.next_col_right.max(response_rect.right());
// From the left of the label, all the way to the right-most of the time panel
let full_width_rect = Rect::from_x_y_ranges(
response_rect.left()..=ui.max_rect().right(),
response_rect.y_range(),
);
let is_visible = ui.is_rect_visible(full_width_rect);
if is_visible && component_has_data_in_current_timeline {
// show the data in the time area:
let row_rect = Rect::from_x_y_ranges(
time_area_response.rect.x_range(),
response_rect.y_range(),
);
highlight_timeline_row(ui, ctx, time_area_painter, &item.to_item(), &row_rect);
let store = match self.source {
TimePanelSource::Recording => ctx.entity_db.store(),
TimePanelSource::Blueprint => ctx.store_context.blueprint.store(),
};
data_density_graph::data_density_graph_ui(
&mut self.data_density_graph_painter,
ctx,
time_ctrl,
store,
time_area_response,
time_area_painter,
ui,
data.num_timeless_messages() as usize,
messages_over_time,
row_rect,
&self.time_ranges_ui,
&item,
);
}
}
}
}
fn top_row_ui(
&mut self,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
ui: &mut egui::Ui,
time_ctrl: &mut TimeControl,
) {
ui.spacing_mut().item_spacing.x = 18.0; // from figma
if ui.max_rect().width() < 600.0 {
// Responsive ui for narrow screens, e.g. mobile. Split the controls into two rows.
ui.vertical(|ui| {
ui.horizontal(|ui| {
let re_ui = &ctx.re_ui;
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, re_ui, times_per_timeline, ui);
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,
entity_db.times_per_timeline(),
ui,
);
current_time_ui(ctx, entity_db, ui, time_ctrl);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
help_button(ui);
});
});
});
} else {
// One row:
let re_ui = &ctx.re_ui;
let times_per_timeline = entity_db.times_per_timeline();
self.time_control_ui
.play_pause_ui(time_ctrl, re_ui, times_per_timeline, ui);
self.time_control_ui
.timeline_selector_ui(time_ctrl, times_per_timeline, ui);
self.time_control_ui.playback_speed_ui(time_ctrl, ui);
self.time_control_ui.fps_ui(time_ctrl, ui);
current_time_ui(ctx, entity_db, ui, time_ctrl);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
help_button(ui);
if self.source == TimePanelSource::Blueprint
&& ctx.app_options.inspect_blueprint_timeline
{
// TODO(jleibs): Once we can edit blueprint while in follow mode, show
// this conditionally.
ui.label(ctx.re_ui.warning_text("Blueprint Editing is Disabled"));
}
});
}
}
}
/// Draw the hovered/selected highlight background for a timeline row.
fn highlight_timeline_row(
ui: &Ui,
ctx: &ViewerContext<'_>,
painter: &Painter,
item: &Item,
row_rect: &Rect,
) {
let item_hovered =
ctx.selection_state().highlight_for_ui_element(item) == HoverHighlight::Hovered;
let item_selected = ctx.selection().contains_item(item);
let bg_color = if item_selected {
Some(ui.visuals().selection.bg_fill.gamma_multiply(0.4))
} else if item_hovered {
Some(
ui.visuals()
.widgets
.hovered
.weak_bg_fill
.gamma_multiply(0.3),
)
} else {
None
};
if let Some(bg_color) = bg_color {
painter.rect_filled(*row_rect, egui::Rounding::ZERO, bg_color);
}
}
fn collapsed_time_marker_and_time(
ui: &mut egui::Ui,
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
time_ctrl: &mut TimeControl,
) {
let space_needed_for_current_time = match time_ctrl.timeline().typ() {
re_data_store::TimeType::Time => 220.0,
re_data_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;
if time_range_rect.width() > 50.0 {
let time_ranges_ui =
initialize_time_ranges_ui(entity_db, time_ctrl, time_range_rect.x_range(), None);
time_ranges_ui.snap_time_control(time_ctrl);
let painter = ui.painter_at(time_range_rect.expand(4.0));
if let Some(highlighted_range) = time_ctrl.highlighted_range {
paint_range_highlight(
highlighted_range,
&time_ranges_ui,
&painter,
time_range_rect,
);
}
painter.hline(
time_range_rect.x_range(),
time_range_rect.center().y,
ui.visuals().widgets.inactive.fg_stroke,
);
time_marker_ui(
&time_ranges_ui,
time_ctrl,
ctx.re_ui,
ui,
&painter,
&time_range_rect,
);
ui.allocate_rect(time_range_rect, egui::Sense::hover());
}
}
current_time_ui(ctx, entity_db, ui, time_ctrl);
}
fn paint_range_highlight(
highlighted_range: TimeRange,
time_ranges_ui: &TimeRangesUi,
painter: &egui::Painter,
rect: Rect,
) {
let x_from = time_ranges_ui.x_from_time_f32(highlighted_range.min.into());
let x_to = time_ranges_ui.x_from_time_f32(highlighted_range.max.into());
if let (Some(x_from), Some(x_to)) = (x_from, x_to) {
let visible_history_area_rect =
Rect::from_x_y_ranges(x_from..=x_to, rect.y_range()).intersect(rect);
painter.rect(
visible_history_area_rect,
0.0,
egui::Color32::WHITE.gamma_multiply(0.1),
egui::Stroke::NONE,
);
}
}
fn help_button(ui: &mut egui::Ui) {
// TODO(andreas): Nicer help text like on space views.
re_ui::help_hover_button(ui).on_hover_text(
"\
In the top row you can drag to move the time, or shift-drag to select a loop region.\n\
\n\
Drag main area to pan.\n\
Zoom: Ctrl/cmd + scroll, or drag up/down with secondary mouse button.\n\
Double-click to reset view.\n\
\n\
Press the space bar to play/pause.",
);
}
/// A user can drag the time slider to between the timeless data and the first real data.
///
/// The time interpolated there is really weird, as it goes from [`TimeInt::BEGINNING`]
/// (which is extremely long time ago) to whatever tim the user logged.
/// So we do not want to display these times to the user.
///
/// This functions returns `true` iff the given time is safe to show.
fn is_time_safe_to_show(
entity_db: &re_entity_db::EntityDb,
timeline: &re_data_store::Timeline,
time: TimeReal,
) -> bool {
if entity_db.num_timeless_messages() == 0 {
return true; // no timeless messages, no problem
}
if let Some(times) = entity_db.tree().subtree.time_histogram.get(timeline) {
if let Some(first_time) = times.min_key() {
let margin = match timeline.typ() {
re_data_store::TimeType::Time => TimeInt::from_seconds(10_000),
re_data_store::TimeType::Sequence => TimeInt::from_sequence(1_000),
};
return TimeInt::from(first_time) <= time + margin;
}
}
TimeInt::BEGINNING < time
}
fn current_time_ui(
ctx: &ViewerContext<'_>,
entity_db: &re_entity_db::EntityDb,
ui: &mut egui::Ui,
time_ctrl: &TimeControl,
) {
if let Some(time_int) = time_ctrl.time_int() {
let timeline = time_ctrl.timeline();
if is_time_safe_to_show(entity_db, timeline, time_int.into()) {
let time_type = time_ctrl.time_type();
ui.monospace(time_type.format(time_int, ctx.app_options.time_zone));
}
}
}
// ----------------------------------------------------------------------------