🔀 merge(C1): every action has a pointer door — one enablement table, an actions card, reasons instead of dead chords
Browse files at this commit1 changed file +509 -188
- crates/app/src/main.rs +509 -188
crates/app/src/main.rsmodified+509 -188
| @@ -406,6 +406,47 @@ const MENU_ITEMS: [ActionId; 14] = [ | ||
| 406 | 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 | 450 | /// The project resolutions [`Player::cycle_resolution`] offers, largest first. |
| 410 | 451 | /// A short list of the sizes people name; the media's own is cycled in beside |
| 411 | 452 | /// them, which is what makes the trip round come back to where it started. |
| @@ -1098,6 +1139,31 @@ impl Player { | ||
| 1098 | 1139 | } |
| 1099 | 1140 | } |
| 1100 | 1141 | |
| 1142 | + /// Whether the editor can be asked for `action` right now, and why not when | |
| 1143 | + /// it cannot. `on` is the clip the question is about -- the one a clip menu | |
| 1144 | + /// was opened on -- and `None` asks about the marked clip instead, which is | |
| 1145 | + /// what a menu that hangs over no clip in particular means by "this one". | |
| 1146 | + /// | |
| 1147 | + /// The player's half of [`enable`]: it reads the state, the table decides. | |
| 1148 | + fn enable(&self, action: ActionId, on: Option<(Lane, usize)>) -> Enable { | |
| 1149 | + let Some(session) = &self.session else { | |
| 1150 | + return enable(action, Ctx::default()); | |
| 1151 | + }; | |
| 1152 | + let clip = on | |
| 1153 | + .or(self.selected) | |
| 1154 | + .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane))); | |
| 1155 | + enable( | |
| 1156 | + action, | |
| 1157 | + Ctx { | |
| 1158 | + clip, | |
| 1159 | + playhead: frame_at(session.now(), self.fps), | |
| 1160 | + timeline: true, | |
| 1161 | + clipboard: self.clipboard.is_some(), | |
| 1162 | + exporting: self.exporting().is_some(), | |
| 1163 | + }, | |
| 1164 | + ) | |
| 1165 | + } | |
| 1166 | + | |
| 1101 | 1167 | /// The one place a clip becomes *the* selected one: a click, a right-click |
| 1102 | 1168 | /// that opens the menu, and every selection key go through here, so what a |
| 1103 | 1169 | /// keyboard marks and what a pointer marks are the same state marked the |
| @@ -4621,8 +4687,10 @@ impl Player { | ||
| 4621 | 4687 | .child(control( |
| 4622 | 4688 | "keys", |
| 4623 | 4689 | None, |
| 4624 | - "Keys", | |
| 4625 | - "show and change the keybindings".to_string(), | |
| 4690 | + "Actions", | |
| 4691 | + // The pointer's way to every action there is, including | |
| 4692 | + // the ones no button here has room for. | |
| 4693 | + "do any action, or change the key that does it".to_string(), | |
| 4626 | 4694 | !exporting, |
| 4627 | 4695 | cx.listener(|this, _: &ClickEvent, _, cx| { |
| 4628 | 4696 | this.keys_open = !this.keys_open; |
| @@ -4832,83 +4900,115 @@ impl Player { | ||
| 4832 | 4900 | ctrl: false, |
| 4833 | 4901 | } |
| 4834 | 4902 | .pretty(); |
| 4835 | - // Every stroke that works, under its heading, and both halves of the | |
| 4836 | - // list come from the registry: one row per action -- an action with two | |
| 4837 | - // strokes reads as one line ("x or delete") and a rebind replaces that | |
| 4838 | - // whole set -- then the strokes the modal cards answer to, which are | |
| 4839 | - // shown but not offered, because nothing may unbind the way out. | |
| 4903 | + // Every action there is, under its heading, and the strokes the modal | |
| 4904 | + // cards answer to beside them -- `keys_rows` is the whole of the order | |
| 4905 | + // and every word in it comes off the registry. | |
| 4906 | + // | |
| 4907 | + // A row is two targets, not one: its label *does* the action, which is | |
| 4908 | + // the pointer's way to the ones no button carries, and its stroke | |
| 4909 | + // changes that stroke. An action with two strokes reads as one line | |
| 4910 | + // ("x or delete") and a rebind replaces that whole set. | |
| 4840 | 4911 | let mut rows: Vec<AnyElement> = Vec::new(); |
| 4841 | - for category in keymap::Category::ALL { | |
| 4842 | - let actions = ActionId::ALL | |
| 4843 | - .into_iter() | |
| 4844 | - .enumerate() | |
| 4845 | - .filter(|(_, a)| a.category() == category); | |
| 4846 | - let fixed = keymap::FIXED.iter().filter(|f| f.category == category); | |
| 4847 | - let mut headed = false; | |
| 4848 | - let mut head = |rows: &mut Vec<AnyElement>| { | |
| 4849 | - if !std::mem::replace(&mut headed, true) { | |
| 4850 | - rows.push( | |
| 4851 | - div() | |
| 4852 | - .flex_none() | |
| 4853 | - .px(px(6.)) | |
| 4854 | - .pt(px(4.)) | |
| 4855 | - .text_size(px(11.)) | |
| 4856 | - .text_color(rgb(INK_DIM)) | |
| 4857 | - .child(category.label()) | |
| 4858 | - .into_any_element(), | |
| 4859 | - ); | |
| 4860 | - } | |
| 4861 | - }; | |
| 4862 | - for (i, action) in actions { | |
| 4863 | - head(&mut rows); | |
| 4864 | - let capturing = self.rebinding == Some(action); | |
| 4865 | - let out = out.clone(); | |
| 4866 | - rows.push( | |
| 4867 | - div() | |
| 4868 | - .id(("bind", i)) | |
| 4869 | - .flex() | |
| 4870 | - // The floor, not the height: a row that needed two lines | |
| 4871 | - // would otherwise paint over the one under it. | |
| 4872 | - .min_h(px(KEYS_ROW_H)) | |
| 4873 | - .items_center() | |
| 4874 | - .justify_between() | |
| 4875 | - .gap(px(12.)) | |
| 4876 | - .px(px(6.)) | |
| 4877 | - .rounded(px(3.)) | |
| 4878 | - .cursor_pointer() | |
| 4879 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 4912 | + let row = || { | |
| 4913 | + div() | |
| 4914 | + .flex() | |
| 4915 | + // The floor, not the height: a row that needed two lines | |
| 4916 | + // would otherwise paint over the one under it. | |
| 4917 | + .min_h(px(KEYS_ROW_H)) | |
| 4918 | + .items_center() | |
| 4919 | + .justify_between() | |
| 4920 | + .gap(px(12.)) | |
| 4921 | + .px(px(6.)) | |
| 4922 | + .rounded(px(3.)) | |
| 4923 | + }; | |
| 4924 | + for (i, key_row) in keys_rows().into_iter().enumerate() { | |
| 4925 | + rows.push(match key_row { | |
| 4926 | + KeyRow::Head(category) => div() | |
| 4927 | + .flex_none() | |
| 4928 | + .px(px(6.)) | |
| 4929 | + .pt(px(4.)) | |
| 4930 | + .text_size(px(11.)) | |
| 4931 | + .text_color(rgb(INK_DIM)) | |
| 4932 | + .child(category.label()) | |
| 4933 | + .into_any_element(), | |
| 4934 | + KeyRow::Act(action) => { | |
| 4935 | + let capturing = self.rebinding == Some(action); | |
| 4936 | + // Why the label half will not answer, if it will not: the | |
| 4937 | + // registry's one answer, the same the clip menu dims by. | |
| 4938 | + let refusal = self.enable(action, None); | |
| 4939 | + let out = out.clone(); | |
| 4940 | + row() | |
| 4880 | 4941 | .when(capturing, |d| d.bg(rgb(SELECTED))) |
| 4881 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 4882 | - this.rebinding = Some(action); | |
| 4883 | - cx.notify(); | |
| 4884 | - })) | |
| 4885 | - .child(action.label()) | |
| 4886 | - .child(if capturing { | |
| 4942 | + .child( | |
| 4887 | 4943 | div() |
| 4888 | - .text_color(rgb(INK_DIM)) | |
| 4889 | - .child(format!("press a key — {out} cancels")) | |
| 4890 | - } else { | |
| 4891 | - div().child(self.keymap.display(action)) | |
| 4892 | - }) | |
| 4893 | - .into_any_element(), | |
| 4894 | - ); | |
| 4895 | - } | |
| 4896 | - for f in fixed { | |
| 4897 | - head(&mut rows); | |
| 4898 | - rows.push( | |
| 4899 | - div() | |
| 4900 | - .flex() | |
| 4901 | - .min_h(px(KEYS_ROW_H)) | |
| 4902 | - .items_center() | |
| 4903 | - .justify_between() | |
| 4904 | - .gap(px(12.)) | |
| 4905 | - .px(px(6.)) | |
| 4944 | + .id(("do", i)) | |
| 4945 | + .flex_1() | |
| 4946 | + .min_w(px(0.)) | |
| 4947 | + .flex() | |
| 4948 | + .min_h(px(KEYS_ROW_H)) | |
| 4949 | + .items_center() | |
| 4950 | + .child(action.label()) | |
| 4951 | + // The reason rides on the label rather than in | |
| 4952 | + // the stroke column, which the rebind half | |
| 4953 | + // needs whatever the editor's state is: an | |
| 4954 | + // action nobody can ask for right now is still | |
| 4955 | + // one whose key may be changed. | |
| 4956 | + .when_some(refusal.why(), |d, why| { | |
| 4957 | + let why: SharedString = why.into(); | |
| 4958 | + d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into()) | |
| 4959 | + }) | |
| 4960 | + .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) | |
| 4961 | + .when(refusal.yes(), |d| { | |
| 4962 | + d.cursor_pointer().hover(|s| s.bg(rgb(HOVER))).on_click( | |
| 4963 | + cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 4964 | + // The card goes first: several of | |
| 4965 | + // these open a card of their own, | |
| 4966 | + // and every edit moves the indices | |
| 4967 | + // the menus are holding. | |
| 4968 | + this.keys_open = false; | |
| 4969 | + this.rebinding = None; | |
| 4970 | + this.act(action, cx); | |
| 4971 | + cx.notify(); | |
| 4972 | + }), | |
| 4973 | + ) | |
| 4974 | + }), | |
| 4975 | + ) | |
| 4976 | + .child( | |
| 4977 | + // ponytail: the column is as wide as the stroke it | |
| 4978 | + // prints, so a one-character chord gives this half a | |
| 4979 | + // hit area under the 24px WCAG 2.5.8 floor -- tall | |
| 4980 | + // enough, narrow. Upgrade: a min_w of HIT_MIN here. | |
| 4981 | + div() | |
| 4982 | + .id(("bind", i)) | |
| 4983 | + .flex_none() | |
| 4984 | + .flex() | |
| 4985 | + .min_h(px(KEYS_ROW_H)) | |
| 4986 | + .items_center() | |
| 4987 | + .cursor_pointer() | |
| 4988 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 4989 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 4990 | + this.rebinding = Some(action); | |
| 4991 | + cx.notify(); | |
| 4992 | + })) | |
| 4993 | + .child(if capturing { | |
| 4994 | + div() | |
| 4995 | + .text_color(rgb(INK_DIM)) | |
| 4996 | + .child(format!("press a key — {out} cancels")) | |
| 4997 | + } else { | |
| 4998 | + div().child(self.keymap.display(action)) | |
| 4999 | + }), | |
| 5000 | + ) | |
| 5001 | + .into_any_element() | |
| 5002 | + } | |
| 5003 | + KeyRow::Fixed(f) => { | |
| 5004 | + let f = &keymap::FIXED[f]; | |
| 5005 | + row() | |
| 4906 | 5006 | .child(f.label) |
| 4907 | 5007 | // Dim, and no hover: this one is not a row you can click. |
| 4908 | 5008 | .child(div().text_color(rgb(INK_DIM)).child(f.chord)) |
| 4909 | - .into_any_element(), | |
| 4910 | - ); | |
| 4911 | - } | |
| 5009 | + .into_any_element() | |
| 5010 | + } | |
| 5011 | + }); | |
| 4912 | 5012 | } |
| 4913 | 5013 | Some( |
| 4914 | 5014 | div() |
| @@ -4935,7 +5035,7 @@ impl Player { | ||
| 4935 | 5035 | // Title and instruction are two children, never one |
| 4936 | 5036 | // wrapping line: a fixed-height slot whose text wrapped |
| 4937 | 5037 | // painted its second line over the first row. |
| 4938 | - .child(div().flex_none().px(px(6.)).child("Keybindings")) | |
| 5038 | + .child(div().flex_none().px(px(6.)).child("Actions & keys")) | |
| 4939 | 5039 | // One status line, under the title where the eye starts. |
| 4940 | 5040 | // A refusal takes it over -- it is the more urgent of the |
| 4941 | 5041 | // two, and the notice bar it would otherwise appear in is |
| @@ -4953,7 +5053,10 @@ impl Player { | ||
| 4953 | 5053 | .child( |
| 4954 | 5054 | self.notice |
| 4955 | 5055 | .clone() |
| 4956 | - .unwrap_or_else(|| "click a row, then press a key".into()), | |
| 5056 | + .unwrap_or_else(|| { | |
| 5057 | + "click an action to do it · click its key to change it" | |
| 5058 | + .into() | |
| 5059 | + }), | |
| 4957 | 5060 | ), |
| 4958 | 5061 | ) |
| 4959 | 5062 | // Capped and scrolling rather than as tall as the action |
| @@ -6492,7 +6595,6 @@ impl Player { | ||
| 6492 | 6595 | let menu = self.context_menu?; |
| 6493 | 6596 | let session = self.session.as_ref()?; |
| 6494 | 6597 | let clip = *session.lane_clips(menu.lane).get(menu.idx)?; |
| 6495 | - let playhead = frame_at(session.now(), self.fps); | |
| 6496 | 6598 | let source = session.sources().get(clip.source).cloned()?; |
| 6497 | 6599 | let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); |
| 6498 | 6600 | let row = |n: usize| { |
| @@ -6546,7 +6648,11 @@ impl Player { | ||
| 6546 | 6648 | } |
| 6547 | 6649 | } else { |
| 6548 | 6650 | for action in MENU_ITEMS { |
| 6549 | - let enabled = applicable(&clip, menu.lane, action, playhead); | |
| 6651 | + // The registry's own answer, the same one the actions card | |
| 6652 | + // dims a row with -- and a row that takes no click says *why* | |
| 6653 | + // rather than printing a stroke that would do nothing. | |
| 6654 | + let refusal = self.enable(action, Some((menu.lane, menu.idx))); | |
| 6655 | + let enabled = refusal.yes(); | |
| 6550 | 6656 | // The one item that is not about this clip says so, and says it |
| 6551 | 6657 | // here rather than in the registry: the stroke is global too, |
| 6552 | 6658 | // but its row in the keys menu is not sitting on a clip. |
| @@ -6558,11 +6664,20 @@ impl Player { | ||
| 6558 | 6664 | rows.push( |
| 6559 | 6665 | row(rows.len()) |
| 6560 | 6666 | .child(label) |
| 6561 | - .child( | |
| 6562 | - div() | |
| 6667 | + .child(match refusal.why() { | |
| 6668 | + // One truncated line, like the details side: a | |
| 6669 | + // reason that wrapped would make the card taller | |
| 6670 | + // than the height `menu_at` placed it by. | |
| 6671 | + Some(why) => div() | |
| 6672 | + .min_w(px(0.)) | |
| 6673 | + .truncate() | |
| 6674 | + .text_size(px(11.)) | |
| 6675 | + .text_color(rgb(INK_DIM)) | |
| 6676 | + .child(why), | |
| 6677 | + None => div() | |
| 6563 | 6678 | .text_color(rgb(INK_DIM)) |
| 6564 | 6679 | .child(self.keymap.display(action)), |
| 6565 | - ) | |
| 6680 | + }) | |
| 6566 | 6681 | .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) |
| 6567 | 6682 | .when(enabled, |d| { |
| 6568 | 6683 | d.cursor_pointer() |
| @@ -7331,42 +7446,132 @@ fn band_label(band: &Band) -> String { | ||
| 7331 | 7446 | } |
| 7332 | 7447 | } |
| 7333 | 7448 | |
| 7334 | -/// Whether the clip menu offers `action` on the clip it was opened on. Two of | |
| 7335 | -/// the items act on the *playhead* rather than on the clip, so a menu opened | |
| 7336 | -/// away from it dims them instead of looking broken when they are clicked, and | |
| 7337 | -/// one acts on sound, which only an audio lane's clip has. | |
| 7338 | -fn applicable(clip: &Clip, lane: Lane, action: ActionId, playhead: u32) -> bool { | |
| 7339 | - match action { | |
| 7340 | - // The equalizer filters samples, and a video clip has none of its own | |
| 7341 | - // here: the sound is the audio lane's, clip for clip. | |
| 7342 | - ActionId::Equalizer => lane.kind == LaneKind::Audio, | |
| 7343 | - // A grade is a picture setting and an audio clip has no picture: the | |
| 7344 | - // item is there on every clip, and dimmed where it would mean nothing. | |
| 7345 | - // A fit policy is a picture setting for the same reason. | |
| 7346 | - ActionId::Color | ActionId::Fit => lane.kind == LaneKind::Video, | |
| 7347 | - // Splits this clip only from inside it: at either edge there is nothing | |
| 7348 | - // to split off -- and, on a speeded clip, only at a frame its own rate | |
| 7349 | - // can address, which is the same question `splittable` asks. | |
| 7350 | - ActionId::Cut => { | |
| 7351 | - clip.start < playhead | |
| 7352 | - && playhead < clip.end() | |
| 7353 | - && clip | |
| 7354 | - .speed | |
| 7355 | - .split_at(clip.len(), playhead - clip.start) | |
| 7356 | - .is_some() | |
| 7449 | +/// Whether an action can be asked for, and what to say when it cannot. Two | |
| 7450 | +/// kinds of no: `Hidden` is about the *kind* of thing the action was aimed at | |
| 7451 | +/// -- an audio clip has no picture, so a grade is not a thing that exists for | |
| 7452 | +/// it, whatever the editor does next -- and `No` is about the state of this | |
| 7453 | +/// moment, which the next click of the playhead can change. Both dim their row | |
| 7454 | +/// today; a menu that wants to leave the class refusals out and keep the state | |
| 7455 | +/// ones has only to match on which of the two it got. | |
| 7456 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | |
| 7457 | +enum Enable { | |
| 7458 | + Yes, | |
| 7459 | + No(&'static str), | |
| 7460 | + Hidden(&'static str), | |
| 7461 | +} | |
| 7462 | + | |
| 7463 | +impl Enable { | |
| 7464 | + /// Whether the row takes a click. | |
| 7465 | + fn yes(self) -> bool { | |
| 7466 | + self == Enable::Yes | |
| 7467 | + } | |
| 7468 | + | |
| 7469 | + /// What the row says instead of its stroke, if it says anything. | |
| 7470 | + fn why(self) -> Option<&'static str> { | |
| 7471 | + match self { | |
| 7472 | + Enable::Yes => None, | |
| 7473 | + Enable::No(why) | Enable::Hidden(why) => Some(why), | |
| 7357 | 7474 | } |
| 7358 | - // A rate applies to a clip of either kind and to its whole group, so | |
| 7359 | - // there is no lane it means nothing on -- `_ => true` below is its | |
| 7360 | - // answer, and the engine words the one refusal there is (no room). | |
| 7475 | + } | |
| 7476 | +} | |
| 7477 | + | |
| 7478 | +/// What an enablement question is asked *about*: the clip in question, if there | |
| 7479 | +/// is one, and the little of the editor's state the answers need. Handed in | |
| 7480 | +/// rather than read off the player, so [`enable`] is a pure function a test can | |
| 7481 | +/// ask about a clip without building a window. | |
| 7482 | +#[derive(Clone, Copy, Default)] | |
| 7483 | +struct Ctx { | |
| 7484 | + /// The clip the question is about -- the one a menu was opened on, or the | |
| 7485 | + /// marked one. `None` means the question is about the editor as a whole, | |
| 7486 | + /// and the clip-relative answers stand aside: those actions find their own | |
| 7487 | + /// clip under the playhead and word their own refusal. | |
| 7488 | + clip: Option<(Clip, Lane)>, | |
| 7489 | + playhead: u32, | |
| 7490 | + /// A timeline is open. | |
| 7491 | + timeline: bool, | |
| 7492 | + /// Something has been copied. | |
| 7493 | + clipboard: bool, | |
| 7494 | + exporting: bool, | |
| 7495 | +} | |
| 7496 | + | |
| 7497 | +/// Whether `action` can be asked for, on `ctx`. One arm per action and nothing | |
| 7498 | +/// else in the editor asks the question: the clip menu dims a row with this, | |
| 7499 | +/// the actions card dims a row with this, and the two can never come to | |
| 7500 | +/// disagree about what an action needs -- exactly the reason [`Player::act`] is | |
| 7501 | +/// one table too. | |
| 7502 | +fn enable(action: ActionId, ctx: Ctx) -> Enable { | |
| 7503 | + if !ctx.timeline { | |
| 7504 | + return Enable::No("no timeline open"); | |
| 7505 | + } | |
| 7506 | + // An export is reading the edit list every other action would change, which | |
| 7507 | + // is the rule the key handler already follows. | |
| 7508 | + if ctx.exporting { | |
| 7509 | + return match action { | |
| 7510 | + ActionId::CancelExport => Enable::Yes, | |
| 7511 | + _ => Enable::No("an export is running"), | |
| 7512 | + }; | |
| 7513 | + } | |
| 7514 | + match action { | |
| 7515 | + // -- class: what kind of thing the action is about. The equalizer | |
| 7516 | + // filters samples, and a video clip has none of its own here: the sound | |
| 7517 | + // is the audio lane's, clip for clip. | |
| 7518 | + ActionId::Equalizer => match ctx.clip { | |
| 7519 | + Some((_, lane)) if lane.kind != LaneKind::Audio => Enable::Hidden("this clip is picture"), | |
| 7520 | + _ => Enable::Yes, | |
| 7521 | + }, | |
| 7522 | + // A grade is a picture setting and an audio clip has no picture. A fit | |
| 7523 | + // policy is a picture setting for the same reason. | |
| 7524 | + ActionId::Color | ActionId::Fit => match ctx.clip { | |
| 7525 | + Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), | |
| 7526 | + _ => Enable::Yes, | |
| 7527 | + }, | |
| 7528 | + // -- state: true of this clip now, and the next playhead click or the | |
| 7529 | + // next selection changes the answer. Splits this clip only from inside | |
| 7530 | + // it: at either edge there is nothing to split off -- and, on a speeded | |
| 7531 | + // clip, only at a frame its own rate can address, which is the same | |
| 7532 | + // question `splittable` asks. | |
| 7533 | + ActionId::Cut => match ctx.clip { | |
| 7534 | + Some((clip, _)) | |
| 7535 | + if !(clip.start < ctx.playhead | |
| 7536 | + && ctx.playhead < clip.end() | |
| 7537 | + && clip | |
| 7538 | + .speed | |
| 7539 | + .split_at(clip.len(), ctx.playhead - clip.start) | |
| 7540 | + .is_some()) => | |
| 7541 | + { | |
| 7542 | + Enable::No("only from inside a clip") | |
| 7543 | + } | |
| 7544 | + _ => Enable::Yes, | |
| 7545 | + }, | |
| 7361 | 7546 | // Rejoins whatever meets at the playhead, so it can mean something only |
| 7362 | 7547 | // at an edge of this clip. Whether those two halves were ever one take |
| 7363 | 7548 | // is the engine's question, and it words that refusal itself. |
| 7364 | - ActionId::Regroup => playhead == clip.start || playhead == clip.end(), | |
| 7549 | + ActionId::Regroup => match ctx.clip { | |
| 7550 | + Some((clip, _)) if ctx.playhead != clip.start && ctx.playhead != clip.end() => { | |
| 7551 | + Enable::No("only where two clips meet") | |
| 7552 | + } | |
| 7553 | + _ => Enable::Yes, | |
| 7554 | + }, | |
| 7365 | 7555 | // Nothing to take apart in a clip that names no group at all. Whether |
| 7366 | 7556 | // the group it names still has another half is the engine's question, |
| 7367 | - // like the regroup above, and it words that refusal itself. | |
| 7368 | - ActionId::Detach => clip.link.is_some(), | |
| 7369 | - _ => true, | |
| 7557 | + // like the regroup above. | |
| 7558 | + ActionId::Detach => match ctx.clip { | |
| 7559 | + Some((clip, _)) if clip.link.is_none() => Enable::No("this clip is not grouped"), | |
| 7560 | + _ => Enable::Yes, | |
| 7561 | + }, | |
| 7562 | + // The three that act on the marked clip and on nothing else: with none | |
| 7563 | + // marked they would silently do nothing, which is what the Delete | |
| 7564 | + // button's own dimming has always said. | |
| 7565 | + ActionId::Copy | ActionId::Delete | ActionId::Lift if ctx.clip.is_none() => { | |
| 7566 | + Enable::No("click a clip first") | |
| 7567 | + } | |
| 7568 | + ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"), | |
| 7569 | + ActionId::CancelExport => Enable::No("nothing is exporting"), | |
| 7570 | + // A rate applies to a clip of either kind and to its whole group, so | |
| 7571 | + // there is no lane it means nothing on, and the engine words the one | |
| 7572 | + // refusal there is (no room). Everything else is the editor's own and | |
| 7573 | + // needs nothing but a timeline. | |
| 7574 | + _ => Enable::Yes, | |
| 7370 | 7575 | } |
| 7371 | 7576 | } |
| 7372 | 7577 | |
| @@ -9060,22 +9265,22 @@ fn timecode(t: f64, fps: f64) -> String { | ||
| 9060 | 9265 | #[cfg(test)] |
| 9061 | 9266 | mod tests { |
| 9062 | 9267 | use super::{ |
| 9063 | - ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | |
| 9064 | - EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | |
| 9065 | - EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, | |
| 9066 | - HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, | |
| 9067 | - KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, | |
| 9068 | - LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, | |
| 9069 | - PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, | |
| 9070 | - SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Transport, VOLUME_W, Volume, | |
| 9071 | - WAVE_BPS, WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, | |
| 9072 | - clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, eq_x, eq_y, | |
| 9073 | - estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, | |
| 9074 | - fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, | |
| 9075 | - keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, | |
| 9076 | - project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, | |
| 9077 | - source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, | |
| 9078 | - unseen_paths, unseen_sources, whole_take, window_title, | |
| 9268 | + ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, | |
| 9269 | + EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, | |
| 9270 | + EQ_SPECTRUM_DB, EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, FORMATS, | |
| 9271 | + Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, | |
| 9272 | + INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, | |
| 9273 | + LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, | |
| 9274 | + MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, | |
| 9275 | + SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, | |
| 9276 | + Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, band_label, bitrate_refusal, | |
| 9277 | + can_add, cancels_export, clipboard_after_remove, color_snap, containers, enable, envelope, | |
| 9278 | + eq_spectrum, eq_x, eq_y, estimated_mb, export_path, export_settings, format_key, | |
| 9279 | + format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, | |
| 9280 | + is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, next_container, | |
| 9281 | + normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, | |
| 9282 | + show_label, silence_rate, snapped, source_tint, span_partner, speed_at, summary_head, | |
| 9283 | + summary_tail, timecode, transport, unseen_paths, unseen_sources, whole_take, window_title, | |
| 9079 | 9284 | }; |
| 9080 | 9285 | use super::{ |
| 9081 | 9286 | LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, |
| @@ -9391,43 +9596,126 @@ mod tests { | ||
| 9391 | 9596 | speed: Speed::NORMAL, |
| 9392 | 9597 | }; |
| 9393 | 9598 | assert_eq!(clip.end(), 90); |
| 9394 | - // Cut splits from inside only: neither edge has anything to split off. | |
| 9395 | 9599 | let a1 = Lane::A1; |
| 9396 | 9600 | let v1 = Lane::V1; |
| 9397 | - assert!(applicable(&clip, v1, ActionId::Cut, 31)); | |
| 9398 | - assert!(applicable(&clip, v1, ActionId::Cut, 89)); | |
| 9399 | - assert!(!applicable(&clip, v1, ActionId::Cut, 30)); | |
| 9400 | - assert!(!applicable(&clip, v1, ActionId::Cut, 90)); | |
| 9401 | - assert!(!applicable(&clip, v1, ActionId::Cut, 200)); | |
| 9601 | + // The question the clip menu asks: a timeline is open and the menu was | |
| 9602 | + // opened on this clip, at this playhead. | |
| 9603 | + let on = |clip: &Clip, lane, action, playhead| { | |
| 9604 | + enable( | |
| 9605 | + action, | |
| 9606 | + Ctx { | |
| 9607 | + clip: Some((*clip, lane)), | |
| 9608 | + playhead, | |
| 9609 | + timeline: true, | |
| 9610 | + ..Ctx::default() | |
| 9611 | + }, | |
| 9612 | + ) | |
| 9613 | + }; | |
| 9614 | + let offered = |clip: &Clip, lane, action, playhead| on(clip, lane, action, playhead).yes(); | |
| 9615 | + // Cut splits from inside only: neither edge has anything to split off. | |
| 9616 | + assert!(offered(&clip, v1, ActionId::Cut, 31)); | |
| 9617 | + assert!(offered(&clip, v1, ActionId::Cut, 89)); | |
| 9618 | + assert!(!offered(&clip, v1, ActionId::Cut, 30)); | |
| 9619 | + assert!(!offered(&clip, v1, ActionId::Cut, 90)); | |
| 9620 | + assert!(!offered(&clip, v1, ActionId::Cut, 200)); | |
| 9402 | 9621 | // Regroup is the other way round: only where this clip meets another. |
| 9403 | - assert!(applicable(&clip, v1, ActionId::Regroup, 30)); | |
| 9404 | - assert!(applicable(&clip, v1, ActionId::Regroup, 90)); | |
| 9405 | - assert!(!applicable(&clip, v1, ActionId::Regroup, 60)); | |
| 9622 | + assert!(offered(&clip, v1, ActionId::Regroup, 30)); | |
| 9623 | + assert!(offered(&clip, v1, ActionId::Regroup, 90)); | |
| 9624 | + assert!(!offered(&clip, v1, ActionId::Regroup, 60)); | |
| 9406 | 9625 | // Detach is the clip's own business: nothing to take apart in one that |
| 9407 | 9626 | // names no group, and whether the group still has another half is the |
| 9408 | 9627 | // engine's question. Group is offered on every clip, for that reason. |
| 9409 | - assert!(!applicable(&clip, v1, ActionId::Detach, 0)); | |
| 9628 | + assert!(!offered(&clip, v1, ActionId::Detach, 0)); | |
| 9410 | 9629 | let grouped = Clip { |
| 9411 | 9630 | link: Some(3), |
| 9412 | 9631 | ..clip |
| 9413 | 9632 | }; |
| 9414 | - assert!(applicable(&grouped, v1, ActionId::Detach, 60)); | |
| 9415 | - assert!(applicable(&clip, a1, ActionId::Group, 0)); | |
| 9633 | + assert!(offered(&grouped, v1, ActionId::Detach, 60)); | |
| 9634 | + assert!(offered(&clip, a1, ActionId::Group, 0)); | |
| 9416 | 9635 | // The equalizer is the one item the *lane* decides: it filters samples, |
| 9417 | 9636 | // and a video clip has none of its own. Never the playhead's business. |
| 9418 | - assert!(applicable(&clip, a1, ActionId::Equalizer, 0)); | |
| 9419 | - assert!(applicable(&clip, a1, ActionId::Equalizer, 60)); | |
| 9420 | - assert!(!applicable(&clip, v1, ActionId::Equalizer, 60)); | |
| 9637 | + assert!(offered(&clip, a1, ActionId::Equalizer, 0)); | |
| 9638 | + assert!(offered(&clip, a1, ActionId::Equalizer, 60)); | |
| 9639 | + assert!(!offered(&clip, v1, ActionId::Equalizer, 60)); | |
| 9421 | 9640 | // The rest act on the clip that was clicked, so they always mean |
| 9422 | 9641 | // something -- the engine words its own refusals. |
| 9423 | 9642 | for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] { |
| 9424 | - assert!(applicable(&clip, v1, action, 0)); | |
| 9425 | - assert!(applicable(&clip, a1, action, 60)); | |
| 9643 | + assert!(offered(&clip, v1, action, 0)); | |
| 9644 | + assert!(offered(&clip, a1, action, 60)); | |
| 9426 | 9645 | } |
| 9427 | 9646 | // Except the grade, which is a picture setting: offered on a video |
| 9428 | 9647 | // clip wherever the playhead is, dimmed on a waveform. |
| 9429 | - assert!(applicable(&clip, v1, ActionId::Color, 0)); | |
| 9430 | - assert!(!applicable(&clip, a1, ActionId::Color, 60)); | |
| 9648 | + assert!(offered(&clip, v1, ActionId::Color, 0)); | |
| 9649 | + assert!(!offered(&clip, a1, ActionId::Color, 60)); | |
| 9650 | + // The two kinds of no, which is what the row can be told apart by: a | |
| 9651 | + // grade on a waveform is a *class* answer -- an audio clip has no | |
| 9652 | + // picture and never will, so a menu may leave the item out -- where a | |
| 9653 | + // cut at the clip's edge is this moment's answer and the next click of | |
| 9654 | + // the playhead changes it, so that one is dimmed and stays. | |
| 9655 | + assert!(matches!( | |
| 9656 | + on(&clip, a1, ActionId::Color, 60), | |
| 9657 | + Enable::Hidden(_) | |
| 9658 | + )); | |
| 9659 | + assert!(matches!( | |
| 9660 | + on(&clip, a1, ActionId::Fit, 60), | |
| 9661 | + Enable::Hidden(_) | |
| 9662 | + )); | |
| 9663 | + assert!(matches!( | |
| 9664 | + on(&clip, v1, ActionId::Equalizer, 60), | |
| 9665 | + Enable::Hidden(_) | |
| 9666 | + )); | |
| 9667 | + assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); | |
| 9668 | + assert!(matches!(on(&clip, v1, ActionId::Regroup, 60), Enable::No(_))); | |
| 9669 | + assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); | |
| 9670 | + // Every refusal says something, and says it short enough to sit in the | |
| 9671 | + // menu's right-hand column beside a label. | |
| 9672 | + for action in MENU_ITEMS { | |
| 9673 | + for lane in [v1, a1] { | |
| 9674 | + for playhead in [0, 30, 60, 90] { | |
| 9675 | + if let Some(why) = on(&clip, lane, action, playhead).why() { | |
| 9676 | + assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); | |
| 9677 | + } | |
| 9678 | + } | |
| 9679 | + } | |
| 9680 | + } | |
| 9681 | + // The editor as a whole, which is how the actions card asks: with no | |
| 9682 | + // timeline nothing is offered, an export leaves only its own cancel, | |
| 9683 | + // and the three that act on the marked clip say so when none is. | |
| 9684 | + let whole = |action, ctx| enable(action, ctx); | |
| 9685 | + assert_eq!( | |
| 9686 | + whole(ActionId::Play, Ctx::default()), | |
| 9687 | + Enable::No("no timeline open") | |
| 9688 | + ); | |
| 9689 | + let live = Ctx { | |
| 9690 | + timeline: true, | |
| 9691 | + ..Ctx::default() | |
| 9692 | + }; | |
| 9693 | + assert!(whole(ActionId::Play, live).yes()); | |
| 9694 | + assert!(!whole(ActionId::Delete, live).yes()); | |
| 9695 | + assert!(!whole(ActionId::Paste, live).yes()); | |
| 9696 | + assert!( | |
| 9697 | + whole( | |
| 9698 | + ActionId::Paste, | |
| 9699 | + Ctx { | |
| 9700 | + clipboard: true, | |
| 9701 | + ..live | |
| 9702 | + } | |
| 9703 | + ) | |
| 9704 | + .yes() | |
| 9705 | + ); | |
| 9706 | + assert!(!whole(ActionId::CancelExport, live).yes()); | |
| 9707 | + let busy = Ctx { | |
| 9708 | + exporting: true, | |
| 9709 | + ..live | |
| 9710 | + }; | |
| 9711 | + assert!(whole(ActionId::CancelExport, busy).yes()); | |
| 9712 | + for action in ActionId::ALL { | |
| 9713 | + assert_eq!( | |
| 9714 | + whole(action, busy).yes(), | |
| 9715 | + action == ActionId::CancelExport, | |
| 9716 | + "{action:?} while an export reads the edit list" | |
| 9717 | + ); | |
| 9718 | + } | |
| 9431 | 9719 | // The playhead frame is the engine's own rule, boundary included. |
| 9432 | 9720 | assert_eq!(frame_at(1.0, 30.), 30); |
| 9433 | 9721 | assert_eq!(frame_at(0.0, 30.), 0); |
| @@ -9470,9 +9758,9 @@ mod tests { | ||
| 9470 | 9758 | |
| 9471 | 9759 | /// The other half of the keys menu's guarantee, and the audit this batch was |
| 9472 | 9760 | /// asked for kept as a test: no action may be a stroke and nothing else. |
| 9473 | - /// Either the clip menu offers it, or a control in the panel does -- named | |
| 9474 | - /// here by the id [`control`] is handed, read out of this file's own source | |
| 9475 | - /// like `no_stroke_is_missing_from_the_keys_menu` reads the key handler. | |
| 9761 | + /// The actions card answers it for all of them at once -- its rows come off | |
| 9762 | + /// [`ActionId::ALL`], so a fortieth action is on it the moment it exists and | |
| 9763 | + /// there is no hand-written list here to fall behind. | |
| 9476 | 9764 | #[test] |
| 9477 | 9765 | fn every_action_is_reachable_without_the_keyboard() { |
| 9478 | 9766 | use keymap::ActionId; |
| @@ -9481,48 +9769,22 @@ mod tests { | ||
| 9481 | 9769 | .next() |
| 9482 | 9770 | .unwrap(); |
| 9483 | 9771 | let element = |id: &str| source.contains(&format!("\"{id}\"")); |
| 9772 | + let listed: Vec<ActionId> = keys_rows() | |
| 9773 | + .iter() | |
| 9774 | + .filter_map(|r| match r { | |
| 9775 | + KeyRow::Act(a) => Some(*a), | |
| 9776 | + _ => None, | |
| 9777 | + }) | |
| 9778 | + .collect(); | |
| 9484 | 9779 | for action in ActionId::ALL { |
| 9485 | - let by_pointer = MENU_ITEMS.contains(&action) | |
| 9486 | - || match action { | |
| 9487 | - ActionId::Play => element("transport"), | |
| 9488 | - // One slot, two states: it starts an export and stops the | |
| 9489 | - // one it started. | |
| 9490 | - ActionId::Export | ActionId::CancelExport => element("export"), | |
| 9491 | - ActionId::Save => element("save"), | |
| 9492 | - ActionId::Undo => element("undo"), | |
| 9493 | - ActionId::Resolution => element("resolution"), | |
| 9494 | - // Three buttons beside it, and the ctrl+wheel on the bar. | |
| 9495 | - ActionId::ZoomIn => element("zoom-in"), | |
| 9496 | - ActionId::ZoomOut => element("zoom-out"), | |
| 9497 | - ActionId::ZoomFit => element("zoom-fit"), | |
| 9498 | - ActionId::AddVideoLane => element("add-video-lane"), | |
| 9499 | - ActionId::AddAudioLane => element("add-audio-lane"), | |
| 9500 | - // The × in a lane's own header, which takes any track and | |
| 9501 | - // not only the last one. | |
| 9502 | - ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => { | |
| 9503 | - source.contains("this.remove_lane(lane, cx)") | |
| 9504 | - } | |
| 9505 | - ActionId::ToggleMute => element("volume"), | |
| 9506 | - // The fader on every audio track's own header, which is | |
| 9507 | - // also what opens the card the limiter is on. | |
| 9508 | - ActionId::Mix => element("mix-lane"), | |
| 9509 | - ActionId::VolumeUp | ActionId::VolumeDown => element("volume-bar"), | |
| 9510 | - // The ruler seeks anywhere the pointer points; the frame and | |
| 9511 | - // the second are the keyboard's finer grain of that move. | |
| 9512 | - ActionId::StepBack | |
| 9513 | - | ActionId::StepForward | |
| 9514 | - | ActionId::JumpBack | |
| 9515 | - | ActionId::JumpForward | |
| 9516 | - | ActionId::GoStart | |
| 9517 | - | ActionId::GoEnd => element("ruler"), | |
| 9518 | - // A press on a clip is the selection, group and all. | |
| 9519 | - ActionId::Select | ActionId::SelectNext | ActionId::SelectPrev => { | |
| 9520 | - source.contains("this.select((lane, i), cx)") | |
| 9521 | - } | |
| 9522 | - _ => false, | |
| 9523 | - }; | |
| 9524 | - assert!(by_pointer, "{action:?} is reachable by keyboard only"); | |
| 9780 | + assert_eq!( | |
| 9781 | + listed.iter().filter(|a| **a == action).count(), | |
| 9782 | + 1, | |
| 9783 | + "{action:?} is reachable by keyboard only" | |
| 9784 | + ); | |
| 9525 | 9785 | } |
| 9786 | + // And the card is a door the pointer can open: the panel's own button. | |
| 9787 | + assert!(element("keys"), "no way to open the actions card"); | |
| 9526 | 9788 | // The card-local strokes have the same rule, and each of them is a thing |
| 9527 | 9789 | // on its card: the graph and its two buttons, the colour bars and their |
| 9528 | 9790 | // reset, the speed bar and its presets, and the silence card's rows -- |
| @@ -10627,6 +10889,65 @@ mod tests { | ||
| 10627 | 10889 | } |
| 10628 | 10890 | } |
| 10629 | 10891 | |
| 10892 | + /// The whole point of the card: there is no action a pointer cannot reach. | |
| 10893 | + /// It renders [`keys_rows`] and nothing else, so this reads the same list | |
| 10894 | + /// the card does -- add an `ActionId` and forget to surface it and this | |
| 10895 | + /// fails, which is the only way that stays true as the editor grows. | |
| 10896 | + #[test] | |
| 10897 | + fn every_action_is_on_the_actions_card() { | |
| 10898 | + use keymap::{ActionId, Category, Keymap}; | |
| 10899 | + let rows = keys_rows(); | |
| 10900 | + let listed: Vec<ActionId> = rows | |
| 10901 | + .iter() | |
| 10902 | + .filter_map(|r| match r { | |
| 10903 | + KeyRow::Act(a) => Some(*a), | |
| 10904 | + _ => None, | |
| 10905 | + }) | |
| 10906 | + .collect(); | |
| 10907 | + for action in ActionId::ALL { | |
| 10908 | + assert_eq!( | |
| 10909 | + listed.iter().filter(|a| **a == action).count(), | |
| 10910 | + 1, | |
| 10911 | + "{action:?} is not on the card exactly once" | |
| 10912 | + ); | |
| 10913 | + } | |
| 10914 | + assert_eq!(listed.len(), ActionId::ALL.len()); | |
| 10915 | + // Under its own heading, in the registry's order: every row after a | |
| 10916 | + // heading belongs to that heading until the next one. | |
| 10917 | + let mut heading = None; | |
| 10918 | + let mut heads = 0; | |
| 10919 | + for row in &rows { | |
| 10920 | + match row { | |
| 10921 | + KeyRow::Head(category) => { | |
| 10922 | + heading = Some(*category); | |
| 10923 | + heads += 1; | |
| 10924 | + } | |
| 10925 | + KeyRow::Act(action) => assert_eq!(Some(action.category()), heading, "{action:?}"), | |
| 10926 | + KeyRow::Fixed(i) => assert_eq!(Some(keymap::FIXED[*i].category), heading), | |
| 10927 | + } | |
| 10928 | + } | |
| 10929 | + assert_eq!(heads, Category::ALL.len(), "a heading per category"); | |
| 10930 | + // The card-local strokes are still all there beside them. | |
| 10931 | + assert_eq!( | |
| 10932 | + rows.iter() | |
| 10933 | + .filter(|r| matches!(r, KeyRow::Fixed(_))) | |
| 10934 | + .count(), | |
| 10935 | + keymap::FIXED.len() | |
| 10936 | + ); | |
| 10937 | + // Both columns say something: the label does the action, the stroke | |
| 10938 | + // beside it changes that stroke, and neither may read blank. | |
| 10939 | + let keymap = Keymap::defaults(); | |
| 10940 | + for action in ActionId::ALL { | |
| 10941 | + assert!(!action.label().is_empty(), "{action:?}"); | |
| 10942 | + assert_ne!(keymap.display(action), "unbound", "{action:?}"); | |
| 10943 | + } | |
| 10944 | + // The list scrolls inside a card the smallest window holds, so a | |
| 10945 | + // thirty-fourth action costs no height at all. | |
| 10946 | + assert!(rows.len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, "no cap needed?"); | |
| 10947 | + // Both halves of a row are click targets, so WCAG 2.5.8 binds them. | |
| 10948 | + assert!(KEYS_ROW_H >= HIT_MIN); | |
| 10949 | + } | |
| 10950 | + | |
| 10630 | 10951 | #[test] |
| 10631 | 10952 | fn the_keybindings_card_fits_the_smallest_window() { |
| 10632 | 10953 | // The row list is capped and scrolls, so the card's height no longer |