forge
Explore
Log in

Don't you dare go Hollow

Every action is a row the pointer can reach, and one table says whether it can

Browse files at this commit

0c264ba85c286cd791b872f125bd4634db5fa4c7Ahmet Kaan GümüşParent: 88fbed0
  • feat
    • every action is a row the pointer can reach, and one table says whether it can
Show full message
✨ feat(actions): every action is a row the pointer can reach, and one table says whether it can

The actions card is generated from the keymap registry -- ActionId::ALL under
Category::ALL, `keys_rows` the whole of the order -- and each row is two
targets: its label does the action, its stroke changes that stroke. One
enablement table answers for both the card and the clip menu, and tells a
class refusal from a state one, so a row that takes no click says why.
crates/app/src/main.rsmodified+476 -131
@@ -325,6 +325,47 @@ const MENU_ITEMS: [ActionId; 11] = [
325 ActionId::ToggleMute,325 ActionId::ToggleMute,
326 ];326 ];
327 327
328+/// One row of the actions card, in the order it lists them: a heading, then
329+/// every action the registry files under it, then the strokes the modal cards
330+/// answer themselves.
331+///
332+/// A list rather than a loop inside the render, so the card and
333+/// `every_action_is_on_the_actions_card` read the *same* order: an action that
334+/// reaches no row fails a test instead of quietly becoming pointer-unreachable.
335+enum KeyRow {
336+ Head(keymap::Category),
337+ /// Click its label to do it, click its stroke to change that stroke.
338+ Act(ActionId),
339+ /// An index into [`keymap::FIXED`]. Shown and never offered: nothing may
340+ /// unbind the way out of a card.
341+ Fixed(usize),
342+}
343+
344+/// Every action, under its heading, and the card-local strokes beside them.
345+/// Generated from the registry -- [`ActionId::ALL`] in its own order, under
346+/// [`keymap::Category::ALL`] -- so an action added there is on the card the
347+/// moment it exists and there is no second list here to forget.
348+fn keys_rows() -> Vec<KeyRow> {
349+ let mut rows = Vec::new();
350+ for category in keymap::Category::ALL {
351+ rows.push(KeyRow::Head(category));
352+ rows.extend(
353+ ActionId::ALL
354+ .into_iter()
355+ .filter(|a| a.category() == category)
356+ .map(KeyRow::Act),
357+ );
358+ rows.extend(
359+ keymap::FIXED
360+ .iter()
361+ .enumerate()
362+ .filter(|(_, f)| f.category == category)
363+ .map(|(i, _)| KeyRow::Fixed(i)),
364+ );
365+ }
366+ rows
367+}
368+
328 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.369 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.
329 /// A short list of the sizes people name; the media's own is cycled in beside370 /// A short list of the sizes people name; the media's own is cycled in beside
330 /// them, which is what makes the trip round come back to where it started.371 /// them, which is what makes the trip round come back to where it started.
@@ -834,6 +875,31 @@ impl Player {
834 }875 }
835 }876 }
836 877
878+ /// Whether the editor can be asked for `action` right now, and why not when
879+ /// it cannot. `on` is the clip the question is about -- the one a clip menu
880+ /// was opened on -- and `None` asks about the marked clip instead, which is
881+ /// what a menu that hangs over no clip in particular means by "this one".
882+ ///
883+ /// The player's half of [`enable`]: it reads the state, the table decides.
884+ fn enable(&self, action: ActionId, on: Option<(Lane, usize)>) -> Enable {
885+ let Some(session) = &self.session else {
886+ return enable(action, Ctx::default());
887+ };
888+ let clip = on
889+ .or(self.selected)
890+ .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane)));
891+ enable(
892+ action,
893+ Ctx {
894+ clip,
895+ playhead: frame_at(session.now(), self.fps),
896+ timeline: true,
897+ clipboard: self.clipboard.is_some(),
898+ exporting: self.exporting().is_some(),
899+ },
900+ )
901+ }
902+
837 /// The one place a clip becomes *the* selected one: a click, a right-click903 /// The one place a clip becomes *the* selected one: a click, a right-click
838 /// that opens the menu, and every selection key go through here, so what a904 /// that opens the menu, and every selection key go through here, so what a
839 /// keyboard marks and what a pointer marks are the same state marked the905 /// keyboard marks and what a pointer marks are the same state marked the
@@ -3558,8 +3624,10 @@ impl Player {
3558 .child(control(3624 .child(control(
3559 "keys",3625 "keys",
3560 None,3626 None,
3561- "Keys",3627+ "Actions",
3562- "show and change the keybindings".to_string(),3628+ // The pointer's way to every action there is, including
3629+ // the ones no button here has room for.
3630+ "do any action, or change the key that does it".to_string(),
3563 !exporting,3631 !exporting,
3564 cx.listener(|this, _: &ClickEvent, _, cx| {3632 cx.listener(|this, _: &ClickEvent, _, cx| {
3565 this.keys_open = !this.keys_open;3633 this.keys_open = !this.keys_open;
@@ -3744,83 +3812,111 @@ impl Player {
3744 ctrl: false,3812 ctrl: false,
3745 }3813 }
3746 .pretty();3814 .pretty();
3747- // Every stroke that works, under its heading, and both halves of the3815+ // Every action there is, under its heading, and the strokes the modal
3748- // list come from the registry: one row per action -- an action with two3816+ // cards answer to beside them -- `keys_rows` is the whole of the order
3749- // strokes reads as one line ("x or delete") and a rebind replaces that3817+ // and every word in it comes off the registry.
3750- // whole set -- then the strokes the modal cards answer to, which are3818+ //
3751- // shown but not offered, because nothing may unbind the way out.3819+ // A row is two targets, not one: its label *does* the action, which is
3820+ // the pointer's way to the ones no button carries, and its stroke
3821+ // changes that stroke. An action with two strokes reads as one line
3822+ // ("x or delete") and a rebind replaces that whole set.
3752 let mut rows: Vec<AnyElement> = Vec::new();3823 let mut rows: Vec<AnyElement> = Vec::new();
3753- for category in keymap::Category::ALL {3824+ let row = || {
3754- let actions = ActionId::ALL3825+ div()
3755- .into_iter()3826+ .flex()
3756- .enumerate()3827+ // The floor, not the height: a row that needed two lines
3757- .filter(|(_, a)| a.category() == category);3828+ // would otherwise paint over the one under it.
3758- let fixed = keymap::FIXED.iter().filter(|f| f.category == category);3829+ .min_h(px(KEYS_ROW_H))
3759- let mut headed = false;3830+ .items_center()
3760- let mut head = |rows: &mut Vec<AnyElement>| {3831+ .justify_between()
3761- if !std::mem::replace(&mut headed, true) {3832+ .gap(px(12.))
3762- rows.push(3833+ .px(px(6.))
3763- div()3834+ .rounded(px(3.))
3764- .flex_none()3835+ };
3765- .px(px(6.))3836+ for (i, key_row) in keys_rows().into_iter().enumerate() {
3766- .pt(px(4.))3837+ rows.push(match key_row {
3767- .text_size(px(11.))3838+ KeyRow::Head(category) => div()
3768- .text_color(rgb(INK_DIM))3839+ .flex_none()
3769- .child(category.label())3840+ .px(px(6.))
3770- .into_any_element(),3841+ .pt(px(4.))
3771- );3842+ .text_size(px(11.))
3772- }3843+ .text_color(rgb(INK_DIM))
3773- };3844+ .child(category.label())
3774- for (i, action) in actions {3845+ .into_any_element(),
3775- head(&mut rows);3846+ KeyRow::Act(action) => {
3776- let capturing = self.rebinding == Some(action);3847+ let capturing = self.rebinding == Some(action);
3777- let out = out.clone();3848+ // Why the label half will not answer, if it will not: the
3778- rows.push(3849+ // registry's one answer, the same the clip menu dims by.
3779- div()3850+ let refusal = self.enable(action, None);
3780- .id(("bind", i))3851+ let out = out.clone();
3781- .flex()3852+ row()
3782- // The floor, not the height: a row that needed two lines
3783- // would otherwise paint over the one under it.
3784- .min_h(px(KEYS_ROW_H))
3785- .items_center()
3786- .justify_between()
3787- .gap(px(12.))
3788- .px(px(6.))
3789- .rounded(px(3.))
3790- .cursor_pointer()
3791- .hover(|s| s.bg(rgb(HOVER)))
3792 .when(capturing, |d| d.bg(rgb(SELECTED)))3853 .when(capturing, |d| d.bg(rgb(SELECTED)))
3793- .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {3854+ .child(
3794- this.rebinding = Some(action);
3795- cx.notify();
3796- }))
3797- .child(action.label())
3798- .child(if capturing {
3799 div()3855 div()
3800- .text_color(rgb(INK_DIM))3856+ .id(("do", i))
3801- .child(format!("press a key — {out} cancels"))3857+ .flex_1()
3802- } else {3858+ .min_w(px(0.))
3803- div().child(self.keymap.display(action))3859+ .flex()
3804- })3860+ .min_h(px(KEYS_ROW_H))
3805- .into_any_element(),3861+ .items_center()
3806- );3862+ .child(action.label())
3807- }3863+ // The reason rides on the label rather than in
3808- for f in fixed {3864+ // the stroke column, which the rebind half
3809- head(&mut rows);3865+ // needs whatever the editor's state is: an
3810- rows.push(3866+ // action nobody can ask for right now is still
3811- div()3867+ // one whose key may be changed.
3812- .flex()3868+ .when_some(refusal.why(), |d, why| {
3813- .min_h(px(KEYS_ROW_H))3869+ let why: SharedString = why.into();
3814- .items_center()3870+ d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into())
3815- .justify_between()3871+ })
3816- .gap(px(12.))3872+ .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed())
3817- .px(px(6.))3873+ .when(refusal.yes(), |d| {
3874+ d.cursor_pointer().hover(|s| s.bg(rgb(HOVER))).on_click(
3875+ cx.listener(move |this, _: &ClickEvent, _, cx| {
3876+ // The card goes first: several of
3877+ // these open a card of their own,
3878+ // and every edit moves the indices
3879+ // the menus are holding.
3880+ this.keys_open = false;
3881+ this.rebinding = None;
3882+ this.act(action, cx);
3883+ cx.notify();
3884+ }),
3885+ )
3886+ }),
3887+ )
3888+ .child(
3889+ div()
3890+ .id(("bind", i))
3891+ .flex_none()
3892+ .flex()
3893+ .min_h(px(KEYS_ROW_H))
3894+ .items_center()
3895+ .cursor_pointer()
3896+ .hover(|s| s.bg(rgb(HOVER)))
3897+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
3898+ this.rebinding = Some(action);
3899+ cx.notify();
3900+ }))
3901+ .child(if capturing {
3902+ div()
3903+ .text_color(rgb(INK_DIM))
3904+ .child(format!("press a key — {out} cancels"))
3905+ } else {
3906+ div().child(self.keymap.display(action))
3907+ }),
3908+ )
3909+ .into_any_element()
3910+ }
3911+ KeyRow::Fixed(f) => {
3912+ let f = &keymap::FIXED[f];
3913+ row()
3818 .child(f.label)3914 .child(f.label)
3819 // Dim, and no hover: this one is not a row you can click.3915 // Dim, and no hover: this one is not a row you can click.
3820 .child(div().text_color(rgb(INK_DIM)).child(f.chord))3916 .child(div().text_color(rgb(INK_DIM)).child(f.chord))
3821- .into_any_element(),3917+ .into_any_element()
3822- );3918+ }
3823- }3919+ });
3824 }3920 }
3825 Some(3921 Some(
3826 div()3922 div()
@@ -3847,7 +3943,7 @@ impl Player {
3847 // Title and instruction are two children, never one3943 // Title and instruction are two children, never one
3848 // wrapping line: a fixed-height slot whose text wrapped3944 // wrapping line: a fixed-height slot whose text wrapped
3849 // painted its second line over the first row.3945 // painted its second line over the first row.
3850- .child(div().flex_none().px(px(6.)).child("Keybindings"))3946+ .child(div().flex_none().px(px(6.)).child("Actions & keys"))
3851 // One status line, under the title where the eye starts.3947 // One status line, under the title where the eye starts.
3852 // A refusal takes it over -- it is the more urgent of the3948 // A refusal takes it over -- it is the more urgent of the
3853 // two, and the notice bar it would otherwise appear in is3949 // two, and the notice bar it would otherwise appear in is
@@ -3865,7 +3961,10 @@ impl Player {
3865 .child(3961 .child(
3866 self.notice3962 self.notice
3867 .clone()3963 .clone()
3868- .unwrap_or_else(|| "click a row, then press a key".into()),3964+ .unwrap_or_else(|| {
3965+ "click an action to do it · click its key to change it"
3966+ .into()
3967+ }),
3869 ),3968 ),
3870 )3969 )
3871 // Capped and scrolling rather than as tall as the action3970 // Capped and scrolling rather than as tall as the action
@@ -4872,7 +4971,6 @@ impl Player {
4872 let menu = self.context_menu?;4971 let menu = self.context_menu?;
4873 let session = self.session.as_ref()?;4972 let session = self.session.as_ref()?;
4874 let clip = *session.lane_clips(menu.lane).get(menu.idx)?;4973 let clip = *session.lane_clips(menu.lane).get(menu.idx)?;
4875- let playhead = frame_at(session.now(), self.fps);
4876 let source = session.sources().get(clip.source).cloned()?;4974 let source = session.sources().get(clip.source).cloned()?;
4877 let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps);4975 let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps);
4878 let row = |n: usize| {4976 let row = |n: usize| {
@@ -4926,7 +5024,11 @@ impl Player {
4926 }5024 }
4927 } else {5025 } else {
4928 for action in MENU_ITEMS {5026 for action in MENU_ITEMS {
4929- let enabled = applicable(&clip, menu.lane, action, playhead);5027+ // The registry's own answer, the same one the actions card
5028+ // dims a row with -- and a row that takes no click says *why*
5029+ // rather than printing a stroke that would do nothing.
5030+ let refusal = self.enable(action, Some((menu.lane, menu.idx)));
5031+ let enabled = refusal.yes();
4930 // The one item that is not about this clip says so, and says it5032 // The one item that is not about this clip says so, and says it
4931 // here rather than in the registry: the stroke is global too,5033 // here rather than in the registry: the stroke is global too,
4932 // but its row in the keys menu is not sitting on a clip.5034 // but its row in the keys menu is not sitting on a clip.
@@ -4938,11 +5040,20 @@ impl Player {
4938 rows.push(5040 rows.push(
4939 row(rows.len())5041 row(rows.len())
4940 .child(label)5042 .child(label)
4941- .child(5043+ .child(match refusal.why() {
4942- div()5044+ // One truncated line, like the details side: a
5045+ // reason that wrapped would make the card taller
5046+ // than the height `menu_at` placed it by.
5047+ Some(why) => div()
5048+ .min_w(px(0.))
5049+ .truncate()
5050+ .text_size(px(11.))
5051+ .text_color(rgb(INK_DIM))
5052+ .child(why),
5053+ None => div()
4943 .text_color(rgb(INK_DIM))5054 .text_color(rgb(INK_DIM))
4944 .child(self.keymap.display(action)),5055 .child(self.keymap.display(action)),
4945- )5056+ })
4946 .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())5057 .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())
4947 .when(enabled, |d| {5058 .when(enabled, |d| {
4948 d.cursor_pointer()5059 d.cursor_pointer()
@@ -5592,42 +5703,132 @@ fn band_label(band: &Band) -> String {
5592 }5703 }
5593 }5704 }
5594 5705
5595-/// Whether the clip menu offers `action` on the clip it was opened on. Two of5706+/// Whether an action can be asked for, and what to say when it cannot. Two
5596-/// the items act on the *playhead* rather than on the clip, so a menu opened5707+/// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at
5597-/// away from it dims them instead of looking broken when they are clicked, and5708+/// -- an audio clip has no picture, so a grade is not a thing that exists for
5598-/// one acts on sound, which only an audio lane's clip has.5709+/// it, whatever the editor does next -- and `No` is about the state of this
5599-fn applicable(clip: &Clip, lane: Lane, action: ActionId, playhead: u32) -> bool {5710+/// moment, which the next click of the playhead can change. Both dim their row
5600- match action {5711+/// today; a menu that wants to leave the class refusals out and keep the state
5601- // The equalizer filters samples, and a video clip has none of its own5712+/// ones has only to match on which of the two it got.
5602- // here: the sound is the audio lane's, clip for clip.5713+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
5603- ActionId::Equalizer => lane.kind == LaneKind::Audio,5714+enum Enable {
5604- // A grade is a picture setting and an audio clip has no picture: the5715+ Yes,
5605- // item is there on every clip, and dimmed where it would mean nothing.5716+ No(&'static str),
5606- // A fit policy is a picture setting for the same reason.5717+ Hidden(&'static str),
5607- ActionId::Color | ActionId::Fit => lane.kind == LaneKind::Video,5718+}
5608- // Splits this clip only from inside it: at either edge there is nothing5719+
5609- // to split off -- and, on a speeded clip, only at a frame its own rate5720+impl Enable {
5610- // can address, which is the same question `splittable` asks.5721+ /// Whether the row takes a click.
5611- ActionId::Cut => {5722+ fn yes(self) -> bool {
5612- clip.start < playhead5723+ self == Enable::Yes
5613- && playhead < clip.end()5724+ }
5614- && clip5725+
5615- .speed5726+ /// What the row says instead of its stroke, if it says anything.
5616- .split_at(clip.len(), playhead - clip.start)5727+ fn why(self) -> Option<&'static str> {
5617- .is_some()5728+ match self {
5729+ Enable::Yes => None,
5730+ Enable::No(why) | Enable::Hidden(why) => Some(why),
5618 }5731 }
5619- // A rate applies to a clip of either kind and to its whole group, so5732+ }
5620- // there is no lane it means nothing on -- `_ => true` below is its5733+}
5621- // answer, and the engine words the one refusal there is (no room).5734+
5735+/// What an enablement question is asked *about*: the clip in question, if there
5736+/// is one, and the little of the editor's state the answers need. Handed in
5737+/// rather than read off the player, so [`enable`] is a pure function a test can
5738+/// ask about a clip without building a window.
5739+#[derive(Clone, Copy, Default)]
5740+struct Ctx {
5741+ /// The clip the question is about -- the one a menu was opened on, or the
5742+ /// marked one. `None` means the question is about the editor as a whole,
5743+ /// and the clip-relative answers stand aside: those actions find their own
5744+ /// clip under the playhead and word their own refusal.
5745+ clip: Option<(Clip, Lane)>,
5746+ playhead: u32,
5747+ /// A timeline is open.
5748+ timeline: bool,
5749+ /// Something has been copied.
5750+ clipboard: bool,
5751+ exporting: bool,
5752+}
5753+
5754+/// Whether `action` can be asked for, on `ctx`. One arm per action and nothing
5755+/// else in the editor asks the question: the clip menu dims a row with this,
5756+/// the actions card dims a row with this, and the two can never come to
5757+/// disagree about what an action needs -- exactly the reason [`Player::act`] is
5758+/// one table too.
5759+fn enable(action: ActionId, ctx: Ctx) -> Enable {
5760+ if !ctx.timeline {
5761+ return Enable::No("no timeline open");
5762+ }
5763+ // An export is reading the edit list every other action would change, which
5764+ // is the rule the key handler already follows.
5765+ if ctx.exporting {
5766+ return match action {
5767+ ActionId::CancelExport => Enable::Yes,
5768+ _ => Enable::No("an export is running"),
5769+ };
5770+ }
5771+ match action {
5772+ // -- class: what kind of thing the action is about. The equalizer
5773+ // filters samples, and a video clip has none of its own here: the sound
5774+ // is the audio lane's, clip for clip.
5775+ ActionId::Equalizer => match ctx.clip {
5776+ Some((_, lane)) if lane.kind != LaneKind::Audio => Enable::Hidden("this clip is picture"),
5777+ _ => Enable::Yes,
5778+ },
5779+ // A grade is a picture setting and an audio clip has no picture. A fit
5780+ // policy is a picture setting for the same reason.
5781+ ActionId::Color | ActionId::Fit => match ctx.clip {
5782+ Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"),
5783+ _ => Enable::Yes,
5784+ },
5785+ // -- state: true of this clip now, and the next playhead click or the
5786+ // next selection changes the answer. Splits this clip only from inside
5787+ // it: at either edge there is nothing to split off -- and, on a speeded
5788+ // clip, only at a frame its own rate can address, which is the same
5789+ // question `splittable` asks.
5790+ ActionId::Cut => match ctx.clip {
5791+ Some((clip, _))
5792+ if !(clip.start < ctx.playhead
5793+ && ctx.playhead < clip.end()
5794+ && clip
5795+ .speed
5796+ .split_at(clip.len(), ctx.playhead - clip.start)
5797+ .is_some()) =>
5798+ {
5799+ Enable::No("only from inside a clip")
5800+ }
5801+ _ => Enable::Yes,
5802+ },
5622 // Rejoins whatever meets at the playhead, so it can mean something only5803 // Rejoins whatever meets at the playhead, so it can mean something only
5623 // at an edge of this clip. Whether those two halves were ever one take5804 // at an edge of this clip. Whether those two halves were ever one take
5624 // is the engine's question, and it words that refusal itself.5805 // is the engine's question, and it words that refusal itself.
5625- ActionId::Regroup => playhead == clip.start || playhead == clip.end(),5806+ ActionId::Regroup => match ctx.clip {
5807+ Some((clip, _)) if ctx.playhead != clip.start && ctx.playhead != clip.end() => {
5808+ Enable::No("only where two clips meet")
5809+ }
5810+ _ => Enable::Yes,
5811+ },
5626 // Nothing to take apart in a clip that names no group at all. Whether5812 // Nothing to take apart in a clip that names no group at all. Whether
5627 // the group it names still has another half is the engine's question,5813 // the group it names still has another half is the engine's question,
5628- // like the regroup above, and it words that refusal itself.5814+ // like the regroup above.
5629- ActionId::Detach => clip.link.is_some(),5815+ ActionId::Detach => match ctx.clip {
5630- _ => true,5816+ Some((clip, _)) if clip.link.is_none() => Enable::No("this clip is not grouped"),
5817+ _ => Enable::Yes,
5818+ },
5819+ // The three that act on the marked clip and on nothing else: with none
5820+ // marked they would silently do nothing, which is what the Delete
5821+ // button's own dimming has always said.
5822+ ActionId::Copy | ActionId::Delete | ActionId::Lift if ctx.clip.is_none() => {
5823+ Enable::No("click a clip first")
5824+ }
5825+ ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"),
5826+ ActionId::CancelExport => Enable::No("nothing is exporting"),
5827+ // A rate applies to a clip of either kind and to its whole group, so
5828+ // there is no lane it means nothing on, and the engine words the one
5829+ // refusal there is (no room). Everything else is the editor's own and
5830+ // needs nothing but a timeline.
5831+ _ => Enable::Yes,
5631 }5832 }
5632 }5833 }
5633 5834
@@ -6711,9 +6912,11 @@ mod tests {
6711 LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H,6912 LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H,
6712 Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS,6913 Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS,
6713 SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Volume, WAVE_BPS, WAVE_COL, Wave,6914 SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Volume, WAVE_BPS, WAVE_COL, Wave,
6714- applicable, band_label, can_add, cancels_export, color_snap, envelope, eq_x, eq_y,6915+ Ctx, Enable, KeyRow, band_label, can_add, cancels_export, color_snap, enable, envelope,
6916+ eq_x, eq_y,
6715 export_path, export_settings, format_key, format_line, format_refusal, frac_along,6917 export_path, export_settings, format_key, format_line, format_refusal, frac_along,
6716- frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked,6918+ frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, keys_rows, lanes_h,
6919+ marked,
6717 menu_at, normalise, panel_h, project_path, push_digit, retarget, scrub_due, show_label,6920 menu_at, normalise, panel_h, project_path, push_digit, retarget, scrub_due, show_label,
6718 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,6921 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,
6719 unseen_sources, whole_take, width_frac, window_title,6922 unseen_sources, whole_take, width_frac, window_title,
@@ -7006,43 +7209,126 @@ mod tests {
7006 speed: Speed::NORMAL,7209 speed: Speed::NORMAL,
7007 };7210 };
7008 assert_eq!(clip.end(), 90);7211 assert_eq!(clip.end(), 90);
7009- // Cut splits from inside only: neither edge has anything to split off.
7010 let a1 = Lane::A1;7212 let a1 = Lane::A1;
7011 let v1 = Lane::V1;7213 let v1 = Lane::V1;
7012- assert!(applicable(&clip, v1, ActionId::Cut, 31));7214+ // The question the clip menu asks: a timeline is open and the menu was
7013- assert!(applicable(&clip, v1, ActionId::Cut, 89));7215+ // opened on this clip, at this playhead.
7014- assert!(!applicable(&clip, v1, ActionId::Cut, 30));7216+ let on = |clip: &Clip, lane, action, playhead| {
7015- assert!(!applicable(&clip, v1, ActionId::Cut, 90));7217+ enable(
7016- assert!(!applicable(&clip, v1, ActionId::Cut, 200));7218+ action,
7219+ Ctx {
7220+ clip: Some((*clip, lane)),
7221+ playhead,
7222+ timeline: true,
7223+ ..Ctx::default()
7224+ },
7225+ )
7226+ };
7227+ let offered = |clip: &Clip, lane, action, playhead| on(clip, lane, action, playhead).yes();
7228+ // Cut splits from inside only: neither edge has anything to split off.
7229+ assert!(offered(&clip, v1, ActionId::Cut, 31));
7230+ assert!(offered(&clip, v1, ActionId::Cut, 89));
7231+ assert!(!offered(&clip, v1, ActionId::Cut, 30));
7232+ assert!(!offered(&clip, v1, ActionId::Cut, 90));
7233+ assert!(!offered(&clip, v1, ActionId::Cut, 200));
7017 // Regroup is the other way round: only where this clip meets another.7234 // Regroup is the other way round: only where this clip meets another.
7018- assert!(applicable(&clip, v1, ActionId::Regroup, 30));7235+ assert!(offered(&clip, v1, ActionId::Regroup, 30));
7019- assert!(applicable(&clip, v1, ActionId::Regroup, 90));7236+ assert!(offered(&clip, v1, ActionId::Regroup, 90));
7020- assert!(!applicable(&clip, v1, ActionId::Regroup, 60));7237+ assert!(!offered(&clip, v1, ActionId::Regroup, 60));
7021 // Detach is the clip's own business: nothing to take apart in one that7238 // Detach is the clip's own business: nothing to take apart in one that
7022 // names no group, and whether the group still has another half is the7239 // names no group, and whether the group still has another half is the
7023 // engine's question. Group is offered on every clip, for that reason.7240 // engine's question. Group is offered on every clip, for that reason.
7024- assert!(!applicable(&clip, v1, ActionId::Detach, 0));7241+ assert!(!offered(&clip, v1, ActionId::Detach, 0));
7025 let grouped = Clip {7242 let grouped = Clip {
7026 link: Some(3),7243 link: Some(3),
7027 ..clip7244 ..clip
7028 };7245 };
7029- assert!(applicable(&grouped, v1, ActionId::Detach, 60));7246+ assert!(offered(&grouped, v1, ActionId::Detach, 60));
7030- assert!(applicable(&clip, a1, ActionId::Group, 0));7247+ assert!(offered(&clip, a1, ActionId::Group, 0));
7031 // The equalizer is the one item the *lane* decides: it filters samples,7248 // The equalizer is the one item the *lane* decides: it filters samples,
7032 // and a video clip has none of its own. Never the playhead's business.7249 // and a video clip has none of its own. Never the playhead's business.
7033- assert!(applicable(&clip, a1, ActionId::Equalizer, 0));7250+ assert!(offered(&clip, a1, ActionId::Equalizer, 0));
7034- assert!(applicable(&clip, a1, ActionId::Equalizer, 60));7251+ assert!(offered(&clip, a1, ActionId::Equalizer, 60));
7035- assert!(!applicable(&clip, v1, ActionId::Equalizer, 60));7252+ assert!(!offered(&clip, v1, ActionId::Equalizer, 60));
7036 // The rest act on the clip that was clicked, so they always mean7253 // The rest act on the clip that was clicked, so they always mean
7037 // something -- the engine words its own refusals.7254 // something -- the engine words its own refusals.
7038 for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] {7255 for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] {
7039- assert!(applicable(&clip, v1, action, 0));7256+ assert!(offered(&clip, v1, action, 0));
7040- assert!(applicable(&clip, a1, action, 60));7257+ assert!(offered(&clip, a1, action, 60));
7041 }7258 }
7042 // Except the grade, which is a picture setting: offered on a video7259 // Except the grade, which is a picture setting: offered on a video
7043 // clip wherever the playhead is, dimmed on a waveform.7260 // clip wherever the playhead is, dimmed on a waveform.
7044- assert!(applicable(&clip, v1, ActionId::Color, 0));7261+ assert!(offered(&clip, v1, ActionId::Color, 0));
7045- assert!(!applicable(&clip, a1, ActionId::Color, 60));7262+ assert!(!offered(&clip, a1, ActionId::Color, 60));
7263+ // The two kinds of no, which is what the row can be told apart by: a
7264+ // grade on a waveform is a *class* answer -- an audio clip has no
7265+ // picture and never will, so a menu may leave the item out -- where a
7266+ // cut at the clip's edge is this moment's answer and the next click of
7267+ // the playhead changes it, so that one is dimmed and stays.
7268+ assert!(matches!(
7269+ on(&clip, a1, ActionId::Color, 60),
7270+ Enable::Hidden(_)
7271+ ));
7272+ assert!(matches!(
7273+ on(&clip, a1, ActionId::Fit, 60),
7274+ Enable::Hidden(_)
7275+ ));
7276+ assert!(matches!(
7277+ on(&clip, v1, ActionId::Equalizer, 60),
7278+ Enable::Hidden(_)
7279+ ));
7280+ assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_)));
7281+ assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_)));
7282+ assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_)));
7283+ // Every refusal says something, and says it short enough to sit in the
7284+ // menu's right-hand column beside a label.
7285+ for action in MENU_ITEMS {
7286+ for lane in [v1, a1] {
7287+ for playhead in [0, 30, 60, 90] {
7288+ if let Some(why) = on(&clip, lane, action, playhead).why() {
7289+ assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}");
7290+ }
7291+ }
7292+ }
7293+ }
7294+ // The editor as a whole, which is how the actions card asks: with no
7295+ // timeline nothing is offered, an export leaves only its own cancel,
7296+ // and the three that act on the marked clip say so when none is.
7297+ let whole = |action, ctx| enable(action, ctx);
7298+ assert_eq!(
7299+ whole(ActionId::Play, Ctx::default()),
7300+ Enable::No("no timeline open")
7301+ );
7302+ let live = Ctx {
7303+ timeline: true,
7304+ ..Ctx::default()
7305+ };
7306+ assert!(whole(ActionId::Play, live).yes());
7307+ assert!(!whole(ActionId::Delete, live).yes());
7308+ assert!(!whole(ActionId::Paste, live).yes());
7309+ assert!(
7310+ whole(
7311+ ActionId::Paste,
7312+ Ctx {
7313+ clipboard: true,
7314+ ..live
7315+ }
7316+ )
7317+ .yes()
7318+ );
7319+ assert!(!whole(ActionId::CancelExport, live).yes());
7320+ let busy = Ctx {
7321+ exporting: true,
7322+ ..live
7323+ };
7324+ assert!(whole(ActionId::CancelExport, busy).yes());
7325+ for action in ActionId::ALL {
7326+ assert_eq!(
7327+ whole(action, busy).yes(),
7328+ action == ActionId::CancelExport,
7329+ "{action:?} while an export reads the edit list"
7330+ );
7331+ }
7046 // The playhead frame is the engine's own rule, boundary included.7332 // The playhead frame is the engine's own rule, boundary included.
7047 assert_eq!(frame_at(1.0, 30.), 30);7333 assert_eq!(frame_at(1.0, 30.), 30);
7048 assert_eq!(frame_at(0.0, 30.), 0);7334 assert_eq!(frame_at(0.0, 30.), 0);
@@ -7786,6 +8072,65 @@ mod tests {
7786 }8072 }
7787 }8073 }
7788 8074
8075+ /// The whole point of the card: there is no action a pointer cannot reach.
8076+ /// It renders [`keys_rows`] and nothing else, so this reads the same list
8077+ /// the card does -- add an `ActionId` and forget to surface it and this
8078+ /// fails, which is the only way that stays true as the editor grows.
8079+ #[test]
8080+ fn every_action_is_on_the_actions_card() {
8081+ use keymap::{ActionId, Category, Keymap};
8082+ let rows = keys_rows();
8083+ let listed: Vec<ActionId> = rows
8084+ .iter()
8085+ .filter_map(|r| match r {
8086+ KeyRow::Act(a) => Some(*a),
8087+ _ => None,
8088+ })
8089+ .collect();
8090+ for action in ActionId::ALL {
8091+ assert_eq!(
8092+ listed.iter().filter(|a| **a == action).count(),
8093+ 1,
8094+ "{action:?} is not on the card exactly once"
8095+ );
8096+ }
8097+ assert_eq!(listed.len(), ActionId::ALL.len());
8098+ // Under its own heading, in the registry's order: every row after a
8099+ // heading belongs to that heading until the next one.
8100+ let mut heading = None;
8101+ let mut heads = 0;
8102+ for row in &rows {
8103+ match row {
8104+ KeyRow::Head(category) => {
8105+ heading = Some(*category);
8106+ heads += 1;
8107+ }
8108+ KeyRow::Act(action) => assert_eq!(Some(action.category()), heading, "{action:?}"),
8109+ KeyRow::Fixed(i) => assert_eq!(Some(keymap::FIXED[*i].category), heading),
8110+ }
8111+ }
8112+ assert_eq!(heads, Category::ALL.len(), "a heading per category");
8113+ // The card-local strokes are still all there beside them.
8114+ assert_eq!(
8115+ rows.iter()
8116+ .filter(|r| matches!(r, KeyRow::Fixed(_)))
8117+ .count(),
8118+ keymap::FIXED.len()
8119+ );
8120+ // Both columns say something: the label does the action, the stroke
8121+ // beside it changes that stroke, and neither may read blank.
8122+ let keymap = Keymap::defaults();
8123+ for action in ActionId::ALL {
8124+ assert!(!action.label().is_empty(), "{action:?}");
8125+ assert_ne!(keymap.display(action), "unbound", "{action:?}");
8126+ }
8127+ // The list scrolls inside a card the smallest window holds, so a
8128+ // thirty-fourth action costs no height at all.
8129+ assert!(rows.len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, "no cap needed?");
8130+ // Both halves of a row are click targets, so WCAG 2.5.8 binds them.
8131+ assert!(KEYS_ROW_H >= HIT_MIN);
8132+ }
8133+
7789 #[test]8134 #[test]
7790 fn the_keybindings_card_fits_the_smallest_window() {8135 fn the_keybindings_card_fits_the_smallest_window() {
7791 // The row list is capped and scrolls, so the card's height no longer8136 // The row list is capped and scrolls, so the card's height no longer