forge
Explore
Log in

Don't you dare go Hollow

Library tabs, accent primary action, redesign guards

Browse files at this commit

2171351fde6a8f912d76a8eccc4c1d0284637508Ahmet Kaan GümüşParent: 2ae5c26
  • feat
    • library tabs, accent primary action, redesign guards
Show full message
✨ feat(ui): library tabs, accent primary action, redesign guards

Media/Audio/Text tabs over the media pool (the giants' split), the Export
button as the one accented control in the window, and three guards: no colour
outside the theme, no settings card drawn from the root, and a reserved rect
for every button whose label changes with its state.
crates/app/src/main.rsmodified+137 -4
@@ -306,6 +306,48 @@ impl Default for Volume {
306306 }
307307 }
308308
309+/// The library's three categories, in the order the giants list them: the
310+/// pictures, the sound, and the words. A file is in exactly one of them, so a
311+/// tab is a question with an answer rather than a filter with a guess.
312+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
313+enum LibraryTab {
314+ Media,
315+ Audio,
316+ Text,
317+}
318+
319+const LIBRARY_TABS: [LibraryTab; 3] = [LibraryTab::Media, LibraryTab::Audio, LibraryTab::Text];
320+
321+impl LibraryTab {
322+ fn label(self) -> &'static str {
323+ match self {
324+ LibraryTab::Media => "Media",
325+ LibraryTab::Audio => "Audio",
326+ LibraryTab::Text => "Text",
327+ }
328+ }
329+
330+ /// Whether a source belongs on this tab. Subtitles are not sources at all
331+ /// -- they are the [`Player::subtitle_section`] under the list -- so the
332+ /// Text tab holds no rows of its own and says so.
333+ fn holds(self, path: &Path) -> bool {
334+ match self {
335+ LibraryTab::Media => !engine::is_audio(path),
336+ LibraryTab::Audio => engine::is_audio(path),
337+ LibraryTab::Text => false,
338+ }
339+ }
340+
341+ /// What an empty tab says instead of being a blank column.
342+ fn empty(self) -> &'static str {
343+ match self {
344+ LibraryTab::Media => "No video or stills yet — Import, or drop a file on the window",
345+ LibraryTab::Audio => "No sound yet — Import, or drop a file on the window",
346+ LibraryTab::Text => "No subtitles yet — drop an .srt on the window, or + S in the toolbar",
347+ }
348+ }
349+}
350+
309351 /// What is known about a source's audio. Three states and not two, because a
310352 /// file whose peaks have not come back yet must not be drawn as one that has no
311353 /// audio at all: the first shows a bed, the second shows nothing.
@@ -1121,6 +1163,10 @@ struct Player {
11211163 /// rebuilt. Its own selection and not the timeline's: Delete keeps acting
11221164 /// on the clip that was clicked in a lane, whatever the library is showing.
11231165 selected_asset: Option<(PathBuf, usize)>,
1166+ /// Which category of the library is being looked at. A tab and not a
1167+ /// filter box: the categories are what the media *is*, and every editor
1168+ /// this one is measured against splits its pool the same way.
1169+ library_tab: LibraryTab,
11241170 /// What is known about each source's audio, taken once and kept. Keyed on
11251171 /// the path *and stream* -- two streams of one file are two envelopes -- and
11261172 /// the key is inserted the moment the decode is *started*: presence means
@@ -8233,13 +8279,20 @@ fn panel_h(lanes: usize) -> f32 {
82338279 PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2)
82348280 }
82358281
8236-/// ...and how tall the timeline region alone is: the panel without the button
8237-/// row that used to sit inside it, which is now its own region above
8238-/// ([`Player::toolbar`], [`TOOLBAR_H`]).
8282+/// How tall the timeline region is: its own padding, the timecode line, the
8283+/// ruler and the gaps between them, plus a row per lane. Measured from its
8284+/// parts rather than taken off [`PANEL_H`] -- the button row moved out of it
8285+/// ([`Player::toolbar`]), and a height still carrying that row's pixels is a
8286+/// height that cuts the last lane off the bottom of the window.
82398287 fn timeline_h(lanes: usize) -> f32 {
8240- panel_h(lanes) - TOOLBAR_H
8288+ TIMELINE_FIXED_H + lanes_h(lanes.clamp(2, LANES_MAX))
82418289 }
82428290
8291+/// 8+8 padding, the timecode line, the 24 px ruler strip and the two 8 px gaps
8292+/// between the three rows, with a couple of px of slack so a taller text line
8293+/// cannot push a lane off the bottom.
8294+const TIMELINE_FIXED_H: f32 = 16. + 18. + 8. + RULER_HIT_H + 8. + 4.;
8295+
82438296 /// The edit toolbar directly above the timeline: one control's height in its
82448297 /// own padding, fixed so nothing in it can push the timeline down.
82458298 const TOOLBAR_H: f32 = CONTROL_H + 16.;
@@ -14174,6 +14227,85 @@ mod tests {
1417414227 );
1417514228 }
1417614229
14230+ /// The whole reason `ui/theme.rs` exists: a colour written anywhere else is
14231+ /// a colour the next palette sweep will miss, which is exactly how 186 grey
14232+ /// calls survived every previous attempt at this.
14233+ #[test]
14234+ fn no_colour_is_written_outside_the_theme() {
14235+ let source = ui_source();
14236+ let stray: Vec<&str> = source
14237+ .lines()
14238+ .filter(|l| l.contains("rgb(0x") || l.contains("rgba(0x"))
14239+ .collect();
14240+ assert!(stray.is_empty(), "colour written outside the theme: {stray:?}");
14241+ }
14242+
14243+ /// The cards are sections of the inspector, not sheets over the timeline:
14244+ /// adjusting a clip must never hide the clip. Structural, because that is
14245+ /// where the rule lives -- a card rendered from the root again would be an
14246+ /// overlay again, whatever it looked like on the day it was written.
14247+ #[test]
14248+ fn an_inspector_section_occludes_no_timeline() {
14249+ let inspector = include_str!("ui/inspector.rs");
14250+ let root = include_str!("main.rs").split("#[cfg(test)]").next().unwrap();
14251+ let render = &root[root.find("impl Render for Player").expect("the root render")..];
14252+ for card in [
14253+ "eq_card", "color_card", "speed_card", "silence_card", "mix_card",
14254+ ] {
14255+ assert!(
14256+ inspector.contains(&format!("self.{card}(")),
14257+ "{card} is not a section of the inspector"
14258+ );
14259+ assert!(
14260+ !render.contains(&format!("self.{card}(")),
14261+ "{card} is drawn from the root again -- it is an overlay over the timeline"
14262+ );
14263+ }
14264+ // The docked cards are placed against the inspector's own box, which is
14265+ // what turns `scrim()` (`absolute().inset_0()`) from a window-wide sheet
14266+ // into this column.
14267+ assert!(
14268+ inspector.contains(".relative()"),
14269+ "the inspector is not a positioning context: its cards would cover the window"
14270+ );
14271+ }
14272+
14273+ /// MUST 1, on the two named offenders: the button that relabels itself
14274+ /// mid-export and the one that used to read "Muted 80%". Both live in a
14275+ /// rect that is reserved once, so the words change and the box does not.
14276+ #[test]
14277+ fn a_stateful_button_keeps_its_rect() {
14278+ use crate::ui::toolbar::{EXPORT_SLOT_W, SNAP_SLOT_W, VOLUME_SLOT_W};
14279+ // Widest word each slot can hold, at the 12 px text this window is set
14280+ // in -- ~7 px a character plus the 16 px of padding.
14281+ let fits = |slot: f32, word: &str| slot >= word.chars().count() as f32 * 7. + 16.;
14282+ for word in ["Export", "Cancel"] {
14283+ assert!(fits(EXPORT_SLOT_W, word), "{word} overflows its rect");
14284+ }
14285+ for word in ["Snap on", "Snap off", "No subs", "Subs off"] {
14286+ assert!(fits(SNAP_SLOT_W, word), "{word} overflows its rect");
14287+ }
14288+ for word in ["100%", "× 100%"] {
14289+ assert!(fits(VOLUME_SLOT_W, word), "{word} overflows its rect");
14290+ }
14291+ // And the rect is passed, not hoped for: every stateful control in the
14292+ // three chrome rows names its width.
14293+ let toolbar = include_str!("ui/toolbar.rs");
14294+ for (id, slot) in [
14295+ ("\"export\"", "EXPORT_SLOT_W"),
14296+ ("\"snap\"", "SNAP_SLOT_W"),
14297+ ("\"subs\"", "SNAP_SLOT_W"),
14298+ ("\"volume\"", "VOLUME_SLOT_W"),
14299+ ("\"zoom-fit\"", "ZOOM_SLOT_W"),
14300+ ] {
14301+ let at = toolbar.find(id).unwrap_or_else(|| panic!("no {id} button"));
14302+ assert!(
14303+ toolbar[at..at + 120].contains(slot),
14304+ "{id} does not reserve {slot}"
14305+ );
14306+ }
14307+ }
14308+
1417714309 #[test]
1417814310 fn nothing_clickable_is_smaller_than_the_wcag_minimum() {
1417914311 // Every hit target in the panel, including the scrub strip -- whose bar
@@ -15128,6 +15260,7 @@ fn main() {
1512815260 picker: None,
1512915261 library_menu: None,
1513015262 selected_asset: None,
15263+ library_tab: LibraryTab::Media,
1513115264 waves: HashMap::new(),
1513215265 streams: HashMap::new(),
1513315266 bitrates: HashMap::new(),
crates/app/src/ui/inspector.rsmodified+12 -1
@@ -8,6 +8,7 @@
88 //! (`an_inspector_section_occludes_no_timeline`).
99
1010 use crate::*;
11+use crate::ui::toolbar::{TONE_SLOT_W, ZOOM_SLOT_W};
1112 use crate::ui::widgets::*;
1213
1314 impl Player {
@@ -124,6 +125,7 @@ impl Player {
124125 .child(self.action_control(
125126 "inspect-speed",
126127 0.,
128+ BG_RAISED,
127129 None,
128130 "Speed",
129131 "how fast this clip and its group play",
@@ -133,6 +135,7 @@ impl Player {
133135 .child(self.action_control(
134136 "inspect-color",
135137 0.,
138+ BG_RAISED,
136139 None,
137140 "Colour",
138141 "exposure, contrast, saturation and temperature",
@@ -142,6 +145,7 @@ impl Player {
142145 .child(self.action_control(
143146 "inspect-eq",
144147 0.,
148+ BG_RAISED,
145149 None,
146150 "Equalizer",
147151 "the bands this clip's sound is filtered through",
@@ -151,6 +155,7 @@ impl Player {
151155 .child(self.action_control(
152156 "inspect-silence",
153157 0.,
158+ BG_RAISED,
154159 None,
155160 "Silence",
156161 "finds the quiet stretches and cuts or speeds them",
@@ -160,6 +165,7 @@ impl Player {
160165 .child(self.action_control(
161166 "inspect-fit",
162167 0.,
168+ BG_RAISED,
163169 None,
164170 "Fit",
165171 "how this picture is placed on the project canvas",
@@ -169,6 +175,7 @@ impl Player {
169175 .child(self.action_control(
170176 "inspect-delete",
171177 0.,
178+ BG_RAISED,
172179 None,
173180 "Delete",
174181 "takes this clip off the timeline",
@@ -206,6 +213,7 @@ impl Player {
206213 .child(self.action_control(
207214 "resolution",
208215 ZOOM_SLOT_W,
216+ BG_RAISED,
209217 None,
210218 resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")),
211219 "the canvas every clip is composed onto, and the size the export comes out at",
@@ -217,6 +225,7 @@ impl Player {
217225 .child(self.action_control(
218226 "fps",
219227 ZOOM_SLOT_W,
228+ BG_RAISED,
220229 None,
221230 match self.session.is_some() {
222231 true => format!("{} fps", fps_label(self.fps)),
@@ -230,7 +239,8 @@ impl Player {
230239 ))
231240 .child(self.action_control(
232241 "tonemap",
233- ZOOM_SLOT_W,
242+ TONE_SLOT_W,
243+ BG_RAISED,
234244 None,
235245 match &self.session {
236246 Some(session) => format!("HDR {}", tone_label(session.tone())),
@@ -245,6 +255,7 @@ impl Player {
245255 .child(self.action_control(
246256 "inspect-mix",
247257 0.,
258+ BG_RAISED,
248259 None,
249260 "Mix",
250261 "a fader per track and the limiter over the sum of them",
crates/app/src/ui/library.rsmodified+44 -6
@@ -40,7 +40,12 @@ impl Player {
4040 },
4141 )
4242 .into_iter()
43+ // The tab is the one filter: `enumerate` stays *before* it, so a row's
44+ // index is still its index in the whole library and the tints, the
45+ // menus and the drags all keep naming the same file whichever tab is
46+ // open.
4347 .enumerate()
48+ .filter(|(_, row)| self.library_tab.holds(&row.path))
4449 .map(|(i, row)| {
4550 let picked = self
4651 .selected_asset
@@ -225,14 +230,44 @@ impl Player {
225230 div()
226231 .flex_1()
227232 .min_w(px(0.))
228- .truncate()
229- .text_size(px(11.))
230- .text_color(rgb(FG_SECONDARY))
231- .child("Media"),
233+ .flex()
234+ .gap(px(2.))
235+ .children(LIBRARY_TABS.map(|tab| {
236+ let on = tab == self.library_tab;
237+ div()
238+ .id(("library-tab", tab as usize))
239+ .flex_none()
240+ .h(px(HIT_MIN))
241+ .px(px(6.))
242+ .flex()
243+ .items_center()
244+ .rounded(px(3.))
245+ .text_size(px(11.))
246+ .text_color(rgb(match on {
247+ true => FG_PRIMARY,
248+ false => FG_SECONDARY,
249+ }))
250+ // One selection language everywhere: the
251+ // same stroke a picked clip and a picked
252+ // row wear.
253+ .when(on, |d| {
254+ d.bg(rgb(BG_SELECTED))
255+ .border_b_2()
256+ .border_color(rgb(STROKE_SELECTED))
257+ })
258+ .cursor_pointer()
259+ .hover(|s| s.bg(rgb(BG_HOVER)))
260+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
261+ this.library_tab = tab;
262+ cx.notify();
263+ }))
264+ .child(tab.label())
265+ })),
232266 )
233267 .child(control(
234268 "import",
235269 0.,
270+ BG_RAISED,
236271 None,
237272 "Import",
238273 "adds a file to this list — or drop one on the window".to_string(),
@@ -256,7 +291,7 @@ impl Player {
256291 div()
257292 .text_size(px(11.))
258293 .text_color(rgb(FG_SECONDARY))
259- .child("No media yet — Import, or drop a file on the window"),
294+ .child(self.library_tab.empty()),
260295 )
261296 })
262297 .children(rows),
@@ -264,10 +299,13 @@ impl Player {
264299 // Under the media it belongs to: a subtitle track is not a source --
265300 // it goes on no lane and is dragged nowhere -- but it is a thing the
266301 // timeline holds, and this is the list of those.
267- .children(self.subtitle_section(width, viewport_h, cx))
302+ .when(self.library_tab == LibraryTab::Text, |d| {
303+ d.children(self.subtitle_section(width, viewport_h, cx))
304+ })
268305 .child(control(
269306 "add-asset",
270307 0.,
308+ BG_RAISED,
271309 None,
272310 "Add at playhead",
273311 match self.selected_asset {
crates/app/src/ui/toolbar.rsmodified+35 -5
@@ -26,6 +26,7 @@ impl Player {
2626 &self,
2727 id: &'static str,
2828 w: f32,
29+ bg: u32,
2930 glyph: Option<AnyElement>,
3031 label: impl Into<SharedString>,
3132 hint: &str,
@@ -41,7 +42,7 @@ impl Player {
4142 Some(why) => format!("{key} — {why}"),
4243 None => format!("{key} — {hint}"),
4344 };
44- control(id, w, glyph, label, say, enabled.yes(), on_click)
45+ control(id, w, bg, glyph, label, say, enabled.yes(), on_click)
4546 }
4647
4748 /// The bar over everything: what is open on the left, the two actions that
@@ -78,6 +79,7 @@ impl Player {
7879 .child(self.action_control(
7980 "save",
8081 0.,
82+ BG_RAISED,
8183 None,
8284 "Save",
8385 "writes the project file",
@@ -93,6 +95,10 @@ impl Player {
9395 .child(self.action_control(
9496 "export",
9597 EXPORT_SLOT_W,
98+ // The one accented button in the window: the primary
99+ // action of an editor, where every consumer editor puts
100+ // it. Cancel keeps the rect and the accent both.
101+ ACCENT_PRIMARY,
96102 None,
97103 if exporting { "Cancel" } else { "Export" },
98104 if exporting {
@@ -114,8 +120,7 @@ impl Player {
114120 }
115121 }),
116122 ))
117- .when(!exporting, |d| d.text_color(rgb(BG_CANVAS)))
118- .when(exporting, |d| d.text_color(rgb(FG_PRIMARY))),
123+ ,
119124 )
120125 }
121126
@@ -142,6 +147,7 @@ impl Player {
142147 .child(self.action_control(
143148 "transport",
144149 40.,
150+ BG_RAISED,
145151 Some(transport_glyph(state).into_any_element()),
146152 "",
147153 "plays and pauses the timeline",
@@ -175,10 +181,15 @@ impl Player {
175181 .child(self.action_control(
176182 "volume",
177183 VOLUME_SLOT_W,
184+ BG_RAISED,
178185 None,
186+ // The level is the label either way and it lives in a fixed
187+ // rect: muting adds a mark and changes the colour, where it
188+ // used to relabel the button "Muted 80%" and shove the slider
189+ // beside it along the row.
179190 match muted {
180- true => format!("🔇 {}%", self.volume.percent()),
181- false => format!("🔊 {}%", self.volume.percent()),
191+ true => format!("× {}%", self.volume.percent()),
192+ false => format!("{}%", self.volume.percent()),
182193 },
183194 "mutes and unmutes; the level is what it comes back to",
184195 ActionId::ToggleMute,
@@ -186,6 +197,10 @@ impl Player {
186197 this.set_volume(|volume| volume.muted = !volume.muted, cx)
187198 }),
188199 ))
200+ .text_color(rgb(match muted {
201+ true => STATUS_WARNING,
202+ false => FG_PRIMARY,
203+ }))
189204 .child(volume_slider(
190205 self.volume,
191206 self.volume_bar.clone(),
@@ -226,6 +241,7 @@ impl Player {
226241 .child(self.action_control(
227242 "cut",
228243 0.,
244+ BG_RAISED,
229245 Some(cut_glyph().into_any_element()),
230246 "Split",
231247 "splits the clip under the playhead",
@@ -235,6 +251,7 @@ impl Player {
235251 .child(self.action_control(
236252 "delete",
237253 0.,
254+ BG_RAISED,
238255 Some(delete_glyph().into_any_element()),
239256 "Delete",
240257 "takes the marked clip off the timeline",
@@ -244,6 +261,7 @@ impl Player {
244261 .child(self.action_control(
245262 "undo",
246263 0.,
264+ BG_RAISED,
247265 None,
248266 "Undo",
249267 "takes the last edit back",
@@ -254,6 +272,7 @@ impl Player {
254272 .child(self.action_control(
255273 "add-video-lane",
256274 0.,
275+ BG_RAISED,
257276 None,
258277 "+ V",
259278 "adds a video track under the ones there",
@@ -265,6 +284,7 @@ impl Player {
265284 .child(self.action_control(
266285 "add-audio-lane",
267286 0.,
287+ BG_RAISED,
268288 None,
269289 "+ A",
270290 "adds an audio track under the ones there",
@@ -276,6 +296,7 @@ impl Player {
276296 .child(self.action_control(
277297 "add-subtitle-track",
278298 0.,
299+ BG_RAISED,
279300 None,
280301 "+ S",
281302 "adds every subtitle track in a file you pick",
@@ -291,6 +312,7 @@ impl Player {
291312 .child(self.action_control(
292313 "snap",
293314 SNAP_SLOT_W,
315+ BG_RAISED,
294316 None,
295317 if self.snap { "Snap on" } else { "Snap off" },
296318 match self.snap {
@@ -303,6 +325,7 @@ impl Player {
303325 .child(self.action_control(
304326 "subs",
305327 SNAP_SLOT_W,
328+ BG_RAISED,
306329 None,
307330 match (self.subtitle_track().is_some(), self.subs_on) {
308331 (false, _) => "No subs",
@@ -317,6 +340,7 @@ impl Player {
317340 .child(self.action_control(
318341 "zoom-out",
319342 CONTROL_H,
343+ BG_RAISED,
320344 None,
321345 "−",
322346 "show more of the timeline; stops with all of it on the bed",
@@ -328,6 +352,7 @@ impl Player {
328352 .child(self.action_control(
329353 "zoom-fit",
330354 ZOOM_SLOT_W,
355+ BG_RAISED,
331356 None,
332357 span_label(self.view().span()),
333358 "fit the whole timeline on the bed",
@@ -337,6 +362,7 @@ impl Player {
337362 .child(self.action_control(
338363 "zoom-in",
339364 CONTROL_H,
365+ BG_RAISED,
340366 None,
341367 "+",
342368 "magnify around the playhead; ctrl+wheel on the ruler zooms at the pointer",
@@ -346,6 +372,7 @@ impl Player {
346372 .child(self.action_control(
347373 "keys",
348374 0.,
375+ BG_RAISED,
349376 None,
350377 "Actions",
351378 "do any action, or change the key that does it",
@@ -365,6 +392,7 @@ impl Player {
365392 .child(control(
366393 "controls-more",
367394 CONTROL_H,
395+ BG_RAISED,
368396 None,
369397 "⋯",
370398 format!(
@@ -390,3 +418,5 @@ pub(crate) const EXPORT_SLOT_W: f32 = 76.;
390418 pub(crate) const SNAP_SLOT_W: f32 = 76.;
391419 pub(crate) const ZOOM_SLOT_W: f32 = 76.;
392420 pub(crate) const VOLUME_SLOT_W: f32 = 76.;
421+/// The HDR rendition's names are the longest words on any button here.
422+pub(crate) const TONE_SLOT_W: f32 = 148.;
crates/app/src/ui/widgets.rsmodified+5 -1
@@ -48,6 +48,9 @@ pub(crate) fn control(
4848 // that relabels itself ("Export"/"Cancel") from shoving its neighbours
4949 // along the row every time its state changes.
5050 w: f32,
51+ // The plane the button stands on. One button in the window is the accent
52+ // (Export, the primary action); everything else is `BG_RAISED`.
53+ bg: u32,
5154 glyph: Option<AnyElement>,
5255 // Not `&'static str`: the volume button's label is its state.
5356 label: impl Into<SharedString>,
@@ -68,7 +71,8 @@ pub(crate) fn control(
6871 .px(px(8.))
6972 .when(w > 0., |d| d.w(px(w)).overflow_hidden())
7073 .rounded(px(4.))
71- .bg(rgb(BG_RAISED))
74+ .bg(rgb(bg))
75+ .when(bg == ACCENT_PRIMARY, |d| d.text_color(rgb(BG_CANVAS)))
7276 .children(glyph)
7377 .child(label)
7478 .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())