From 9d24ad88e73dc193ad006934382f8446bafb7b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 17:50:33 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20every=20menu=20lands?= =?UTF-8?q?=20inside=20the=20window,=20clear=20of=20what=20it=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The three hanging menus mount on the room root instead of inside `stance-centre`: their anchors are window coordinates, and the dock -- painted after the centre column -- covered every pixel past the seam, which is the clip menu whose chords were cut mid-word at x=995. `menu_at` now clears all four edges by `MENU_EDGE`, and `menu_rows_h` takes both margins off the room first, so a floored menu never buys that room back off the picture. The library menu hangs a row below the pointer rather than on it: opened at the pointer it covered the very row it was about. Its rows wear the chord of the verb (`Add at playhead ↵`) or nothing at all -- the prose glosses were §8's instructional copy in the column §4 reserves for strokes -- and the destructive remove says its consequence in its own label, since nothing prints beside it now. --- crates/app/src/layout.rs | 7 +++ crates/app/src/menus.rs | 42 +++++++++------- crates/app/src/oracle.rs | 14 ++++-- crates/app/src/tests/cards.rs | 2 +- crates/app/src/tests/editing.rs | 71 ++++++++++++++++++++++++-- crates/app/src/tests/layout.rs | 8 +-- crates/app/src/ui/library.rs | 41 ++++++++++++--- crates/app/src/ui/stance.rs | 89 +++++++++++++++++++++++---------- 8 files changed, 210 insertions(+), 64 deletions(-) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 569952b..971d528 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -89,6 +89,13 @@ pub(crate) const EXPORT_KEY_W: f32 = 26.; pub(crate) const MENU_W: f32 = 260.; pub(crate) const MENU_ROW_H: f32 = HIT_MIN; pub(crate) const MENU_PAD: f32 = 6.; +/// The breathing room a hanging menu keeps against every window edge. Without +/// it `menu_at`'s clamp let a menu sit flush on the bottom edge -- the last row +/// touching the frame reads as a list cut off rather than a list that ended, +/// which is what the user saw at 1280x720 (`f-clip-menu.png`, rows running to +/// y=720 exactly). Taken out of the room the list may fill as well as off the +/// clamp, so a floored menu never grows back up over the picture to buy it. +pub(crate) const MENU_EDGE: f32 = 4.; /// A cue's text, and the line it sits on. Fixed rather than a share of the /// picture: the video region is 108 px tall at the 640x360 floor and a diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index e933aac..b8d137b 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -110,8 +110,9 @@ pub(crate) enum Choice { pub(crate) type ChoiceRow = (Choice, SharedString, SharedString, bool); /// What a library row's menu offers, in the order it lists them. Unlike the clip -/// menu's items none of these is a stroke -- there is no keyboard way to a row -- -/// so the label and the hint are written here rather than read off the keymap. +/// menu's items only one of these ([`RowItem::Add`]) is a stroke, and that one +/// is not a bindable [`ActionId`] but `ui/stance.rs`'s own `enter` branch, so +/// the label and the chord are written here rather than read off the keymap. #[derive(Clone, Copy, PartialEq)] pub(crate) enum RowItem { Add, @@ -140,29 +141,34 @@ impl RowItem { match self { Self::Add => "Add at playhead", Self::Remove => "Remove from library", - // Same label as the plain remove: only ever one of the two is on - // the plate (the oracle hides the other), so what differs is the - // consequence, and the consequence belongs in the hint column - // where every other row states its own. The long dashed title - // truncated its own hint at `MENU_W`. - Self::RemoveWithClips => "Remove from library", + // The consequence is in the label now rather than in the hint + // column beside a label identical to the plain remove's: that + // column carries chords ([`RowItem::hint`]), and a destructive + // verb whose difference from the row above it lived in dim grey + // prose is a verb that reads as the same verb. It fits `MENU_W` + // whole exactly because nothing is printed to its right. + Self::RemoveWithClips => "Remove with its clips", Self::Reveal => "Reveal in files", Self::Properties => "Properties", } } - /// The dim right-hand column, where the clip menu prints the stroke: what - /// the item will do to the timeline, so nothing here is a surprise. + /// The dim right-hand column: the *stroke* that does the same thing, the + /// one thing DESIGN §4 puts there ("every command wears its chord"), and + /// nothing at all where no stroke reaches the verb. + /// + /// It used to carry a prose gloss on every row -- a phrase about the whole + /// file, one about the desktop's file browser, one about clips -- which is + /// §8's instructional copy sitting in the column the sibling clip menu + /// spends on chords, and which the user read as the crowding it is. The + /// only row a stroke reaches is the add (`ui/stance.rs`'s `enter` branch, + /// live while a dock row is picked); its own row in the dock already wears + /// the same `↵`. A refusal still prints here in place of the chord + /// (`oracle::row_enable`) -- that is state, not instruction. pub(crate) fn hint(self) -> &'static str { match self { - // Short enough to sit beside its label inside `MENU_W`, the clip - // menu's rule for a refusal: this column truncates, and a hint cut - // off mid-word says less than a shorter one. - Self::Add => "the whole file", - Self::Remove => "nothing plays it", - Self::RemoveWithClips => "clips too", - Self::Reveal => "file manager", - Self::Properties => "…", + Self::Add => "↵", + Self::Remove | Self::RemoveWithClips | Self::Reveal | Self::Properties => "", } } } diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 372001a..b913e9c 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -451,18 +451,22 @@ pub(crate) fn row_items(ctx: RowCtx) -> Vec { /// How tall a menu's list may draw: the whole of it where the window has room, /// and what the window has where it has not -- only then does the list scroll. /// A cap fixed at twelve rows put the last items behind a scroll on a window -/// with room to spare, which reads as a menu cut off by the bottom edge. +/// with room to spare, which reads as a menu cut off by the bottom edge. Both +/// [`MENU_EDGE`] margins come off the room first, so the plate `menu_at` places +/// from this always fits between them whatever the anchor. pub(crate) fn menu_rows_h(rows: usize, viewport: Size) -> f32 { - let room = f32::from(viewport.height) - MENU_PAD * 2.; + let room = f32::from(viewport.height) - MENU_PAD * 2. - MENU_EDGE * 2.; (rows as f32 * MENU_ROW_H).min(room.max(MENU_ROW_H)) } /// Where the menu actually hangs: at the pointer, pulled back inside the window /// when it would not fit -- an item off the bottom edge is an item nobody can -/// click. Never negative, so a window smaller than the menu loses the bottom of -/// it rather than the top, where the items are. +/// click. All four edges, [`MENU_EDGE`] clear of each: a plate flush on the +/// frame reads as a list that was cut, not one that ended. Never past the top +/// or left edge, so a window smaller than the menu loses the bottom of it +/// rather than the top, where the items are. pub(crate) fn menu_at(at: Point, viewport: Size, height: f32) -> (f32, f32) { - let fit = |v: f32, size: f32, room: f32| v.min(room - size).max(0.); + let fit = |v: f32, size: f32, room: f32| v.min(room - MENU_EDGE - size).max(MENU_EDGE); ( fit(f32::from(at.x), MENU_W, f32::from(viewport.width)), fit(f32::from(at.y), height, f32::from(viewport.height)), diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index cf1bec1..8123ba1 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1443,7 +1443,7 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { assert!(tall <= 360., "the list is taller than the floor"); assert_eq!( menu_at(point(px(600.), px(340.)), size(px(640.), px(360.)), tall), - (640. - MENU_W, 360. - tall), + (640. - crate::layout::MENU_EDGE - MENU_W, 360. - crate::layout::MENU_EDGE - tall), "the list would hang off the smallest window" ); } diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index d56b980..2480851 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -983,12 +983,14 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.)); assert_eq!( menu_at(point(px(700.), px(380.)), viewport, 150.), - (800. - MENU_W, 250.) + (800. - crate::layout::MENU_EDGE - MENU_W, 400. - crate::layout::MENU_EDGE - 150.) ); - // A window smaller than the menu loses its bottom, never its top. + // A window smaller than the menu loses its bottom, never its top: the + // top-left margin wins over the bottom-right one, because the items are + // at the top. assert_eq!( menu_at(point(px(90.), px(40.)), size(px(100.), px(50.)), 150.), - (0., 0.) + (crate::layout::MENU_EDGE, crate::layout::MENU_EDGE) ); // Every item is an action the registry knows, so the menu and the keys // menu say the same thing about it -- and none of them is unreachable @@ -1015,7 +1017,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { menu_at(point(px(0.), px(0.)), floor, { MENU_PAD * 2. + menu_rows_h(items, floor) }), - (0., 0.) + (crate::layout::MENU_EDGE, crate::layout::MENU_EDGE) ); // The picker is the same card and the longest list in it is the palette // family list, which grows every time somebody asks for more colours. @@ -1219,6 +1221,67 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { assert!(menu_rows_h(items, size(px(640.), px(360.))) < items as f32 * MENU_ROW_H); } +/// Defects 2 and 3 of the menu-placement lane, as source guards -- this binary +/// has no `VisualTestContext`, so where an element *mounts* and what its dim +/// column *says* are read off the source the way every other layout scan here +/// is. +/// +/// 1. All three hanging menus mount on the room's ROOT. Mounted inside +/// `stance-centre` the clip menu's window-coordinate anchor was laid out +/// from the centre column's own origin and painted under the dock, which is +/// the "chords cut mid-word" the user photographed. +/// 2. The library menu hangs a row clear of the pointer, so it cannot cover the +/// row it is about. +/// 3. The library rows carry chords, not prose. DESIGN §4 puts the stroke in +/// that column and §8 forbids the instructional copy that used to sit there. +#[test] +fn the_hanging_menus_mount_at_the_room_root_and_their_rows_wear_chords_not_prose() { + let stance = src_text("ui/stance.rs"); + let (centre, root) = stance + .split_once(".child(divider(Split::Dock,") + .expect("the dock seam splits the centre column from the room root"); + for menu in [ + "children(player.context_card(", + "children(player.library_card(", + "children(player.picker_card(", + ] { + assert!( + root.contains(menu), + "{menu} must mount after the dock, on the room root" + ); + assert!( + !centre.contains(menu), + "{menu} mounted inside stance-centre paints under the dock" + ); + } + let library = src_text("ui/library.rs"); + assert!( + library.contains("menu.at.y + px(ROW_CLEAR)"), + "the library menu must hang clear of the row it names" + ); + // Exactly one row wears a chord, and it is the one `ui/stance.rs`'s + // `enter` branch actually answers; every other row's column is empty. + for item in ROW_ITEMS { + let hint = item.hint(); + match item { + RowItem::Add => { + assert_eq!(hint, "↵"); + assert!( + stance.contains("if key == \"enter\"\n && this.dock_src_active"), + "the ↵ this menu advertises must still be the stroke that adds" + ); + } + _ => assert!(hint.is_empty(), "{:?} prints prose: {hint:?}", item.label()), + } + // §9: no junk drawer. A label that fits the plate whole beside its + // chord, and never a sentence. + assert!(item.label().split_whitespace().count() <= 4, "{}", item.label()); + } + // The two removes must not read as the same verb now that the column + // beside them is empty. + assert_ne!(RowItem::Remove.label(), RowItem::RemoveWithClips.label()); +} + /// The other half of the keys menu's guarantee, and the audit this batch was /// asked for kept as a test: no action may be a stroke and nothing else. /// The actions card answers it for all of them at once -- its rows come off diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index aaaa842..453318a 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2206,9 +2206,11 @@ fn every_darkroom_menu_sizes_its_list_against_the_floor_room_not_the_raw_viewpor to the picture floor (the 'menu in somewhere nonsense' defect)" ); assert!( - library.contains("menu_at(menu.at, viewport"), - "ui/library.rs no longer anchors its menu to the pointer through \ - menu_at -- update this guard" + library.contains("menu_at(at, viewport, h)") + && library.contains("point(menu.at.x, menu.at.y + px(ROW_CLEAR))"), + "ui/library.rs no longer anchors its menu to the pointer -- one row \ + clear of it, so the menu cannot cover the row it names -- through \ + menu_at; update this guard" ); } diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index e7812f1..c767084 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -4,6 +4,18 @@ use crate::ui::type_scale::Typeset; use crate::ui::widgets::*; use crate::*; +/// How far below the pointer a library menu hangs so it clears the row it was +/// opened on: a source row is two lines (`dock_stance::source_row` -- `py(4.)` +/// twice, a `gap(2.)` and two ~20px line boxes), and the pointer may land on +/// its very first pixel. +/// +/// corner-cut: a constant rather than the row's measured bottom, which the +/// `on_mouse_down` listener that sets `LibraryMenu::at` has no access to. The +/// ceiling is a row that grows a third line -- the menu would then start +/// inside it. Upgrade path: carry the row's `Bounds` bottom in `LibraryMenu` +/// via a `canvas`/`prepaint` probe in `source_row` and hang the menu off that. +const ROW_CLEAR: f32 = 52.; + impl Player { /// The menu a right-click on a library row opens: what can be done with the /// *file* rather than with a clip of it, and a turn-over side saying what @@ -161,14 +173,29 @@ impl Player { ); } } - // Placed at the pointer, clamped only to the window's own bounds -- - // standard context-menu behavior. Unlike the clip menu, this menu - // mounts on the root over the dock (no picture behind it to protect), - // so it does not go through `menu_floor`'s picture-floor clamp; doing - // so pulled a right-click high in the dock down to the picture floor, - // teleporting the menu away from the pointer that opened it. + // Hung BELOW the row it is about, not on the pointer: opened at the + // pointer it covered the very row it names (`k-lib-menu.png` -- the + // source row vanished under its own menu), and a menu that hides its + // subject is DESIGN §11.6's occlusion rule broken on the other panel. + // `menu_at` then does the rest -- left-aligned to the pointer, pulled + // back inside all four window edges, and flipped up above the row + // where the dock has no room below. Unlike the clip menu it does not + // go through `menu_floor`'s picture-floor clamp: it mounts over the + // dock, which has no picture behind it, and clamping there pulled a + // right-click high in the dock down to the picture floor, teleporting + // the menu away from the pointer that opened it. let list_h = menu_rows_h(rows.len(), viewport); - let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); + let h = MENU_PAD * 2. + list_h; + let below = point(menu.at.x, menu.at.y + px(ROW_CLEAR)); + // Above the row instead when the plate would not fit whole below it: + // `menu_at`'s own clamp would otherwise slide it back up *over* the + // row, which is the thing this placement exists to prevent. + let at = if f32::from(below.y) + h + MENU_EDGE > f32::from(viewport.height) { + point(menu.at.x, px((f32::from(menu.at.y) - h).max(0.))) + } else { + below + }; + let (x, y) = menu_at(at, viewport, h); let full: SharedString = path.display().to_string().into(); Some( scrim() diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index c47a5af..5ae7026 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -224,17 +224,59 @@ mod menu_floor_tests { let floor = below_picture_floor(f32::from(viewport.height), BENCH_H); let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, BENCH_H); assert_eq!(f32::from(at.y), floor); - // 396px of rows (the charter's measured menu height) does not fit in - // the 316px footprint room, so it must be capped to it, not the - // window's 720. - let list_h = (396f32).min(f32::from(room.height)); + // 17 rows -- more than the footprint holds -- sized through the real + // sizer, so the `MENU_EDGE` margin is in the number the clamp sees. + let list_h = crate::oracle::menu_rows_h(17, room); assert!(list_h <= f32::from(room.height)); - let (_, y) = crate::oracle::menu_at(at, viewport, list_h); + let h = crate::layout::MENU_PAD * 2. + list_h; + let (_, y) = crate::oracle::menu_at(at, viewport, h); assert_eq!( y, floor, "the top edge must not be walked back above the floor" ); } + + /// Defect 1 as the user met it (`f-clip-menu.png`): a menu opened near the + /// right and bottom of a 1280x720 window ran off both edges -- chords cut + /// mid-word at the dock seam, rows past the frame. Pure clamp math, both + /// window sizes the charter names, and both the floored (clip) menu and + /// the unfloored (library) one: whatever the anchor, the whole plate lands + /// inside the frame with [`MENU_EDGE`] to spare, and the floored one never + /// buys that room off the picture. + #[test] + fn a_menu_opened_in_the_bottom_right_corner_lands_whole_inside_the_window() { + use crate::layout::{MENU_EDGE, MENU_PAD, MENU_W}; + for viewport in [size(px(1280.), px(720.)), size(px(2560.), px(1440.))] { + let (w, v) = (f32::from(viewport.width), f32::from(viewport.height)); + let floor = below_picture_floor(v, BENCH_H); + for rows in [1usize, 5, 16, 40] { + for anchor in [ + point(px(w - 1.), px(v - 1.)), + point(px(w - 1.), px(0.)), + point(px(0.), px(v - 1.)), + ] { + // The clip menu's path: floored below the picture, sized + // against the room that leaves, then clamped. + let (at, room) = menu_floor(anchor, viewport, BENCH_H); + let h = MENU_PAD * 2. + crate::oracle::menu_rows_h(rows, room); + let (x, y) = crate::oracle::menu_at(at, viewport, h); + assert!(x >= MENU_EDGE && x + MENU_W <= w - MENU_EDGE, "x {x} rows {rows}"); + assert!(y >= MENU_EDGE && y + h <= v - MENU_EDGE, "y {y} h {h} rows {rows}"); + assert!(y >= floor, "y {y} walked above the picture floor {floor}"); + // The library menu's path: no floor, hung a row below the + // pointer, same clamp. + let h = MENU_PAD * 2. + crate::oracle::menu_rows_h(rows, viewport); + let (x, y) = crate::oracle::menu_at( + point(anchor.x, anchor.y + px(52.)), + viewport, + h, + ); + assert!(x >= MENU_EDGE && x + MENU_W <= w - MENU_EDGE, "lib x {x}"); + assert!(y >= MENU_EDGE && y + h <= v - MENU_EDGE, "lib y {y} h {h}"); + } + } + } + } } #[cfg(test)] @@ -1102,17 +1144,6 @@ pub(crate) fn render( .when(player.settings_open, |el| { el.child(settings_stance::render(player, window_size, cx)) }) - // The two menus (DESIGN §9: "verbs of the thing under the - // cursor", plate styling, the same scrim-and-row component - // the legacy tree already uses -- `library.rs`'s own doc - // comment: "Built like `Player::context_card` ... because it - // is the same menu on the other panel") and the open list a - // picker sets: none of the three had a home in the stance, - // so `overlaid()` refused every key over them for nothing - // ever drawn (FAULT 2). `render.rs`'s children order is kept - // -- clip menu, then library menu, then the open list last so - // it floats over whichever row opened it. - .children(player.context_card(window_size, cx)) // The export card and its running-progress sheet, mounted // over the whole room exactly as the legacy tree mounts them // (`render.rs`) -- the fix for the shipped "Export does @@ -1120,7 +1151,6 @@ pub(crate) fn render( // what draws it once open. .children(player.export_card(window_size, cx)) .children(player.export_progress_card(cx)) - .children(player.picker_card(window_size, cx)) // A maximized clip param card (EQ/Colour/Transform/Speed/ // Silence/Mix/Subtitle style) escapes the dock to mount here // instead, the same window-space `stance-centre` context @@ -1145,14 +1175,21 @@ pub(crate) fn render( ) .child(divider(Split::Dock, player.split_drag == Some(Split::Dock), cx)) .child(dock(player, dock_w, window_size, window, cx)) - // The library row menu mounts on the ROOT, not inside - // `stance-centre` like the clip menu beside it: it is opened from a - // dock row, so its anchor is a window x past the centre column's own - // right edge, and the dock -- painted after the centre -- covered - // every pixel of it. That is the whole of the shipped "can not - // remove a media from library" defect: the plate was built, placed - // and never visible. Mounted here it paints last, over the dock it - // belongs to, and its own `menu_floor` window coordinates finally - // mean what they say. + // All three hanging menus (DESIGN §9: "verbs of the thing under the + // cursor") mount on the ROOT, and none of them inside + // `stance-centre`. Their anchors are *window* coordinates -- a + // `MouseDownEvent::position` -- while an absolutely placed child of + // the centre column is laid out from that column's own origin and + // ends where it ends: the spine shifted every clip menu right by + // `SPINE_W`, and the dock, painted after the centre, covered every + // pixel past x = width - dock. That is the shipped "can not remove a + // media from library" defect (the library plate was built, placed and + // never visible) and the clip menu whose chords were cut off mid-word + // at the dock seam. Mounted here they paint last, over the dock they + // may overlap, and `menu_floor`/`menu_at`'s window coordinates finally + // mean what they say. Order is `render.rs`'s -- clip menu, library + // menu, then the open list last so it floats over whichever row set it. + .children(player.context_card(window_size, cx)) .children(player.library_card(window_size, cx)) + .children(player.picker_card(window_size, cx)) }