forge
Explore
Log in

Don't you dare go Hollow

Every setting has a button, not only a key

Browse files at this commit

b362ed528d4ffd3dbae95791275292f4531dd165Ahmet Kaan GümüşParent: 6686ecd
  • feat
    • every setting has a button, not only a key
Show full message
✨ feat(ui): every setting has a button, not only a key

The audit the ask names, and what it found missing. The project resolution
was ctrl+r and nothing else, undo was a stroke, an export could only be
cancelled with escape, copy and paste had no door at all, the silence card
was seven settings a pointer could pick but never move, and the scan itself
was a key with no menu item.

Each of them now has the pointer path its stroke always had -- the
resolution cycles on a button that says where it is, the export button
becomes the cancel while one runs, the clip menu carries the clipboard pair
and the silence card, and every silence row has its own two steppers, on
the same nudge the arrows call.

The clip menu's list scrolls past twelve items so a longer menu cannot hang
its last item off the window, and the toolbar scrolls sideways for the same
reason: at 640 px it was already wider than the panel, and Keys was off the
edge before any of this was added.

every_action_is_reachable_without_the_keyboard keeps the audit from rotting:
no ActionId may be a stroke and nothing else.
crates/app/src/main.rsmodified+234 -18
@@ -120,6 +120,11 @@ const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H;
120 const MENU_W: f32 = 260.;120 const MENU_W: f32 = 260.;
121 const MENU_ROW_H: f32 = HIT_MIN;121 const MENU_ROW_H: f32 = HIT_MIN;
122 const MENU_PAD: f32 = 6.;122 const MENU_PAD: f32 = 6.;
123+/// How much of the item list is on screen at once, capped and scrolling like the
124+/// keybindings and export lists: every action the pointer can reach is an item
125+/// here, and a menu taller than the 640x360 floor would hang its last items off
126+/// the bottom edge, where nobody can click them.
127+const MENU_ROWS_H: f32 = 12. * MENU_ROW_H;
123 128
124 /// The one key name this file still spells out, and gpui's spelling of it: it129 /// The one key name this file still spells out, and gpui's spelling of it: it
125 /// is the way out of a capture and out of the overlay, and both have to work130 /// is the way out of a capture and out of the overlay, and both have to work
@@ -342,8 +347,13 @@ impl RowItem {
342 /// action a stroke already reaches -- the menu is a second way *to* the actions347 /// action a stroke already reaches -- the menu is a second way *to* the actions
343 /// and never a second version of them -- so both the label and the hint come348 /// and never a second version of them -- so both the label and the hint come
344 /// out of the keymap registry and the two can never disagree.349 /// out of the keymap registry and the two can never disagree.
345-const MENU_ITEMS: [ActionId; 11] = [350+const MENU_ITEMS: [ActionId; 14] = [
346 ActionId::Cut,351 ActionId::Cut,
352+ // The clipboard pair, which had no door but a chord: copy takes the clip the
353+ // menu names, and paste is the timeline's rather than this clip's -- the
354+ // same kind of global item the mute below already is.
355+ ActionId::Copy,
356+ ActionId::Paste,
347 ActionId::Delete,357 ActionId::Delete,
348 ActionId::Lift,358 ActionId::Lift,
349 ActionId::Regroup,359 ActionId::Regroup,
@@ -351,6 +361,10 @@ const MENU_ITEMS: [ActionId; 11] = [
351 ActionId::Group,361 ActionId::Group,
352 ActionId::Equalizer,362 ActionId::Equalizer,
353 ActionId::Speed,363 ActionId::Speed,
364+ // The scan is a clip card like the two above it -- opened on whichever half
365+ // was clicked -- and a card only a stroke could open is one a pointer never
366+ // finds.
367+ ActionId::Silence,
354 ActionId::Color,368 ActionId::Color,
355 ActionId::Fit,369 ActionId::Fit,
356 ActionId::ToggleMute,370 ActionId::ToggleMute,
@@ -3636,6 +3650,10 @@ impl Player {
3636 // Everything but Import and Keys needs a timeline to act on: with none3650 // Everything but Import and Keys needs a timeline to act on: with none
3637 // open they are dimmed rather than silently doing nothing.3651 // open they are dimmed rather than silently doing nothing.
3638 let live = self.session.is_some() && !exporting;3652 let live = self.session.is_some() && !exporting;
3653+ // The project's own picture size, for the button that cycles it: read
3654+ // per render like everything else here, so a cycle shows on the button
3655+ // that made it.
3656+ let resolution = self.session.as_ref().map(PlaybackSession::resolution);
3639 let key = |action| self.keymap.display(action);3657 let key = |action| self.keymap.display(action);
3640 // The lanes the project has, or the pair a fresh one starts with so the3658 // The lanes the project has, or the pair a fresh one starts with so the
3641 // panel reads the same before a file is open as after.3659 // panel reads the same before a file is open as after.
@@ -3685,12 +3703,20 @@ impl Player {
3685 .bg(rgb(CHROME))3703 .bg(rgb(CHROME))
3686 // Transport | edit | file: three groups, so the eye can skip two of3704 // Transport | edit | file: three groups, so the eye can skip two of
3687 // them. Every button says what it does; the tooltip adds its key.3705 // them. Every button says what it does; the tooltip adds its key.
3706+ //
3707+ // The row scrolls rather than losing its tail: at the 640 px floor
3708+ // this window is sized for it is wider than the panel, and a button
3709+ // off the right edge is a button a pointer cannot press. A plain
3710+ // wheel moves it -- gpui puts a vertical delta on the x axis when
3711+ // that is the only one scrolling (div.rs:2424).
3688 .child(3712 .child(
3689 div()3713 div()
3714+ .id("controls")
3690 .flex_none()3715 .flex_none()
3691 .flex()3716 .flex()
3692 .items_center()3717 .items_center()
3693 .gap(px(8.))3718 .gap(px(8.))
3719+ .overflow_x_scroll()
3694 .child(control(3720 .child(control(
3695 "transport",3721 "transport",
3696 Some(transport_glyph(playing).into_any_element()),3722 Some(transport_glyph(playing).into_any_element()),
@@ -3732,6 +3758,17 @@ impl Player {
3732 live && self.selected.is_some(),3758 live && self.selected.is_some(),
3733 cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)),3759 cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)),
3734 ))3760 ))
3761+ // The way back from every one of them. It was a stroke and
3762+ // nothing else, which made the whole edit group a one-way
3763+ // door for anyone working with a pointer.
3764+ .child(control(
3765+ "undo",
3766+ None,
3767+ "Undo",
3768+ format!("{} — takes the last edit back", key(ActionId::Undo)),
3769+ live,
3770+ cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)),
3771+ ))
3735 // With the edit group, beside the buttons that change the3772 // With the edit group, beside the buttons that change the
3736 // edit list: a track is a row of it, and adding one is an3773 // edit list: a track is a row of it, and adding one is an
3737 // undoable edit like the rest. Two buttons rather than one3774 // undoable edit like the rest. Two buttons rather than one
@@ -3790,19 +3827,60 @@ impl Player {
3790 cx,3827 cx,
3791 ))3828 ))
3792 .child(separator())3829 .child(separator())
3830+ // The size every clip is composed onto, which is also the
3831+ // size the export comes out at: the one project setting a
3832+ // stroke used to be the only way to. Cycles exactly as the
3833+ // key does, and says where it is now rather than opening a
3834+ // list to close again.
3835+ .child(control(
3836+ "resolution",
3837+ None,
3838+ resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")),
3839+ match resolution {
3840+ Some((w, h)) => format!(
3841+ "{} — the project is {w}x{h}; cycles source → 2160p → 1080p → 720p → 480p",
3842+ key(ActionId::Resolution)
3843+ ),
3844+ None => format!("{} — open a file first", key(ActionId::Resolution)),
3845+ },
3846+ live,
3847+ cx.listener(|this, _: &ClickEvent, _, cx| this.cycle_resolution(cx)),
3848+ ))
3793 // Import is not here: it belongs to the media list it adds3849 // Import is not here: it belongs to the media list it adds
3794 // to, and two doors into one action is a question about3850 // to, and two doors into one action is a question about
3795 // which one is the real one.3851 // which one is the real one.
3852+ //
3853+ // While one runs, this button is the way out of it: the
3854+ // progress line promised esc and nothing else, which left a
3855+ // pointer no way to stop an export it had started.
3796 .child(control(3856 .child(control(
3797 "export",3857 "export",
3798 None,3858 None,
3799- "Export",3859+ if exporting { "Cancel" } else { "Export" },
3800- format!(3860+ if exporting {
3801- "{} — quality and destination, then writes the timeline out",3861+ format!(
3802- key(ActionId::Export)3862+ "{} — stops the export; the part-written file goes",
3803- ),3863+ key(ActionId::CancelExport)
3804- live && self.export.is_none(),3864+ )
3805- cx.listener(|this, _: &ClickEvent, _, cx| this.open_export(cx)),3865+ } else {
3866+ format!(
3867+ "{} — quality and destination, then writes the timeline out",
3868+ key(ActionId::Export)
3869+ )
3870+ },
3871+ if exporting {
3872+ true
3873+ } else {
3874+ live && self.export.is_none()
3875+ },
3876+ cx.listener(|this, _: &ClickEvent, _, cx| {
3877+ if this.exporting().is_some() {
3878+ this.cancel_export();
3879+ cx.notify();
3880+ } else {
3881+ this.open_export(cx);
3882+ }
3883+ }),
3806 ))3884 ))
3807 .child(control(3885 .child(control(
3808 "save",3886 "save",
@@ -4952,7 +5030,45 @@ impl Player {
4952 cx.notify();5030 cx.notify();
4953 }))5031 }))
4954 .child(div().text_color(rgb(INK_DIM)).child(label))5032 .child(div().text_color(rgb(INK_DIM)).child(label))
4955- .child(value)5033+ // The value and the two steps that move it. Every other
5034+ // card has something to drag or press; this one had the
5035+ // arrow keys and nothing else, so a row was a setting a
5036+ // pointer could pick but never change. One press each, the
5037+ // same call the arrows make -- the hold-to-run is the
5038+ // keyboard's own and is not a thing a button has.
5039+ .child(
5040+ div()
5041+ .flex()
5042+ .items_center()
5043+ .gap(px(4.))
5044+ .child(value)
5045+ .children([-1, 1].map(|steps: i32| {
5046+ div()
5047+ .id(("silence-step", n * 2 + usize::from(steps > 0)))
5048+ .flex_none()
5049+ .w(px(HIT_MIN))
5050+ .h(px(KEYS_ROW_H))
5051+ .flex()
5052+ .items_center()
5053+ .justify_center()
5054+ .rounded(px(3.))
5055+ .bg(rgb(CHROME))
5056+ .cursor_pointer()
5057+ .hover(|s| s.bg(rgb(HOVER)))
5058+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
5059+ // Picked as well as moved: the row a
5060+ // press lands on is the row the arrows
5061+ // carry on from.
5062+ this.silence_field = n;
5063+ this.nudge_silence(steps);
5064+ cx.notify();
5065+ }))
5066+ .child(match steps > 0 {
5067+ true => "+",
5068+ false => "−",
5069+ })
5070+ })),
5071+ )
4956 })5072 })
4957 .collect();5073 .collect();
4958 // The two buttons the ask names, side by side: a mode toggle would hide5074 // The two buttons the ask names, side by side: a mode toggle would hide
@@ -5010,7 +5126,7 @@ impl Player {
5010 .text_size(px(11.))5126 .text_size(px(11.))
5011 .text_color(rgb(INK_DIM))5127 .text_color(rgb(INK_DIM))
5012 .child(5128 .child(
5013- "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes",5129+ "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes",
5014 ),5130 ),
5015 )5131 )
5016 .children(rows)5132 .children(rows)
@@ -5291,7 +5407,7 @@ impl Player {
5291 // The one item that is not about this clip says so, and says it5407 // The one item that is not about this clip says so, and says it
5292 // here rather than in the registry: the stroke is global too,5408 // here rather than in the registry: the stroke is global too,
5293 // but its row in the keys menu is not sitting on a clip.5409 // but its row in the keys menu is not sitting on a clip.
5294- let label = if action == ActionId::ToggleMute {5410+ let label = if matches!(action, ActionId::ToggleMute | ActionId::Paste) {
5295 format!("{} (global)", action.label())5411 format!("{} (global)", action.label())
5296 } else {5412 } else {
5297 action.label().to_string()5413 action.label().to_string()
@@ -5338,7 +5454,10 @@ impl Player {
5338 let (x, y) = menu_at(5454 let (x, y) = menu_at(
5339 menu.at,5455 menu.at,
5340 viewport,5456 viewport,
5341- MENU_PAD * 2. + rows.len() as f32 * MENU_ROW_H,5457+ // The cap once the list is longer than it: past that the list
5458+ // scrolls and the card stops growing, exactly as the keybindings and
5459+ // export lists do.
5460+ MENU_PAD * 2. + (rows.len() as f32 * MENU_ROW_H).min(MENU_ROWS_H),
5342 );5461 );
5343 let full: SharedString = source.path.display().to_string().into();5462 let full: SharedString = source.path.display().to_string().into();
5344 Some(5463 Some(
@@ -5393,7 +5512,18 @@ impl Player {
5393 .when(menu.details, |d| {5512 .when(menu.details, |d| {
5394 d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into())5513 d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into())
5395 })5514 })
5396- .children(rows),5515+ // The list scrolls where the card would otherwise grow
5516+ // past the window's floor -- an item hanging off the
5517+ // bottom edge is an item nobody can click.
5518+ .child(
5519+ div()
5520+ .id("menu-rows")
5521+ .flex()
5522+ .flex_col()
5523+ .max_h(px(MENU_ROWS_H))
5524+ .overflow_y_scroll()
5525+ .children(rows),
5526+ ),
5397 ),5527 ),
5398 )5528 )
5399 }5529 }
@@ -7328,10 +7458,10 @@ mod tests {
7328 EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS,7458 EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS,
7329 HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H,7459 HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H,
7330 LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS,7460 LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS,
7331- MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS,7461+ MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H,
7332- SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo,7462+ SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source,
7333- VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add,7463+ Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label,
7334- cancels_export, color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path,7464+ can_add, cancels_export, color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path,
7335 export_settings, format_key, format_line, format_refusal, frac_along, frac_down, frame_at,7465 export_settings, format_key, format_line, format_refusal, frac_along, frac_down, frame_at,
7336 histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at, normalise,7466 histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at, normalise,
7337 nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, show_label,7467 nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, show_label,
@@ -7687,6 +7817,89 @@ mod tests {
7687 assert!(ActionId::ALL.contains(&action), "{action:?} is not listed");7817 assert!(ActionId::ALL.contains(&action), "{action:?} is not listed");
7688 assert_ne!(keymap.display(action), "unbound", "{action:?}");7818 assert_ne!(keymap.display(action), "unbound", "{action:?}");
7689 }7819 }
7820+ // ...and the whole card still fits the 640x360 floor, however many items
7821+ // it grows to: the list is what scrolls past the cap, never the card.
7822+ let items = MENU_ITEMS.len() + 1; // Properties
7823+ assert!(MENU_PAD * 2. + MENU_ROWS_H <= 360., "menu too tall");
7824+ assert!(
7825+ MENU_ROWS_H / MENU_ROW_H >= 12.,
7826+ "too few items visible to scan"
7827+ );
7828+ assert_eq!(
7829+ menu_at(point(px(0.), px(0.)), size(px(640.), px(360.)), {
7830+ MENU_PAD * 2. + (items as f32 * MENU_ROW_H).min(MENU_ROWS_H)
7831+ }),
7832+ (0., 0.)
7833+ );
7834+ }
7835+
7836+ /// The other half of the keys menu's guarantee, and the audit this batch was
7837+ /// asked for kept as a test: no action may be a stroke and nothing else.
7838+ /// Either the clip menu offers it, or a control in the panel does -- named
7839+ /// here by the id [`control`] is handed, read out of this file's own source
7840+ /// like `no_stroke_is_missing_from_the_keys_menu` reads the key handler.
7841+ #[test]
7842+ fn every_action_is_reachable_without_the_keyboard() {
7843+ use keymap::ActionId;
7844+ let source = include_str!("main.rs")
7845+ .split("#[cfg(test)]")
7846+ .next()
7847+ .unwrap();
7848+ let element = |id: &str| source.contains(&format!("\"{id}\""));
7849+ for action in ActionId::ALL {
7850+ let by_pointer = MENU_ITEMS.contains(&action)
7851+ || match action {
7852+ ActionId::Play => element("transport"),
7853+ // One slot, two states: it starts an export and stops the
7854+ // one it started.
7855+ ActionId::Export | ActionId::CancelExport => element("export"),
7856+ ActionId::Save => element("save"),
7857+ ActionId::Undo => element("undo"),
7858+ ActionId::Resolution => element("resolution"),
7859+ ActionId::AddVideoLane => element("add-video-lane"),
7860+ ActionId::AddAudioLane => element("add-audio-lane"),
7861+ // The × in a lane's own header, which takes any track and
7862+ // not only the last one.
7863+ ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => {
7864+ source.contains("this.remove_lane(lane, cx)")
7865+ }
7866+ ActionId::ToggleMute => element("volume"),
7867+ ActionId::VolumeUp | ActionId::VolumeDown => element("volume-bar"),
7868+ // The ruler seeks anywhere the pointer points; the frame and
7869+ // the second are the keyboard's finer grain of that move.
7870+ ActionId::StepBack
7871+ | ActionId::StepForward
7872+ | ActionId::JumpBack
7873+ | ActionId::JumpForward
7874+ | ActionId::GoStart
7875+ | ActionId::GoEnd => element("ruler"),
7876+ // A press on a clip is the selection, group and all.
7877+ ActionId::Select | ActionId::SelectNext | ActionId::SelectPrev => {
7878+ source.contains("this.select((lane, i), cx)")
7879+ }
7880+ _ => false,
7881+ };
7882+ assert!(by_pointer, "{action:?} is reachable by keyboard only");
7883+ }
7884+ // The card-local strokes have the same rule, and each of them is a thing
7885+ // on its card: the graph and its two buttons, the colour bars and their
7886+ // reset, the speed bar and its presets, and the silence card's rows --
7887+ // whose steppers are the pointer's only way to a threshold.
7888+ for id in [
7889+ "eq-graph",
7890+ "eq-reset",
7891+ "eq-spectrum",
7892+ "color-bar",
7893+ "color-reset",
7894+ "speed-bar",
7895+ "speed-preset",
7896+ "silence-row",
7897+ "silence-step",
7898+ "silence-apply",
7899+ "export-confirm",
7900+ ] {
7901+ assert!(element(id), "{id} is not on any card");
7902+ }
7690 }7903 }
7691 7904
7692 /// What the Detach and Group items do to a real timeline: a music video's7905 /// What the Detach and Group items do to a real timeline: a music video's
@@ -8983,8 +9196,11 @@ mod tests {
8983 <= 360.,9196 <= 360.,
8984 "card too tall"9197 "card too tall"
8985 );9198 );
8986- // Its rows and buttons are clicked, so WCAG 2.5.8 binds them.9199+ // Its rows, its steppers and its buttons are clicked, so WCAG 2.5.8
9200+ // binds them: a stepper is `HIT_MIN` square inside a row of that height.
8987 assert!(KEYS_ROW_H >= HIT_MIN);9201 assert!(KEYS_ROW_H >= HIT_MIN);
9202+ // ...and the pair of them fits beside the widest value the card prints.
9203+ assert!(2. * HIT_MIN + 4. < COLOR_W / 2., "steppers crowd the value");
8988 // A "speed-up" is never a slow-down: the rate stops above real time at9204 // A "speed-up" is never a slow-down: the rate stops above real time at
8989 // one end and at what a clip can hold at the other, whatever the keys9205 // one end and at what a clip can hold at the other, whatever the keys
8990 // ask for. A silence played *slower* would make the timeline longer,9206 // ask for. A silence played *slower* would make the timeline longer,