Merge remote-tracking branch 'origin/main' into worktree-agent-ae0878bafe33df931
Browse files at this commit1 changed file +512 -191
- crates/app/src/main.rs +512 -191
crates/app/src/main.rsmodified+512 -191
| @@ -406,6 +406,47 @@ const MENU_ITEMS: [ActionId; 14] = [ | |||
| 406 | ActionId::ToggleMute, | 406 | ActionId::ToggleMute, |
| 407 | ]; | 407 | ]; |
| 408 | 408 | ||
| 409 | +/// One row of the actions card, in the order it lists them: a heading, then | ||
| 410 | +/// every action the registry files under it, then the strokes the modal cards | ||
| 411 | +/// answer themselves. | ||
| 412 | +/// | ||
| 413 | +/// A list rather than a loop inside the render, so the card and | ||
| 414 | +/// `every_action_is_on_the_actions_card` read the *same* order: an action that | ||
| 415 | +/// reaches no row fails a test instead of quietly becoming pointer-unreachable. | ||
| 416 | +enum KeyRow { | ||
| 417 | + Head(keymap::Category), | ||
| 418 | + /// Click its label to do it, click its stroke to change that stroke. | ||
| 419 | + Act(ActionId), | ||
| 420 | + /// An index into [`keymap::FIXED`]. Shown and never offered: nothing may | ||
| 421 | + /// unbind the way out of a card. | ||
| 422 | + Fixed(usize), | ||
| 423 | +} | ||
| 424 | + | ||
| 425 | +/// Every action, under its heading, and the card-local strokes beside them. | ||
| 426 | +/// Generated from the registry -- [`ActionId::ALL`] in its own order, under | ||
| 427 | +/// [`keymap::Category::ALL`] -- so an action added there is on the card the | ||
| 428 | +/// moment it exists and there is no second list here to forget. | ||
| 429 | +fn keys_rows() -> Vec<KeyRow> { | ||
| 430 | + let mut rows = Vec::new(); | ||
| 431 | + for category in keymap::Category::ALL { | ||
| 432 | + rows.push(KeyRow::Head(category)); | ||
| 433 | + rows.extend( | ||
| 434 | + ActionId::ALL | ||
| 435 | + .into_iter() | ||
| 436 | + .filter(|a| a.category() == category) | ||
| 437 | + .map(KeyRow::Act), | ||
| 438 | + ); | ||
| 439 | + rows.extend( | ||
| 440 | + keymap::FIXED | ||
| 441 | + .iter() | ||
| 442 | + .enumerate() | ||
| 443 | + .filter(|(_, f)| f.category == category) | ||
| 444 | + .map(|(i, _)| KeyRow::Fixed(i)), | ||
| 445 | + ); | ||
| 446 | + } | ||
| 447 | + rows | ||
| 448 | +} | ||
| 449 | + | ||
| 409 | /// The project resolutions [`Player::cycle_resolution`] offers, largest first. | 450 | /// The project resolutions [`Player::cycle_resolution`] offers, largest first. |
| 410 | /// A short list of the sizes people name; the media's own is cycled in beside | 451 | /// A short list of the sizes people name; the media's own is cycled in beside |
| 411 | /// them, which is what makes the trip round come back to where it started. | 452 | /// them, which is what makes the trip round come back to where it started. |
| @@ -1133,6 +1174,31 @@ impl Player { | |||
| 1133 | } | 1174 | } |
| 1134 | } | 1175 | } |
| 1135 | 1176 | ||
| 1177 | + /// Whether the editor can be asked for `action` right now, and why not when | ||
| 1178 | + /// it cannot. `on` is the clip the question is about -- the one a clip menu | ||
| 1179 | + /// was opened on -- and `None` asks about the marked clip instead, which is | ||
| 1180 | + /// what a menu that hangs over no clip in particular means by "this one". | ||
| 1181 | + /// | ||
| 1182 | + /// The player's half of [`enable`]: it reads the state, the table decides. | ||
| 1183 | + fn enable(&self, action: ActionId, on: Option<(Lane, usize)>) -> Enable { | ||
| 1184 | + let Some(session) = &self.session else { | ||
| 1185 | + return enable(action, Ctx::default()); | ||
| 1186 | + }; | ||
| 1187 | + let clip = on | ||
| 1188 | + .or(self.selected) | ||
| 1189 | + .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane))); | ||
| 1190 | + enable( | ||
| 1191 | + action, | ||
| 1192 | + Ctx { | ||
| 1193 | + clip, | ||
| 1194 | + playhead: frame_at(session.now(), self.fps), | ||
| 1195 | + timeline: true, | ||
| 1196 | + clipboard: self.clipboard.is_some(), | ||
| 1197 | + exporting: self.exporting().is_some(), | ||
| 1198 | + }, | ||
| 1199 | + ) | ||
| 1200 | + } | ||
| 1201 | + | ||
| 1136 | /// The one place a clip becomes *the* selected one: a click, a right-click | 1202 | /// The one place a clip becomes *the* selected one: a click, a right-click |
| 1137 | /// that opens the menu, and every selection key go through here, so what a | 1203 | /// that opens the menu, and every selection key go through here, so what a |
| 1138 | /// keyboard marks and what a pointer marks are the same state marked the | 1204 | /// keyboard marks and what a pointer marks are the same state marked the |
| @@ -4717,8 +4783,10 @@ impl Player { | |||
| 4717 | .child(control( | 4783 | .child(control( |
| 4718 | "keys", | 4784 | "keys", |
| 4719 | None, | 4785 | None, |
| 4720 | - "Keys", | 4786 | + "Actions", |
| 4721 | - "show and change the keybindings".to_string(), | 4787 | + // The pointer's way to every action there is, including |
| 4788 | + // the ones no button here has room for. | ||
| 4789 | + "do any action, or change the key that does it".to_string(), | ||
| 4722 | !exporting, | 4790 | !exporting, |
| 4723 | cx.listener(|this, _: &ClickEvent, _, cx| { | 4791 | cx.listener(|this, _: &ClickEvent, _, cx| { |
| 4724 | this.keys_open = !this.keys_open; | 4792 | this.keys_open = !this.keys_open; |
| @@ -4928,83 +4996,115 @@ impl Player { | |||
| 4928 | ctrl: false, | 4996 | ctrl: false, |
| 4929 | } | 4997 | } |
| 4930 | .pretty(); | 4998 | .pretty(); |
| 4931 | - // Every stroke that works, under its heading, and both halves of the | 4999 | + // Every action there is, under its heading, and the strokes the modal |
| 4932 | - // list come from the registry: one row per action -- an action with two | 5000 | + // cards answer to beside them -- `keys_rows` is the whole of the order |
| 4933 | - // strokes reads as one line ("x or delete") and a rebind replaces that | 5001 | + // and every word in it comes off the registry. |
| 4934 | - // whole set -- then the strokes the modal cards answer to, which are | 5002 | + // |
| 4935 | - // shown but not offered, because nothing may unbind the way out. | 5003 | + // A row is two targets, not one: its label *does* the action, which is |
| 5004 | + // the pointer's way to the ones no button carries, and its stroke | ||
| 5005 | + // changes that stroke. An action with two strokes reads as one line | ||
| 5006 | + // ("x or delete") and a rebind replaces that whole set. | ||
| 4936 | let mut rows: Vec<AnyElement> = Vec::new(); | 5007 | let mut rows: Vec<AnyElement> = Vec::new(); |
| 4937 | - for category in keymap::Category::ALL { | 5008 | + let row = || { |
| 4938 | - let actions = ActionId::ALL | 5009 | + div() |
| 4939 | - .into_iter() | 5010 | + .flex() |
| 4940 | - .enumerate() | 5011 | + // The floor, not the height: a row that needed two lines |
| 4941 | - .filter(|(_, a)| a.category() == category); | 5012 | + // would otherwise paint over the one under it. |
| 4942 | - let fixed = keymap::FIXED.iter().filter(|f| f.category == category); | 5013 | + .min_h(px(KEYS_ROW_H)) |
| 4943 | - let mut headed = false; | 5014 | + .items_center() |
| 4944 | - let mut head = |rows: &mut Vec<AnyElement>| { | 5015 | + .justify_between() |
| 4945 | - if !std::mem::replace(&mut headed, true) { | 5016 | + .gap(px(12.)) |
| 4946 | - rows.push( | 5017 | + .px(px(6.)) |
| 4947 | - div() | 5018 | + .rounded(px(3.)) |
| 4948 | - .flex_none() | 5019 | + }; |
| 4949 | - .px(px(6.)) | 5020 | + for (i, key_row) in keys_rows().into_iter().enumerate() { |
| 4950 | - .pt(px(4.)) | 5021 | + rows.push(match key_row { |
| 4951 | - .text_size(px(11.)) | 5022 | + KeyRow::Head(category) => div() |
| 4952 | - .text_color(rgb(INK_DIM)) | 5023 | + .flex_none() |
| 4953 | - .child(category.label()) | 5024 | + .px(px(6.)) |
| 4954 | - .into_any_element(), | 5025 | + .pt(px(4.)) |
| 4955 | - ); | 5026 | + .text_size(px(11.)) |
| 4956 | - } | 5027 | + .text_color(rgb(INK_DIM)) |
| 4957 | - }; | 5028 | + .child(category.label()) |
| 4958 | - for (i, action) in actions { | 5029 | + .into_any_element(), |
| 4959 | - head(&mut rows); | 5030 | + KeyRow::Act(action) => { |
| 4960 | - let capturing = self.rebinding == Some(action); | 5031 | + let capturing = self.rebinding == Some(action); |
| 4961 | - let out = out.clone(); | 5032 | + // Why the label half will not answer, if it will not: the |
| 4962 | - rows.push( | 5033 | + // registry's one answer, the same the clip menu dims by. |
| 4963 | - div() | 5034 | + let refusal = self.enable(action, None); |
| 4964 | - .id(("bind", i)) | 5035 | + let out = out.clone(); |
| 4965 | - .flex() | 5036 | + row() |
| 4966 | - // The floor, not the height: a row that needed two lines | ||
| 4967 | - // would otherwise paint over the one under it. | ||
| 4968 | - .min_h(px(KEYS_ROW_H)) | ||
| 4969 | - .items_center() | ||
| 4970 | - .justify_between() | ||
| 4971 | - .gap(px(12.)) | ||
| 4972 | - .px(px(6.)) | ||
| 4973 | - .rounded(px(3.)) | ||
| 4974 | - .cursor_pointer() | ||
| 4975 | - .hover(|s| s.bg(rgb(HOVER))) | ||
| 4976 | .when(capturing, |d| d.bg(rgb(SELECTED))) | 5037 | .when(capturing, |d| d.bg(rgb(SELECTED))) |
| 4977 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 5038 | + .child( |
| 4978 | - this.rebinding = Some(action); | ||
| 4979 | - cx.notify(); | ||
| 4980 | - })) | ||
| 4981 | - .child(action.label()) | ||
| 4982 | - .child(if capturing { | ||
| 4983 | div() | 5039 | div() |
| 4984 | - .text_color(rgb(INK_DIM)) | 5040 | + .id(("do", i)) |
| 4985 | - .child(format!("press a key — {out} cancels")) | 5041 | + .flex_1() |
| 4986 | - } else { | 5042 | + .min_w(px(0.)) |
| 4987 | - div().child(self.keymap.display(action)) | 5043 | + .flex() |
| 4988 | - }) | 5044 | + .min_h(px(KEYS_ROW_H)) |
| 4989 | - .into_any_element(), | 5045 | + .items_center() |
| 4990 | - ); | 5046 | + .child(action.label()) |
| 4991 | - } | 5047 | + // The reason rides on the label rather than in |
| 4992 | - for f in fixed { | 5048 | + // the stroke column, which the rebind half |
| 4993 | - head(&mut rows); | 5049 | + // needs whatever the editor's state is: an |
| 4994 | - rows.push( | 5050 | + // action nobody can ask for right now is still |
| 4995 | - div() | 5051 | + // one whose key may be changed. |
| 4996 | - .flex() | 5052 | + .when_some(refusal.why(), |d, why| { |
| 4997 | - .min_h(px(KEYS_ROW_H)) | 5053 | + let why: SharedString = why.into(); |
| 4998 | - .items_center() | 5054 | + d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into()) |
| 4999 | - .justify_between() | 5055 | + }) |
| 5000 | - .gap(px(12.)) | 5056 | + .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) |
| 5001 | - .px(px(6.)) | 5057 | + .when(refusal.yes(), |d| { |
| 5058 | + d.cursor_pointer().hover(|s| s.bg(rgb(HOVER))).on_click( | ||
| 5059 | + cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5060 | + // The card goes first: several of | ||
| 5061 | + // these open a card of their own, | ||
| 5062 | + // and every edit moves the indices | ||
| 5063 | + // the menus are holding. | ||
| 5064 | + this.keys_open = false; | ||
| 5065 | + this.rebinding = None; | ||
| 5066 | + this.act(action, cx); | ||
| 5067 | + cx.notify(); | ||
| 5068 | + }), | ||
| 5069 | + ) | ||
| 5070 | + }), | ||
| 5071 | + ) | ||
| 5072 | + .child( | ||
| 5073 | + // ponytail: the column is as wide as the stroke it | ||
| 5074 | + // prints, so a one-character chord gives this half a | ||
| 5075 | + // hit area under the 24px WCAG 2.5.8 floor -- tall | ||
| 5076 | + // enough, narrow. Upgrade: a min_w of HIT_MIN here. | ||
| 5077 | + div() | ||
| 5078 | + .id(("bind", i)) | ||
| 5079 | + .flex_none() | ||
| 5080 | + .flex() | ||
| 5081 | + .min_h(px(KEYS_ROW_H)) | ||
| 5082 | + .items_center() | ||
| 5083 | + .cursor_pointer() | ||
| 5084 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5085 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5086 | + this.rebinding = Some(action); | ||
| 5087 | + cx.notify(); | ||
| 5088 | + })) | ||
| 5089 | + .child(if capturing { | ||
| 5090 | + div() | ||
| 5091 | + .text_color(rgb(INK_DIM)) | ||
| 5092 | + .child(format!("press a key — {out} cancels")) | ||
| 5093 | + } else { | ||
| 5094 | + div().child(self.keymap.display(action)) | ||
| 5095 | + }), | ||
| 5096 | + ) | ||
| 5097 | + .into_any_element() | ||
| 5098 | + } | ||
| 5099 | + KeyRow::Fixed(f) => { | ||
| 5100 | + let f = &keymap::FIXED[f]; | ||
| 5101 | + row() | ||
| 5002 | .child(f.label) | 5102 | .child(f.label) |
| 5003 | // Dim, and no hover: this one is not a row you can click. | 5103 | // Dim, and no hover: this one is not a row you can click. |
| 5004 | .child(div().text_color(rgb(INK_DIM)).child(f.chord)) | 5104 | .child(div().text_color(rgb(INK_DIM)).child(f.chord)) |
| 5005 | - .into_any_element(), | 5105 | + .into_any_element() |
| 5006 | - ); | 5106 | + } |
| 5007 | - } | 5107 | + }); |
| 5008 | } | 5108 | } |
| 5009 | Some( | 5109 | Some( |
| 5010 | div() | 5110 | div() |
| @@ -5031,7 +5131,7 @@ impl Player { | |||
| 5031 | // Title and instruction are two children, never one | 5131 | // Title and instruction are two children, never one |
| 5032 | // wrapping line: a fixed-height slot whose text wrapped | 5132 | // wrapping line: a fixed-height slot whose text wrapped |
| 5033 | // painted its second line over the first row. | 5133 | // painted its second line over the first row. |
| 5034 | - .child(div().flex_none().px(px(6.)).child("Keybindings")) | 5134 | + .child(div().flex_none().px(px(6.)).child("Actions & keys")) |
| 5035 | // One status line, under the title where the eye starts. | 5135 | // One status line, under the title where the eye starts. |
| 5036 | // A refusal takes it over -- it is the more urgent of the | 5136 | // A refusal takes it over -- it is the more urgent of the |
| 5037 | // two, and the notice bar it would otherwise appear in is | 5137 | // two, and the notice bar it would otherwise appear in is |
| @@ -5049,7 +5149,10 @@ impl Player { | |||
| 5049 | .child( | 5149 | .child( |
| 5050 | self.notice | 5150 | self.notice |
| 5051 | .clone() | 5151 | .clone() |
| 5052 | - .unwrap_or_else(|| "click a row, then press a key".into()), | 5152 | + .unwrap_or_else(|| { |
| 5153 | + "click an action to do it · click its key to change it" | ||
| 5154 | + .into() | ||
| 5155 | + }), | ||
| 5053 | ), | 5156 | ), |
| 5054 | ) | 5157 | ) |
| 5055 | // Capped and scrolling rather than as tall as the action | 5158 | // Capped and scrolling rather than as tall as the action |
| @@ -6725,7 +6828,6 @@ impl Player { | |||
| 6725 | let menu = self.context_menu?; | 6828 | let menu = self.context_menu?; |
| 6726 | let session = self.session.as_ref()?; | 6829 | let session = self.session.as_ref()?; |
| 6727 | let clip = *session.lane_clips(menu.lane).get(menu.idx)?; | 6830 | let clip = *session.lane_clips(menu.lane).get(menu.idx)?; |
| 6728 | - let playhead = frame_at(session.now(), self.fps); | ||
| 6729 | let source = session.sources().get(clip.source).cloned()?; | 6831 | let source = session.sources().get(clip.source).cloned()?; |
| 6730 | let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); | 6832 | let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); |
| 6731 | let row = |n: usize| { | 6833 | let row = |n: usize| { |
| @@ -6779,7 +6881,11 @@ impl Player { | |||
| 6779 | } | 6881 | } |
| 6780 | } else { | 6882 | } else { |
| 6781 | for action in MENU_ITEMS { | 6883 | for action in MENU_ITEMS { |
| 6782 | - let enabled = applicable(&clip, menu.lane, action, playhead); | 6884 | + // The registry's own answer, the same one the actions card |
| 6885 | + // dims a row with -- and a row that takes no click says *why* | ||
| 6886 | + // rather than printing a stroke that would do nothing. | ||
| 6887 | + let refusal = self.enable(action, Some((menu.lane, menu.idx))); | ||
| 6888 | + let enabled = refusal.yes(); | ||
| 6783 | // The one item that is not about this clip says so, and says it | 6889 | // The one item that is not about this clip says so, and says it |
| 6784 | // here rather than in the registry: the stroke is global too, | 6890 | // here rather than in the registry: the stroke is global too, |
| 6785 | // but its row in the keys menu is not sitting on a clip. | 6891 | // but its row in the keys menu is not sitting on a clip. |
| @@ -6791,11 +6897,20 @@ impl Player { | |||
| 6791 | rows.push( | 6897 | rows.push( |
| 6792 | row(rows.len()) | 6898 | row(rows.len()) |
| 6793 | .child(label) | 6899 | .child(label) |
| 6794 | - .child( | 6900 | + .child(match refusal.why() { |
| 6795 | - div() | 6901 | + // One truncated line, like the details side: a |
| 6902 | + // reason that wrapped would make the card taller | ||
| 6903 | + // than the height `menu_at` placed it by. | ||
| 6904 | + Some(why) => div() | ||
| 6905 | + .min_w(px(0.)) | ||
| 6906 | + .truncate() | ||
| 6907 | + .text_size(px(11.)) | ||
| 6908 | + .text_color(rgb(INK_DIM)) | ||
| 6909 | + .child(why), | ||
| 6910 | + None => div() | ||
| 6796 | .text_color(rgb(INK_DIM)) | 6911 | .text_color(rgb(INK_DIM)) |
| 6797 | .child(self.keymap.display(action)), | 6912 | .child(self.keymap.display(action)), |
| 6798 | - ) | 6913 | + }) |
| 6799 | .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | 6914 | .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) |
| 6800 | .when(enabled, |d| { | 6915 | .when(enabled, |d| { |
| 6801 | d.cursor_pointer() | 6916 | d.cursor_pointer() |
| @@ -7604,42 +7719,132 @@ fn band_label(band: &Band) -> String { | |||
| 7604 | } | 7719 | } |
| 7605 | } | 7720 | } |
| 7606 | 7721 | ||
| 7607 | -/// Whether the clip menu offers `action` on the clip it was opened on. Two of | 7722 | +/// Whether an action can be asked for, and what to say when it cannot. Two |
| 7608 | -/// the items act on the *playhead* rather than on the clip, so a menu opened | 7723 | +/// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at |
| 7609 | -/// away from it dims them instead of looking broken when they are clicked, and | 7724 | +/// -- an audio clip has no picture, so a grade is not a thing that exists for |
| 7610 | -/// one acts on sound, which only an audio lane's clip has. | 7725 | +/// it, whatever the editor does next -- and `No` is about the state of this |
| 7611 | -fn applicable(clip: &Clip, lane: Lane, action: ActionId, playhead: u32) -> bool { | 7726 | +/// moment, which the next click of the playhead can change. Both dim their row |
| 7612 | - match action { | 7727 | +/// today; a menu that wants to leave the class refusals out and keep the state |
| 7613 | - // The equalizer filters samples, and a video clip has none of its own | 7728 | +/// ones has only to match on which of the two it got. |
| 7614 | - // here: the sound is the audio lane's, clip for clip. | 7729 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 7615 | - ActionId::Equalizer => lane.kind == LaneKind::Audio, | 7730 | +enum Enable { |
| 7616 | - // A grade is a picture setting and an audio clip has no picture: the | 7731 | + Yes, |
| 7617 | - // item is there on every clip, and dimmed where it would mean nothing. | 7732 | + No(&'static str), |
| 7618 | - // A fit policy is a picture setting for the same reason. | 7733 | + Hidden(&'static str), |
| 7619 | - ActionId::Color | ActionId::Fit => lane.kind == LaneKind::Video, | 7734 | +} |
| 7620 | - // Splits this clip only from inside it: at either edge there is nothing | 7735 | + |
| 7621 | - // to split off -- and, on a speeded clip, only at a frame its own rate | 7736 | +impl Enable { |
| 7622 | - // can address, which is the same question `splittable` asks. | 7737 | + /// Whether the row takes a click. |
| 7623 | - ActionId::Cut => { | 7738 | + fn yes(self) -> bool { |
| 7624 | - clip.start < playhead | 7739 | + self == Enable::Yes |
| 7625 | - && playhead < clip.end() | 7740 | + } |
| 7626 | - && clip | 7741 | + |
| 7627 | - .speed | 7742 | + /// What the row says instead of its stroke, if it says anything. |
| 7628 | - .split_at(clip.len(), playhead - clip.start) | 7743 | + fn why(self) -> Option<&'static str> { |
| 7629 | - .is_some() | 7744 | + match self { |
| 7745 | + Enable::Yes => None, | ||
| 7746 | + Enable::No(why) | Enable::Hidden(why) => Some(why), | ||
| 7630 | } | 7747 | } |
| 7631 | - // A rate applies to a clip of either kind and to its whole group, so | 7748 | + } |
| 7632 | - // there is no lane it means nothing on -- `_ => true` below is its | 7749 | +} |
| 7633 | - // answer, and the engine words the one refusal there is (no room). | 7750 | + |
| 7751 | +/// What an enablement question is asked *about*: the clip in question, if there | ||
| 7752 | +/// is one, and the little of the editor's state the answers need. Handed in | ||
| 7753 | +/// rather than read off the player, so [`enable`] is a pure function a test can | ||
| 7754 | +/// ask about a clip without building a window. | ||
| 7755 | +#[derive(Clone, Copy, Default)] | ||
| 7756 | +struct Ctx { | ||
| 7757 | + /// The clip the question is about -- the one a menu was opened on, or the | ||
| 7758 | + /// marked one. `None` means the question is about the editor as a whole, | ||
| 7759 | + /// and the clip-relative answers stand aside: those actions find their own | ||
| 7760 | + /// clip under the playhead and word their own refusal. | ||
| 7761 | + clip: Option<(Clip, Lane)>, | ||
| 7762 | + playhead: u32, | ||
| 7763 | + /// A timeline is open. | ||
| 7764 | + timeline: bool, | ||
| 7765 | + /// Something has been copied. | ||
| 7766 | + clipboard: bool, | ||
| 7767 | + exporting: bool, | ||
| 7768 | +} | ||
| 7769 | + | ||
| 7770 | +/// Whether `action` can be asked for, on `ctx`. One arm per action and nothing | ||
| 7771 | +/// else in the editor asks the question: the clip menu dims a row with this, | ||
| 7772 | +/// the actions card dims a row with this, and the two can never come to | ||
| 7773 | +/// disagree about what an action needs -- exactly the reason [`Player::act`] is | ||
| 7774 | +/// one table too. | ||
| 7775 | +fn enable(action: ActionId, ctx: Ctx) -> Enable { | ||
| 7776 | + if !ctx.timeline { | ||
| 7777 | + return Enable::No("no timeline open"); | ||
| 7778 | + } | ||
| 7779 | + // An export is reading the edit list every other action would change, which | ||
| 7780 | + // is the rule the key handler already follows. | ||
| 7781 | + if ctx.exporting { | ||
| 7782 | + return match action { | ||
| 7783 | + ActionId::CancelExport => Enable::Yes, | ||
| 7784 | + _ => Enable::No("an export is running"), | ||
| 7785 | + }; | ||
| 7786 | + } | ||
| 7787 | + match action { | ||
| 7788 | + // -- class: what kind of thing the action is about. The equalizer | ||
| 7789 | + // filters samples, and a video clip has none of its own here: the sound | ||
| 7790 | + // is the audio lane's, clip for clip. | ||
| 7791 | + ActionId::Equalizer => match ctx.clip { | ||
| 7792 | + Some((_, lane)) if lane.kind != LaneKind::Audio => Enable::Hidden("this clip is picture"), | ||
| 7793 | + _ => Enable::Yes, | ||
| 7794 | + }, | ||
| 7795 | + // A grade is a picture setting and an audio clip has no picture. A fit | ||
| 7796 | + // policy is a picture setting for the same reason. | ||
| 7797 | + ActionId::Color | ActionId::Fit => match ctx.clip { | ||
| 7798 | + Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), | ||
| 7799 | + _ => Enable::Yes, | ||
| 7800 | + }, | ||
| 7801 | + // -- state: true of this clip now, and the next playhead click or the | ||
| 7802 | + // next selection changes the answer. Splits this clip only from inside | ||
| 7803 | + // it: at either edge there is nothing to split off -- and, on a speeded | ||
| 7804 | + // clip, only at a frame its own rate can address, which is the same | ||
| 7805 | + // question `splittable` asks. | ||
| 7806 | + ActionId::Cut => match ctx.clip { | ||
| 7807 | + Some((clip, _)) | ||
| 7808 | + if !(clip.start < ctx.playhead | ||
| 7809 | + && ctx.playhead < clip.end() | ||
| 7810 | + && clip | ||
| 7811 | + .speed | ||
| 7812 | + .split_at(clip.len(), ctx.playhead - clip.start) | ||
| 7813 | + .is_some()) => | ||
| 7814 | + { | ||
| 7815 | + Enable::No("only from inside a clip") | ||
| 7816 | + } | ||
| 7817 | + _ => Enable::Yes, | ||
| 7818 | + }, | ||
| 7634 | // Rejoins whatever meets at the playhead, so it can mean something only | 7819 | // Rejoins whatever meets at the playhead, so it can mean something only |
| 7635 | // at an edge of this clip. Whether those two halves were ever one take | 7820 | // at an edge of this clip. Whether those two halves were ever one take |
| 7636 | // is the engine's question, and it words that refusal itself. | 7821 | // is the engine's question, and it words that refusal itself. |
| 7637 | - ActionId::Regroup => playhead == clip.start || playhead == clip.end(), | 7822 | + ActionId::Regroup => match ctx.clip { |
| 7823 | + Some((clip, _)) if ctx.playhead != clip.start && ctx.playhead != clip.end() => { | ||
| 7824 | + Enable::No("only where two clips meet") | ||
| 7825 | + } | ||
| 7826 | + _ => Enable::Yes, | ||
| 7827 | + }, | ||
| 7638 | // Nothing to take apart in a clip that names no group at all. Whether | 7828 | // Nothing to take apart in a clip that names no group at all. Whether |
| 7639 | // the group it names still has another half is the engine's question, | 7829 | // the group it names still has another half is the engine's question, |
| 7640 | - // like the regroup above, and it words that refusal itself. | 7830 | + // like the regroup above. |
| 7641 | - ActionId::Detach => clip.link.is_some(), | 7831 | + ActionId::Detach => match ctx.clip { |
| 7642 | - _ => true, | 7832 | + Some((clip, _)) if clip.link.is_none() => Enable::No("this clip is not grouped"), |
| 7833 | + _ => Enable::Yes, | ||
| 7834 | + }, | ||
| 7835 | + // The three that act on the marked clip and on nothing else: with none | ||
| 7836 | + // marked they would silently do nothing, which is what the Delete | ||
| 7837 | + // button's own dimming has always said. | ||
| 7838 | + ActionId::Copy | ActionId::Delete | ActionId::Lift if ctx.clip.is_none() => { | ||
| 7839 | + Enable::No("click a clip first") | ||
| 7840 | + } | ||
| 7841 | + ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"), | ||
| 7842 | + ActionId::CancelExport => Enable::No("nothing is exporting"), | ||
| 7843 | + // A rate applies to a clip of either kind and to its whole group, so | ||
| 7844 | + // there is no lane it means nothing on, and the engine words the one | ||
| 7845 | + // refusal there is (no room). Everything else is the editor's own and | ||
| 7846 | + // needs nothing but a timeline. | ||
| 7847 | + _ => Enable::Yes, | ||
| 7643 | } | 7848 | } |
| 7644 | } | 7849 | } |
| 7645 | 7850 | ||
| @@ -9367,25 +9572,25 @@ fn timecode(t: f64, fps: f64) -> String { | |||
| 9367 | #[cfg(test)] | 9572 | #[cfg(test)] |
| 9368 | mod tests { | 9573 | mod tests { |
| 9369 | use super::{ | 9574 | use super::{ |
| 9370 | - ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | 9575 | + ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, EQ_BANDS_MAX, |
| 9371 | - EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | 9576 | + EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, |
| 9372 | - EQ_BANDS_MAX, EQ_FREQ_STEP, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_TICKS, EQ_W_MAX, ESCAPE, | 9577 | + EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, |
| 9373 | - EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, | 9578 | + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, FORMATS, |
| 9374 | - HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, | 9579 | + Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, |
| 9375 | - KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, | 9580 | + INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, |
| 9376 | - LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, | 9581 | + LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, |
| 9377 | - PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, | 9582 | + MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, |
| 9378 | - SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Transport, VOLUME_W, Volume, | 9583 | + SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, |
| 9379 | - WAVE_BPS, WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, | 9584 | + Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, band_label, bitrate_refusal, |
| 9380 | - clipboard_after_remove, color_snap, containers, envelope, eq_card_w, eq_freq, eq_freq_label, | 9585 | + can_add, cancels_export, clipboard_after_remove, color_snap, containers, enable, envelope, |
| 9381 | - eq_spectrum, eq_x, eq_y, | 9586 | + eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, estimated_mb, export_path, |
| 9382 | - estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, | 9587 | + export_settings, format_key, |
| 9383 | - fps_label, frac_along, frac_down, frame_at, histogram, inserted_band, is_bare_modifier, | 9588 | + format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, |
| 9384 | - is_project, | 9589 | + inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, |
| 9385 | - keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, | 9590 | + next_container, |
| 9386 | - project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, | 9591 | + normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, |
| 9387 | - source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, | 9592 | + show_label, silence_rate, snapped, source_tint, span_partner, speed_at, summary_head, |
| 9388 | - unseen_paths, unseen_sources, whole_take, window_title, | 9593 | + summary_tail, timecode, transport, unseen_paths, unseen_sources, whole_take, window_title, |
| 9389 | }; | 9594 | }; |
| 9390 | use super::{ | 9595 | use super::{ |
| 9391 | LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, | 9596 | LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, |
| @@ -9701,43 +9906,126 @@ mod tests { | |||
| 9701 | speed: Speed::NORMAL, | 9906 | speed: Speed::NORMAL, |
| 9702 | }; | 9907 | }; |
| 9703 | assert_eq!(clip.end(), 90); | 9908 | assert_eq!(clip.end(), 90); |
| 9704 | - // Cut splits from inside only: neither edge has anything to split off. | ||
| 9705 | let a1 = Lane::A1; | 9909 | let a1 = Lane::A1; |
| 9706 | let v1 = Lane::V1; | 9910 | let v1 = Lane::V1; |
| 9707 | - assert!(applicable(&clip, v1, ActionId::Cut, 31)); | 9911 | + // The question the clip menu asks: a timeline is open and the menu was |
| 9708 | - assert!(applicable(&clip, v1, ActionId::Cut, 89)); | 9912 | + // opened on this clip, at this playhead. |
| 9709 | - assert!(!applicable(&clip, v1, ActionId::Cut, 30)); | 9913 | + let on = |clip: &Clip, lane, action, playhead| { |
| 9710 | - assert!(!applicable(&clip, v1, ActionId::Cut, 90)); | 9914 | + enable( |
| 9711 | - assert!(!applicable(&clip, v1, ActionId::Cut, 200)); | 9915 | + action, |
| 9916 | + Ctx { | ||
| 9917 | + clip: Some((*clip, lane)), | ||
| 9918 | + playhead, | ||
| 9919 | + timeline: true, | ||
| 9920 | + ..Ctx::default() | ||
| 9921 | + }, | ||
| 9922 | + ) | ||
| 9923 | + }; | ||
| 9924 | + let offered = |clip: &Clip, lane, action, playhead| on(clip, lane, action, playhead).yes(); | ||
| 9925 | + // Cut splits from inside only: neither edge has anything to split off. | ||
| 9926 | + assert!(offered(&clip, v1, ActionId::Cut, 31)); | ||
| 9927 | + assert!(offered(&clip, v1, ActionId::Cut, 89)); | ||
| 9928 | + assert!(!offered(&clip, v1, ActionId::Cut, 30)); | ||
| 9929 | + assert!(!offered(&clip, v1, ActionId::Cut, 90)); | ||
| 9930 | + assert!(!offered(&clip, v1, ActionId::Cut, 200)); | ||
| 9712 | // Regroup is the other way round: only where this clip meets another. | 9931 | // Regroup is the other way round: only where this clip meets another. |
| 9713 | - assert!(applicable(&clip, v1, ActionId::Regroup, 30)); | 9932 | + assert!(offered(&clip, v1, ActionId::Regroup, 30)); |
| 9714 | - assert!(applicable(&clip, v1, ActionId::Regroup, 90)); | 9933 | + assert!(offered(&clip, v1, ActionId::Regroup, 90)); |
| 9715 | - assert!(!applicable(&clip, v1, ActionId::Regroup, 60)); | 9934 | + assert!(!offered(&clip, v1, ActionId::Regroup, 60)); |
| 9716 | // Detach is the clip's own business: nothing to take apart in one that | 9935 | // Detach is the clip's own business: nothing to take apart in one that |
| 9717 | // names no group, and whether the group still has another half is the | 9936 | // names no group, and whether the group still has another half is the |
| 9718 | // engine's question. Group is offered on every clip, for that reason. | 9937 | // engine's question. Group is offered on every clip, for that reason. |
| 9719 | - assert!(!applicable(&clip, v1, ActionId::Detach, 0)); | 9938 | + assert!(!offered(&clip, v1, ActionId::Detach, 0)); |
| 9720 | let grouped = Clip { | 9939 | let grouped = Clip { |
| 9721 | link: Some(3), | 9940 | link: Some(3), |
| 9722 | ..clip | 9941 | ..clip |
| 9723 | }; | 9942 | }; |
| 9724 | - assert!(applicable(&grouped, v1, ActionId::Detach, 60)); | 9943 | + assert!(offered(&grouped, v1, ActionId::Detach, 60)); |
| 9725 | - assert!(applicable(&clip, a1, ActionId::Group, 0)); | 9944 | + assert!(offered(&clip, a1, ActionId::Group, 0)); |
| 9726 | // The equalizer is the one item the *lane* decides: it filters samples, | 9945 | // The equalizer is the one item the *lane* decides: it filters samples, |
| 9727 | // and a video clip has none of its own. Never the playhead's business. | 9946 | // and a video clip has none of its own. Never the playhead's business. |
| 9728 | - assert!(applicable(&clip, a1, ActionId::Equalizer, 0)); | 9947 | + assert!(offered(&clip, a1, ActionId::Equalizer, 0)); |
| 9729 | - assert!(applicable(&clip, a1, ActionId::Equalizer, 60)); | 9948 | + assert!(offered(&clip, a1, ActionId::Equalizer, 60)); |
| 9730 | - assert!(!applicable(&clip, v1, ActionId::Equalizer, 60)); | 9949 | + assert!(!offered(&clip, v1, ActionId::Equalizer, 60)); |
| 9731 | // The rest act on the clip that was clicked, so they always mean | 9950 | // The rest act on the clip that was clicked, so they always mean |
| 9732 | // something -- the engine words its own refusals. | 9951 | // something -- the engine words its own refusals. |
| 9733 | for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] { | 9952 | for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] { |
| 9734 | - assert!(applicable(&clip, v1, action, 0)); | 9953 | + assert!(offered(&clip, v1, action, 0)); |
| 9735 | - assert!(applicable(&clip, a1, action, 60)); | 9954 | + assert!(offered(&clip, a1, action, 60)); |
| 9736 | } | 9955 | } |
| 9737 | // Except the grade, which is a picture setting: offered on a video | 9956 | // Except the grade, which is a picture setting: offered on a video |
| 9738 | // clip wherever the playhead is, dimmed on a waveform. | 9957 | // clip wherever the playhead is, dimmed on a waveform. |
| 9739 | - assert!(applicable(&clip, v1, ActionId::Color, 0)); | 9958 | + assert!(offered(&clip, v1, ActionId::Color, 0)); |
| 9740 | - assert!(!applicable(&clip, a1, ActionId::Color, 60)); | 9959 | + assert!(!offered(&clip, a1, ActionId::Color, 60)); |
| 9960 | + // The two kinds of no, which is what the row can be told apart by: a | ||
| 9961 | + // grade on a waveform is a *class* answer -- an audio clip has no | ||
| 9962 | + // picture and never will, so a menu may leave the item out -- where a | ||
| 9963 | + // cut at the clip's edge is this moment's answer and the next click of | ||
| 9964 | + // the playhead changes it, so that one is dimmed and stays. | ||
| 9965 | + assert!(matches!( | ||
| 9966 | + on(&clip, a1, ActionId::Color, 60), | ||
| 9967 | + Enable::Hidden(_) | ||
| 9968 | + )); | ||
| 9969 | + assert!(matches!( | ||
| 9970 | + on(&clip, a1, ActionId::Fit, 60), | ||
| 9971 | + Enable::Hidden(_) | ||
| 9972 | + )); | ||
| 9973 | + assert!(matches!( | ||
| 9974 | + on(&clip, v1, ActionId::Equalizer, 60), | ||
| 9975 | + Enable::Hidden(_) | ||
| 9976 | + )); | ||
| 9977 | + assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); | ||
| 9978 | + assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); | ||
| 9979 | + assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); | ||
| 9980 | + // Every refusal says something, and says it short enough to sit in the | ||
| 9981 | + // menu's right-hand column beside a label. | ||
| 9982 | + for action in MENU_ITEMS { | ||
| 9983 | + for lane in [v1, a1] { | ||
| 9984 | + for playhead in [0, 30, 60, 90] { | ||
| 9985 | + if let Some(why) = on(&clip, lane, action, playhead).why() { | ||
| 9986 | + assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); | ||
| 9987 | + } | ||
| 9988 | + } | ||
| 9989 | + } | ||
| 9990 | + } | ||
| 9991 | + // The editor as a whole, which is how the actions card asks: with no | ||
| 9992 | + // timeline nothing is offered, an export leaves only its own cancel, | ||
| 9993 | + // and the three that act on the marked clip say so when none is. | ||
| 9994 | + let whole = |action, ctx| enable(action, ctx); | ||
| 9995 | + assert_eq!( | ||
| 9996 | + whole(ActionId::Play, Ctx::default()), | ||
| 9997 | + Enable::No("no timeline open") | ||
| 9998 | + ); | ||
| 9999 | + let live = Ctx { | ||
| 10000 | + timeline: true, | ||
| 10001 | + ..Ctx::default() | ||
| 10002 | + }; | ||
| 10003 | + assert!(whole(ActionId::Play, live).yes()); | ||
| 10004 | + assert!(!whole(ActionId::Delete, live).yes()); | ||
| 10005 | + assert!(!whole(ActionId::Paste, live).yes()); | ||
| 10006 | + assert!( | ||
| 10007 | + whole( | ||
| 10008 | + ActionId::Paste, | ||
| 10009 | + Ctx { | ||
| 10010 | + clipboard: true, | ||
| 10011 | + ..live | ||
| 10012 | + } | ||
| 10013 | + ) | ||
| 10014 | + .yes() | ||
| 10015 | + ); | ||
| 10016 | + assert!(!whole(ActionId::CancelExport, live).yes()); | ||
| 10017 | + let busy = Ctx { | ||
| 10018 | + exporting: true, | ||
| 10019 | + ..live | ||
| 10020 | + }; | ||
| 10021 | + assert!(whole(ActionId::CancelExport, busy).yes()); | ||
| 10022 | + for action in ActionId::ALL { | ||
| 10023 | + assert_eq!( | ||
| 10024 | + whole(action, busy).yes(), | ||
| 10025 | + action == ActionId::CancelExport, | ||
| 10026 | + "{action:?} while an export reads the edit list" | ||
| 10027 | + ); | ||
| 10028 | + } | ||
| 9741 | // The playhead frame is the engine's own rule, boundary included. | 10029 | // The playhead frame is the engine's own rule, boundary included. |
| 9742 | assert_eq!(frame_at(1.0, 30.), 30); | 10030 | assert_eq!(frame_at(1.0, 30.), 30); |
| 9743 | assert_eq!(frame_at(0.0, 30.), 0); | 10031 | assert_eq!(frame_at(0.0, 30.), 0); |
| @@ -9780,9 +10068,9 @@ mod tests { | |||
| 9780 | 10068 | ||
| 9781 | /// The other half of the keys menu's guarantee, and the audit this batch was | 10069 | /// The other half of the keys menu's guarantee, and the audit this batch was |
| 9782 | /// asked for kept as a test: no action may be a stroke and nothing else. | 10070 | /// asked for kept as a test: no action may be a stroke and nothing else. |
| 9783 | - /// Either the clip menu offers it, or a control in the panel does -- named | 10071 | + /// The actions card answers it for all of them at once -- its rows come off |
| 9784 | - /// here by the id [`control`] is handed, read out of this file's own source | 10072 | + /// [`ActionId::ALL`], so a fortieth action is on it the moment it exists and |
| 9785 | - /// like `no_stroke_is_missing_from_the_keys_menu` reads the key handler. | 10073 | + /// there is no hand-written list here to fall behind. |
| 9786 | #[test] | 10074 | #[test] |
| 9787 | fn every_action_is_reachable_without_the_keyboard() { | 10075 | fn every_action_is_reachable_without_the_keyboard() { |
| 9788 | use keymap::ActionId; | 10076 | use keymap::ActionId; |
| @@ -9791,48 +10079,22 @@ mod tests { | |||
| 9791 | .next() | 10079 | .next() |
| 9792 | .unwrap(); | 10080 | .unwrap(); |
| 9793 | let element = |id: &str| source.contains(&format!("\"{id}\"")); | 10081 | let element = |id: &str| source.contains(&format!("\"{id}\"")); |
| 10082 | + let listed: Vec<ActionId> = keys_rows() | ||
| 10083 | + .iter() | ||
| 10084 | + .filter_map(|r| match r { | ||
| 10085 | + KeyRow::Act(a) => Some(*a), | ||
| 10086 | + _ => None, | ||
| 10087 | + }) | ||
| 10088 | + .collect(); | ||
| 9794 | for action in ActionId::ALL { | 10089 | for action in ActionId::ALL { |
| 9795 | - let by_pointer = MENU_ITEMS.contains(&action) | 10090 | + assert_eq!( |
| 9796 | - || match action { | 10091 | + listed.iter().filter(|a| **a == action).count(), |
| 9797 | - ActionId::Play => element("transport"), | 10092 | + 1, |
| 9798 | - // One slot, two states: it starts an export and stops the | 10093 | + "{action:?} is reachable by keyboard only" |
| 9799 | - // one it started. | 10094 | + ); |
| 9800 | - ActionId::Export | ActionId::CancelExport => element("export"), | ||
| 9801 | - ActionId::Save => element("save"), | ||
| 9802 | - ActionId::Undo => element("undo"), | ||
| 9803 | - ActionId::Resolution => element("resolution"), | ||
| 9804 | - // Three buttons beside it, and the ctrl+wheel on the bar. | ||
| 9805 | - ActionId::ZoomIn => element("zoom-in"), | ||
| 9806 | - ActionId::ZoomOut => element("zoom-out"), | ||
| 9807 | - ActionId::ZoomFit => element("zoom-fit"), | ||
| 9808 | - ActionId::AddVideoLane => element("add-video-lane"), | ||
| 9809 | - ActionId::AddAudioLane => element("add-audio-lane"), | ||
| 9810 | - // The × in a lane's own header, which takes any track and | ||
| 9811 | - // not only the last one. | ||
| 9812 | - ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => { | ||
| 9813 | - source.contains("this.remove_lane(lane, cx)") | ||
| 9814 | - } | ||
| 9815 | - ActionId::ToggleMute => element("volume"), | ||
| 9816 | - // The fader on every audio track's own header, which is | ||
| 9817 | - // also what opens the card the limiter is on. | ||
| 9818 | - ActionId::Mix => element("mix-lane"), | ||
| 9819 | - ActionId::VolumeUp | ActionId::VolumeDown => element("volume-bar"), | ||
| 9820 | - // The ruler seeks anywhere the pointer points; the frame and | ||
| 9821 | - // the second are the keyboard's finer grain of that move. | ||
| 9822 | - ActionId::StepBack | ||
| 9823 | - | ActionId::StepForward | ||
| 9824 | - | ActionId::JumpBack | ||
| 9825 | - | ActionId::JumpForward | ||
| 9826 | - | ActionId::GoStart | ||
| 9827 | - | ActionId::GoEnd => element("ruler"), | ||
| 9828 | - // A press on a clip is the selection, group and all. | ||
| 9829 | - ActionId::Select | ActionId::SelectNext | ActionId::SelectPrev => { | ||
| 9830 | - source.contains("this.select((lane, i), cx)") | ||
| 9831 | - } | ||
| 9832 | - _ => false, | ||
| 9833 | - }; | ||
| 9834 | - assert!(by_pointer, "{action:?} is reachable by keyboard only"); | ||
| 9835 | } | 10095 | } |
| 10096 | + // And the card is a door the pointer can open: the panel's own button. | ||
| 10097 | + assert!(element("keys"), "no way to open the actions card"); | ||
| 9836 | // The card-local strokes have the same rule, and each of them is a thing | 10098 | // The card-local strokes have the same rule, and each of them is a thing |
| 9837 | // on its card: the graph and its two buttons, the colour bars and their | 10099 | // on its card: the graph and its two buttons, the colour bars and their |
| 9838 | // reset, the speed bar and its presets, and the silence card's rows -- | 10100 | // reset, the speed bar and its presets, and the silence card's rows -- |
| @@ -10937,6 +11199,65 @@ mod tests { | |||
| 10937 | } | 11199 | } |
| 10938 | } | 11200 | } |
| 10939 | 11201 | ||
| 11202 | + /// The whole point of the card: there is no action a pointer cannot reach. | ||
| 11203 | + /// It renders [`keys_rows`] and nothing else, so this reads the same list | ||
| 11204 | + /// the card does -- add an `ActionId` and forget to surface it and this | ||
| 11205 | + /// fails, which is the only way that stays true as the editor grows. | ||
| 11206 | + #[test] | ||
| 11207 | + fn every_action_is_on_the_actions_card() { | ||
| 11208 | + use keymap::{ActionId, Category, Keymap}; | ||
| 11209 | + let rows = keys_rows(); | ||
| 11210 | + let listed: Vec<ActionId> = rows | ||
| 11211 | + .iter() | ||
| 11212 | + .filter_map(|r| match r { | ||
| 11213 | + KeyRow::Act(a) => Some(*a), | ||
| 11214 | + _ => None, | ||
| 11215 | + }) | ||
| 11216 | + .collect(); | ||
| 11217 | + for action in ActionId::ALL { | ||
| 11218 | + assert_eq!( | ||
| 11219 | + listed.iter().filter(|a| **a == action).count(), | ||
| 11220 | + 1, | ||
| 11221 | + "{action:?} is not on the card exactly once" | ||
| 11222 | + ); | ||
| 11223 | + } | ||
| 11224 | + assert_eq!(listed.len(), ActionId::ALL.len()); | ||
| 11225 | + // Under its own heading, in the registry's order: every row after a | ||
| 11226 | + // heading belongs to that heading until the next one. | ||
| 11227 | + let mut heading = None; | ||
| 11228 | + let mut heads = 0; | ||
| 11229 | + for row in &rows { | ||
| 11230 | + match row { | ||
| 11231 | + KeyRow::Head(category) => { | ||
| 11232 | + heading = Some(*category); | ||
| 11233 | + heads += 1; | ||
| 11234 | + } | ||
| 11235 | + KeyRow::Act(action) => assert_eq!(Some(action.category()), heading, "{action:?}"), | ||
| 11236 | + KeyRow::Fixed(i) => assert_eq!(Some(keymap::FIXED[*i].category), heading), | ||
| 11237 | + } | ||
| 11238 | + } | ||
| 11239 | + assert_eq!(heads, Category::ALL.len(), "a heading per category"); | ||
| 11240 | + // The card-local strokes are still all there beside them. | ||
| 11241 | + assert_eq!( | ||
| 11242 | + rows.iter() | ||
| 11243 | + .filter(|r| matches!(r, KeyRow::Fixed(_))) | ||
| 11244 | + .count(), | ||
| 11245 | + keymap::FIXED.len() | ||
| 11246 | + ); | ||
| 11247 | + // Both columns say something: the label does the action, the stroke | ||
| 11248 | + // beside it changes that stroke, and neither may read blank. | ||
| 11249 | + let keymap = Keymap::defaults(); | ||
| 11250 | + for action in ActionId::ALL { | ||
| 11251 | + assert!(!action.label().is_empty(), "{action:?}"); | ||
| 11252 | + assert_ne!(keymap.display(action), "unbound", "{action:?}"); | ||
| 11253 | + } | ||
| 11254 | + // The list scrolls inside a card the smallest window holds, so a | ||
| 11255 | + // thirty-fourth action costs no height at all. | ||
| 11256 | + assert!(rows.len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, "no cap needed?"); | ||
| 11257 | + // Both halves of a row are click targets, so WCAG 2.5.8 binds them. | ||
| 11258 | + assert!(KEYS_ROW_H >= HIT_MIN); | ||
| 11259 | + } | ||
| 11260 | + | ||
| 10940 | #[test] | 11261 | #[test] |
| 10941 | fn the_keybindings_card_fits_the_smallest_window() { | 11262 | fn the_keybindings_card_fits_the_smallest_window() { |
| 10942 | // The row list is capped and scrolls, so the card's height no longer | 11263 | // The row list is capped and scrolls, so the card's height no longer |