@@ -24,10 +24,7 @@ pub fn time_panel_blueprint_entity_path() -> EntityPath {
24
24
25
25
/// Helper trait to write time panel related blueprint components.
26
26
pub trait TimeBlueprintExt {
27
- fn set_timeline_and_time ( & self , timeline : TimelineName , time : impl Into < TimeInt > ) {
28
- self . set_timeline ( timeline) ;
29
- self . set_time ( time) ;
30
- }
27
+ fn set_timeline_and_time ( & self , timeline : TimelineName , time : impl Into < TimeInt > ) ;
31
28
32
29
fn set_time ( & self , time : impl Into < TimeInt > ) ;
33
30
@@ -39,9 +36,20 @@ pub trait TimeBlueprintExt {
39
36
40
37
/// Replaces the current timeline with the automatic one.
41
38
fn clear_timeline ( & self ) ;
39
+
40
+ fn clear_time ( & self ) ;
42
41
}
43
42
44
43
impl < T : BlueprintContext > TimeBlueprintExt for T {
44
+ fn set_timeline_and_time ( & self , timeline : TimelineName , time : impl Into < TimeInt > ) {
45
+ self . save_blueprint_component (
46
+ time_panel_blueprint_entity_path ( ) ,
47
+ & TimePanelBlueprint :: descriptor_timeline ( ) ,
48
+ & re_types:: blueprint:: components:: TimelineName :: from ( timeline. as_str ( ) ) ,
49
+ ) ;
50
+ self . set_time ( time) ;
51
+ }
52
+
45
53
fn set_time ( & self , time : impl Into < TimeInt > ) {
46
54
let time: TimeInt = time. into ( ) ;
47
55
self . save_blueprint_component_static (
@@ -69,6 +77,7 @@ impl<T: BlueprintContext> TimeBlueprintExt for T {
69
77
& TimePanelBlueprint :: descriptor_timeline ( ) ,
70
78
& re_types:: blueprint:: components:: TimelineName :: from ( timeline. as_str ( ) ) ,
71
79
) ;
80
+ self . clear_time ( ) ;
72
81
}
73
82
74
83
fn get_timeline ( & self ) -> Option < TimelineName > {
@@ -89,6 +98,13 @@ impl<T: BlueprintContext> TimeBlueprintExt for T {
89
98
TimePanelBlueprint :: descriptor_timeline ( ) ,
90
99
) ;
91
100
}
101
+
102
+ fn clear_time ( & self ) {
103
+ self . clear_static_blueprint_component (
104
+ time_panel_blueprint_entity_path ( ) ,
105
+ TimePanelBlueprint :: descriptor_time ( ) ,
106
+ ) ;
107
+ }
92
108
}
93
109
94
110
/// The time range we are currently zoomed in on.
@@ -318,7 +334,7 @@ impl TimeControl {
318
334
pub fn from_blueprint ( blueprint_ctx : & impl BlueprintContext ) -> Self {
319
335
let mut this = Self :: default ( ) ;
320
336
321
- this. update_from_blueprint ( blueprint_ctx) ;
337
+ this. update_from_blueprint ( blueprint_ctx, None ) ;
322
338
323
339
this
324
340
}
@@ -356,7 +372,11 @@ impl TimeControl {
356
372
self . set_time ( time) ;
357
373
}
358
374
359
- fn update_from_blueprint ( & mut self , blueprint_ctx : & impl BlueprintContext ) {
375
+ fn update_from_blueprint (
376
+ & mut self ,
377
+ blueprint_ctx : & impl BlueprintContext ,
378
+ times_per_timeline : Option < & TimesPerTimeline > ,
379
+ ) {
360
380
if let Some ( timeline) = blueprint_ctx. get_timeline ( ) {
361
381
if matches ! ( self . timeline, ActiveTimeline :: Auto ( _) )
362
382
|| timeline. as_str ( ) != self . timeline ( ) . name ( ) . as_str ( )
@@ -367,10 +387,18 @@ impl TimeControl {
367
387
self . timeline = ActiveTimeline :: Auto ( * self . timeline ( ) ) ;
368
388
}
369
389
370
- if let Some ( time) = blueprint_ctx. get_time ( )
371
- && self . time_int ( ) != Some ( time)
372
- {
373
- self . set_time ( time. into ( ) ) ;
390
+ if let Some ( times_per_timeline) = times_per_timeline {
391
+ self . select_a_valid_timeline ( times_per_timeline) ;
392
+ }
393
+
394
+ if let Some ( time) = blueprint_ctx. get_time ( ) {
395
+ if self . time_int ( ) != Some ( time) {
396
+ self . set_time ( time. into ( ) ) ;
397
+ }
398
+ }
399
+ // If the blueprint time wasn't set, but the current state's time was, we likely just switched timelines, so restore that timeline's time.
400
+ else if let Some ( state) = self . states . get ( self . timeline ( ) . name ( ) ) {
401
+ blueprint_ctx. set_time ( state. current . time . floor ( ) ) ;
374
402
}
375
403
}
376
404
@@ -384,11 +412,11 @@ impl TimeControl {
384
412
blueprint_ctx : Option < & impl BlueprintContext > ,
385
413
) -> TimeControlResponse {
386
414
if let Some ( blueprint_ctx) = blueprint_ctx {
387
- self . update_from_blueprint ( blueprint_ctx) ;
415
+ self . update_from_blueprint ( blueprint_ctx, Some ( times_per_timeline) ) ;
416
+ } else {
417
+ self . select_a_valid_timeline ( times_per_timeline) ;
388
418
}
389
419
390
- self . select_a_valid_timeline ( times_per_timeline) ;
391
-
392
420
let Some ( full_valid_range) = self . full_valid_range ( times_per_timeline) else {
393
421
return TimeControlResponse :: no_repaint ( ) ; // we have no data on this timeline yet, so bail
394
422
} ;
0 commit comments