forge
Explore
Log in

Don't you dare go Hollow

A menu fits the room it is allowed

Browse files at this commit

9585160d8914965d14280a2536173a7bfe8a35adAhmet Kaan GümüşParent: d0ddef0
  • fix
    • a menu fits the room it is allowed
Show full message
🐛 fix(ui): a menu fits the room it is allowed

The clamp put the menu's top below the picture, and then the menu walked
straight back up over it: the list was still measured against the whole
window, so anything taller than the space below the frame was re-fitted to
the window's own bottom edge. Measured on a 720-high room, a 396-high menu
floored at 404 came back to 324 and ate the last ten pixels of the picture.

Menus now size their list against the room they are actually allowed to
fill, so a long one scrolls inside its own plate exactly as the keys
overlay does, and the frame stays whole. Two tests hold it: one reproduces
those numbers, one greps for the shape of the mistake so the next floated
surface cannot make it quietly.

This is the fourth surface to land on the picture — after the notice bar,
the export card and the preview badge — which is why the guard is
structural rather than another instance fixed.
crates/app/src/tests/layout.rsmodified+33 -0
@@ -1889,3 +1889,36 @@ fn the_darkroom_path_never_lets_a_notice_surface_reach_the_picture() {
18891889 the darkroom stance would paint it over the picture again"
18901890 );
18911891 }
1892+
1893+/// DESIGN §5/§11 check 6, the fourth occlusion defect (notice bar, export
1894+/// card, preview badge, now menus): every floating menu that can open above
1895+/// the picture -- the clip context menu, the picker, the library menu -- must
1896+/// size its scrolling list against `stance::menu_floor`'s room, not the raw
1897+/// window. Sizing against the whole viewport is exactly the bug that shipped:
1898+/// a menu taller than the bench/ledger/dock footprint got clamped by
1899+/// `menu_at`'s own bottom-edge fit back up over the picture, because nothing
1900+/// had told the list it only had the footprint to grow into. This pins the
1901+/// general rule so the next surface someone floats -- a fourth menu, a fifth
1902+/// occlusion -- cannot silently reintroduce `menu_rows_h(rows.len(),
1903+/// viewport)` in its place.
1904+#[test]
1905+fn every_darkroom_menu_sizes_its_list_against_the_floor_room_not_the_raw_viewport() {
1906+ for file in ["ui/overlays.rs", "ui/library.rs"] {
1907+ let text = src_text(file);
1908+ assert!(
1909+ !text.contains("menu_rows_h(rows.len(), viewport)"),
1910+ "{file} sizes a menu's list against the raw viewport again -- \
1911+ route it through stance::menu_floor's room instead, or a tall \
1912+ menu will climb back over the picture"
1913+ );
1914+ let floors = text.matches("menu_floor(").count();
1915+ let sizings = text.matches("menu_rows_h(rows.len(),").count();
1916+ assert_eq!(
1917+ floors, sizings,
1918+ "{file} has a menu list-sizing call not paired with a menu_floor \
1919+ call -- every darkroom menu must clamp both its anchor and its \
1920+ list room together"
1921+ );
1922+ assert!(sizings > 0, "{file} no longer opens any menu -- update this guard");
1923+ }
1924+}
crates/app/src/ui/library.rsmodified+7 -7
@@ -3,7 +3,7 @@
33 use crate::*;
44 use crate::ui::widgets::*;
55 use crate::ui::type_scale::Typeset;
6-use crate::ui::stance::below_picture_floor;
6+use crate::ui::stance::menu_floor;
77
88 impl Player {
99 /// The media library: a row per source the timeline knows, in the order
@@ -684,12 +684,12 @@ impl Player {
684684 }
685685 }
686686 // Placed by the height it is drawn to, and drawn to what the window has
687- // room for -- the clip menu's rule, one function for all three.
688- let list_h = menu_rows_h(rows.len(), viewport);
689- let mut at = menu.at;
690- if darkroom {
691- at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height))));
692- }
687+ // room for -- the clip menu's rule, one function for all three. The
688+ // floor clamp and the room the list sizes against are `menu_floor`'s,
689+ // so a menu taller than the footprint scrolls instead of climbing
690+ // back over the picture.
691+ let (at, room) = menu_floor(menu.at, viewport, darkroom);
692+ let list_h = menu_rows_h(rows.len(), room);
693693 let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h);
694694 let full: SharedString = path.display().to_string().into();
695695 Some(
crates/app/src/ui/overlays.rsmodified+9 -12
@@ -2,7 +2,7 @@
22
33 use crate::*;
44 use crate::ui::widgets::*;
5-use crate::ui::stance::below_picture_floor;
5+use crate::ui::stance::menu_floor;
66 use crate::ui::type_scale::{self, Typeset};
77
88 impl Player {
@@ -662,16 +662,16 @@ impl Player {
662662 // The height the card is *placed* by and the height its list is drawn
663663 // to are one number: placed by a taller one, the card would hang off the
664664 // window's floor -- the very thing the clamp is for.
665- let list_h = menu_rows_h(rows.len(), viewport);
666665 // §5/§11 check 6: the picture is never covered. A right-click high on
667666 // the window would otherwise hang the menu at the pointer, straight
668667 // over the screen -- clamped below it into the bench/ledger/dock
669668 // footprint instead, darkroom only (the legacy tree has no such
670- // fixed split to clamp against).
671- let mut at = menu.at;
672- if self.darkroom {
673- at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height))));
674- }
669+ // fixed split to clamp against). The list is sized against that same
670+ // footprint (`room`), not the whole window, so a menu taller than
671+ // the footprint scrolls inside its own plate instead of walking its
672+ // clamped top edge back up over the picture ([`menu_floor`]).
673+ let (at, room) = menu_floor(menu.at, viewport, self.darkroom);
674+ let list_h = menu_rows_h(rows.len(), room);
675675 let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h);
676676 let full: SharedString = source
677677 .map(|source| source.path.display().to_string())
@@ -832,11 +832,8 @@ impl Player {
832832 .collect();
833833 // The window's own room, and the list scrolls only where the window has
834834 // none -- the clip menu's rule, one function for both.
835- let list_h = menu_rows_h(rows.len(), viewport);
836- let mut at = picker.at;
837- if darkroom {
838- at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height))));
839- }
835+ let (at, room) = menu_floor(picker.at, viewport, darkroom);
836+ let list_h = menu_rows_h(rows.len(), room);
840837 let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h);
841838 Some(
842839 scrim()
crates/app/src/ui/stance.rsmodified+54 -0
@@ -42,6 +42,60 @@ pub(crate) fn below_picture_floor(viewport_h: f32) -> f32 {
4242 (viewport_h - TIME_BAND_H - BENCH_H - LEDGER_H).max(0.)
4343 }
4444
45+/// The floor-clamped placement for every scrolling menu (clip context menu,
46+/// picker, library menu): the anchor pulled down to [`below_picture_floor`]
47+/// *and* the room its list may fill capped to what is actually left between
48+/// that floor and the window's bottom edge -- not the whole viewport. Passing
49+/// the untouched viewport to `menu_rows_h` let a menu taller than the
50+/// bench/ledger/dock footprint size itself against the full window, and then
51+/// `menu_at`'s own bottom-edge clamp (`v.min(room - size)`) pulled the
52+/// already-floored top edge back up over the picture to make it fit -- the
53+/// menu-occlusion defect this exists to close. Sizing the list against the
54+/// room *below the floor* instead means it never needs more than that room,
55+/// so `menu_at` never has a reason to walk it back up; a list still taller
56+/// than the room scrolls inside its own plate, same as the keys overlay.
57+/// Darkroom only -- the legacy tree has no fixed split to clamp against.
58+pub(crate) fn menu_floor(
59+ at: Point<Pixels>,
60+ viewport: Size<Pixels>,
61+ darkroom: bool,
62+) -> (Point<Pixels>, Size<Pixels>) {
63+ if !darkroom {
64+ return (at, viewport);
65+ }
66+ let floor = below_picture_floor(f32::from(viewport.height));
67+ let at = point(at.x, px(f32::from(at.y).max(floor)));
68+ let room = size(viewport.width, px(f32::from(viewport.height) - floor));
69+ (at, room)
70+}
71+
72+#[cfg(test)]
73+mod menu_floor_tests {
74+ use super::*;
75+
76+ /// The defect measured live: a 396px-tall menu anchored high in a 720px
77+ /// window used to size itself against the full window (720), so
78+ /// `menu_at`'s bottom clamp walked its floored top edge back up to
79+ /// 720-396=324 -- 10px above the picture's own floor (404 at this
80+ /// window height: 720-88-200-28). The room handed to the list sizer must
81+ /// now be capped to the footprint (316px here), so the placed top edge
82+ /// never leaves the floor.
83+ #[test]
84+ fn a_menu_taller_than_the_footprint_stays_pinned_to_the_floor_not_walked_back_over_it() {
85+ let viewport = size(px(1280.), px(720.));
86+ let floor = below_picture_floor(f32::from(viewport.height));
87+ let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, true);
88+ assert_eq!(f32::from(at.y), floor);
89+ // 396px of rows (the charter's measured menu height) does not fit in
90+ // the 316px footprint room, so it must be capped to it, not the
91+ // window's 720.
92+ let list_h = (396f32).min(f32::from(room.height));
93+ assert!(list_h <= f32::from(room.height));
94+ let (_, y) = crate::oracle::menu_at(at, viewport, list_h);
95+ assert_eq!(y, floor, "the top edge must not be walked back above the floor");
96+ }
97+}
98+
4599 thread_local! {
46100 // FAULT 3: the picture region's own laid-out box, measured each frame by
47101 // a [`bounds_probe`] the same shape `timeband_stance`'s contact strip