egui_pop_views/timeline/tokens.rs
1//! What a timeline is drawn with: its own tokens (`timeline.*`), each read by
2//! path and falling back on the system token it aliases, so a theme restyles
3//! the ruler, the playhead, the range, the markers, the tracks and the clips
4//! with data only.
5
6use egui::{Color32, Context};
7use egui_pop_core::theme::Tokens;
8
9/// A timeline's colours and sizes, from the theme installed.
10#[derive(Clone, Debug, PartialEq)]
11pub struct TimelineTokens {
12 /// Behind the lanes (`timeline.background`, else `surface.sunken`).
13 pub background: Color32,
14 /// Behind the ruler (`timeline.ruler.fill`, else `surface.raised`).
15 pub ruler_fill: Color32,
16 /// The line under the ruler (`timeline.ruler.border`, else `border.default`).
17 pub ruler_border: Color32,
18 /// Its ticks (`timeline.ruler.tick`, else `text.muted`).
19 pub ruler_tick: Color32,
20 /// Its labels (`timeline.ruler.text`, else `text.muted`).
21 pub ruler_text: Color32,
22 /// The lines down the lanes at the labelled ticks (`timeline.grid`, else
23 /// `border.default`).
24 pub grid: Color32,
25 /// The selected range's fill (`timeline.range.fill`, else `accent.subtle`).
26 pub range_fill: Color32,
27 /// Its band on the ruler and its edges while it loops
28 /// (`timeline.range.edge`, else `accent.default`).
29 pub range_edge: Color32,
30 /// The same while it does not (`timeline.range.idle`, else `text.muted`).
31 pub range_edge_idle: Color32,
32 /// The playhead (`timeline.playhead`, else `accent.default`).
33 pub playhead: Color32,
34 /// A marker without a colour of its own (`timeline.marker`, else
35 /// `info`, apart from the playhead's accent).
36 pub marker: Color32,
37 /// A marker's label (`timeline.marker.text`, else `text.default`).
38 pub marker_text: Color32,
39 /// Around the marker the keys act on (`timeline.marker.selected`, else
40 /// `focus.ring`).
41 pub marker_selected: Color32,
42 /// The line between two tracks (`timeline.track.border`, else
43 /// `border.default`).
44 pub track_border: Color32,
45 /// A track's name (`timeline.track.text`, else `text.muted`).
46 pub track_text: Color32,
47 /// A clip without a colour of its own (`timeline.clip.fill`, else
48 /// `surface.raised`).
49 pub clip_fill: Color32,
50 /// A clip's outline (`timeline.clip.border`, else `border.strong`).
51 pub clip_border: Color32,
52 /// A clip's label (`timeline.clip.text`, else `text.default`).
53 pub clip_text: Color32,
54 /// A selected clip's outline and a trimming handle
55 /// (`timeline.clip.selected`, else `accent.default`).
56 pub clip_selected: Color32,
57 /// The outline while the timeline has the keyboard focus (`focus.ring`).
58 pub focus: Color32,
59 /// The speed badge's fill and text (`surface.raised`, `text.strong`).
60 pub badge_fill: Color32,
61 pub badge_text: Color32,
62 /// The ruler's height (`size.control.height`).
63 pub ruler_height: f32,
64 /// The markers' lane (`size.control.height`, four fifths of it).
65 pub lane_height: f32,
66 /// A track's height unless it or the timeline says
67 /// (`size.control.height`, twice).
68 pub track_height: f32,
69 /// The labels' size (`font.scale.xs`).
70 pub font_size: f32,
71 /// Corners (`radius.widget`).
72 pub radius: f32,
73}
74
75impl TimelineTokens {
76 /// The tokens of the theme installed in `ctx`.
77 pub fn of(ctx: &Context) -> TimelineTokens {
78 let t = Tokens::of(ctx);
79 let c = |path: &str, fallback: Color32| t.color(path).unwrap_or(fallback);
80 TimelineTokens {
81 background: c("timeline.background", t.surface.sunken),
82 ruler_fill: c("timeline.ruler.fill", t.surface.raised),
83 ruler_border: c("timeline.ruler.border", t.border.default),
84 ruler_tick: c("timeline.ruler.tick", t.text.muted),
85 ruler_text: c("timeline.ruler.text", t.text.muted),
86 grid: c("timeline.grid", t.border.default),
87 range_fill: c("timeline.range.fill", t.accent.subtle),
88 range_edge: c("timeline.range.edge", t.accent.default),
89 range_edge_idle: c("timeline.range.idle", t.text.muted),
90 playhead: c("timeline.playhead", t.accent.default),
91 marker: c("timeline.marker", t.status.info),
92 marker_text: c("timeline.marker.text", t.text.default),
93 marker_selected: c("timeline.marker.selected", t.focus_ring),
94 track_border: c("timeline.track.border", t.border.default),
95 track_text: c("timeline.track.text", t.text.muted),
96 clip_fill: c("timeline.clip.fill", t.surface.raised),
97 clip_border: c("timeline.clip.border", t.border.strong),
98 clip_text: c("timeline.clip.text", t.text.default),
99 clip_selected: c("timeline.clip.selected", t.accent.default),
100 focus: t.focus_ring,
101 badge_fill: t.surface.raised,
102 badge_text: t.text.strong,
103 ruler_height: t.size.control_height,
104 lane_height: (t.size.control_height * 0.8).round(),
105 track_height: t.size.control_height * 2.0,
106 font_size: t.font.scale.xs,
107 radius: t.radius.widget,
108 }
109 }
110}