From 9585160d8914965d14280a2536173a7bfe8a35ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 18:02:57 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(ui):=20a=20menu=20fits=20the?= =?UTF-8?q?=20room=20it=20is=20allowed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 33 +++++++++++++++++++++ crates/app/src/ui/library.rs | 14 ++++----- crates/app/src/ui/overlays.rs | 21 ++++++------- crates/app/src/ui/stance.rs | 54 ++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 19 deletions(-) diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 119046f..28640da 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1889,3 +1889,36 @@ fn the_darkroom_path_never_lets_a_notice_surface_reach_the_picture() { the darkroom stance would paint it over the picture again" ); } + +/// DESIGN §5/§11 check 6, the fourth occlusion defect (notice bar, export +/// card, preview badge, now menus): every floating menu that can open above +/// the picture -- the clip context menu, the picker, the library menu -- must +/// size its scrolling list against `stance::menu_floor`'s room, not the raw +/// window. Sizing against the whole viewport is exactly the bug that shipped: +/// a menu taller than the bench/ledger/dock footprint got clamped by +/// `menu_at`'s own bottom-edge fit back up over the picture, because nothing +/// had told the list it only had the footprint to grow into. This pins the +/// general rule so the next surface someone floats -- a fourth menu, a fifth +/// occlusion -- cannot silently reintroduce `menu_rows_h(rows.len(), +/// viewport)` in its place. +#[test] +fn every_darkroom_menu_sizes_its_list_against_the_floor_room_not_the_raw_viewport() { + for file in ["ui/overlays.rs", "ui/library.rs"] { + let text = src_text(file); + assert!( + !text.contains("menu_rows_h(rows.len(), viewport)"), + "{file} sizes a menu's list against the raw viewport again -- \ + route it through stance::menu_floor's room instead, or a tall \ + menu will climb back over the picture" + ); + let floors = text.matches("menu_floor(").count(); + let sizings = text.matches("menu_rows_h(rows.len(),").count(); + assert_eq!( + floors, sizings, + "{file} has a menu list-sizing call not paired with a menu_floor \ + call -- every darkroom menu must clamp both its anchor and its \ + list room together" + ); + assert!(sizings > 0, "{file} no longer opens any menu -- update this guard"); + } +} diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index 83c43fc..8c51a2b 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -3,7 +3,7 @@ use crate::*; use crate::ui::widgets::*; use crate::ui::type_scale::Typeset; -use crate::ui::stance::below_picture_floor; +use crate::ui::stance::menu_floor; impl Player { /// The media library: a row per source the timeline knows, in the order @@ -684,12 +684,12 @@ impl Player { } } // Placed by the height it is drawn to, and drawn to what the window has - // room for -- the clip menu's rule, one function for all three. - let list_h = menu_rows_h(rows.len(), viewport); - let mut at = menu.at; - if darkroom { - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); - } + // room for -- the clip menu's rule, one function for all three. The + // floor clamp and the room the list sizes against are `menu_floor`'s, + // so a menu taller than the footprint scrolls instead of climbing + // back over the picture. + let (at, room) = menu_floor(menu.at, viewport, darkroom); + let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = path.display().to_string().into(); Some( diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index da4d8a2..63ce4f3 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -2,7 +2,7 @@ use crate::*; use crate::ui::widgets::*; -use crate::ui::stance::below_picture_floor; +use crate::ui::stance::menu_floor; use crate::ui::type_scale::{self, Typeset}; impl Player { @@ -662,16 +662,16 @@ impl Player { // The height the card is *placed* by and the height its list is drawn // to are one number: placed by a taller one, the card would hang off the // window's floor -- the very thing the clamp is for. - let list_h = menu_rows_h(rows.len(), viewport); // §5/§11 check 6: the picture is never covered. A right-click high on // the window would otherwise hang the menu at the pointer, straight // over the screen -- clamped below it into the bench/ledger/dock // footprint instead, darkroom only (the legacy tree has no such - // fixed split to clamp against). - let mut at = menu.at; - if self.darkroom { - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); - } + // fixed split to clamp against). The list is sized against that same + // footprint (`room`), not the whole window, so a menu taller than + // the footprint scrolls inside its own plate instead of walking its + // clamped top edge back up over the picture ([`menu_floor`]). + let (at, room) = menu_floor(menu.at, viewport, self.darkroom); + let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = source .map(|source| source.path.display().to_string()) @@ -832,11 +832,8 @@ impl Player { .collect(); // The window's own room, and the list scrolls only where the window has // none -- the clip menu's rule, one function for both. - let list_h = menu_rows_h(rows.len(), viewport); - let mut at = picker.at; - if darkroom { - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); - } + let (at, room) = menu_floor(picker.at, viewport, darkroom); + let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); Some( scrim() diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 2ea0439..4185f57 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -42,6 +42,60 @@ pub(crate) fn below_picture_floor(viewport_h: f32) -> f32 { (viewport_h - TIME_BAND_H - BENCH_H - LEDGER_H).max(0.) } +/// The floor-clamped placement for every scrolling menu (clip context menu, +/// picker, library menu): the anchor pulled down to [`below_picture_floor`] +/// *and* the room its list may fill capped to what is actually left between +/// that floor and the window's bottom edge -- not the whole viewport. Passing +/// the untouched viewport to `menu_rows_h` let a menu taller than the +/// bench/ledger/dock footprint size itself against the full window, and then +/// `menu_at`'s own bottom-edge clamp (`v.min(room - size)`) pulled the +/// already-floored top edge back up over the picture to make it fit -- the +/// menu-occlusion defect this exists to close. Sizing the list against the +/// room *below the floor* instead means it never needs more than that room, +/// so `menu_at` never has a reason to walk it back up; a list still taller +/// than the room scrolls inside its own plate, same as the keys overlay. +/// Darkroom only -- the legacy tree has no fixed split to clamp against. +pub(crate) fn menu_floor( + at: Point, + viewport: Size, + darkroom: bool, +) -> (Point, Size) { + if !darkroom { + return (at, viewport); + } + let floor = below_picture_floor(f32::from(viewport.height)); + let at = point(at.x, px(f32::from(at.y).max(floor))); + let room = size(viewport.width, px(f32::from(viewport.height) - floor)); + (at, room) +} + +#[cfg(test)] +mod menu_floor_tests { + use super::*; + + /// The defect measured live: a 396px-tall menu anchored high in a 720px + /// window used to size itself against the full window (720), so + /// `menu_at`'s bottom clamp walked its floored top edge back up to + /// 720-396=324 -- 10px above the picture's own floor (404 at this + /// window height: 720-88-200-28). The room handed to the list sizer must + /// now be capped to the footprint (316px here), so the placed top edge + /// never leaves the floor. + #[test] + fn a_menu_taller_than_the_footprint_stays_pinned_to_the_floor_not_walked_back_over_it() { + let viewport = size(px(1280.), px(720.)); + let floor = below_picture_floor(f32::from(viewport.height)); + let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, true); + 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)); + assert!(list_h <= f32::from(room.height)); + let (_, y) = crate::oracle::menu_at(at, viewport, list_h); + assert_eq!(y, floor, "the top edge must not be walked back above the floor"); + } +} + thread_local! { // FAULT 3: the picture region's own laid-out box, measured each frame by // a [`bounds_probe`] the same shape `timeband_stance`'s contact strip