A menu fits the room it is allowed
Browse files at this commit9585160d8914965d14280a2536173a7bfe8a35adParent: d0ddef0- fix
- a menu fits the room it is allowed
4 changed files +103 -19
- crates/app/src/tests/layout.rs +33 -0
- crates/app/src/ui/library.rs +7 -7
- crates/app/src/ui/overlays.rs +9 -12
- crates/app/src/ui/stance.rs +54 -0
crates/app/src/tests/layout.rsmodified+33 -0
| @@ -1889,3 +1889,36 @@ fn the_darkroom_path_never_lets_a_notice_surface_reach_the_picture() { | |||
| 1889 | the darkroom stance would paint it over the picture again" | 1889 | the darkroom stance would paint it over the picture again" |
| 1890 | ); | 1890 | ); |
| 1891 | } | 1891 | } |
| 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 @@ | |||
| 3 | use crate::*; | 3 | use crate::*; |
| 4 | use crate::ui::widgets::*; | 4 | use crate::ui::widgets::*; |
| 5 | use crate::ui::type_scale::Typeset; | 5 | use crate::ui::type_scale::Typeset; |
| 6 | -use crate::ui::stance::below_picture_floor; | 6 | +use crate::ui::stance::menu_floor; |
| 7 | 7 | ||
| 8 | impl Player { | 8 | impl Player { |
| 9 | /// The media library: a row per source the timeline knows, in the order | 9 | /// The media library: a row per source the timeline knows, in the order |
| @@ -684,12 +684,12 @@ impl Player { | |||
| 684 | } | 684 | } |
| 685 | } | 685 | } |
| 686 | // Placed by the height it is drawn to, and drawn to what the window has | 686 | // 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. | 687 | + // room for -- the clip menu's rule, one function for all three. The |
| 688 | - let list_h = menu_rows_h(rows.len(), viewport); | 688 | + // floor clamp and the room the list sizes against are `menu_floor`'s, |
| 689 | - let mut at = menu.at; | 689 | + // so a menu taller than the footprint scrolls instead of climbing |
| 690 | - if darkroom { | 690 | + // back over the picture. |
| 691 | - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); | 691 | + let (at, room) = menu_floor(menu.at, viewport, darkroom); |
| 692 | - } | 692 | + let list_h = menu_rows_h(rows.len(), room); |
| 693 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); | 693 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); |
| 694 | let full: SharedString = path.display().to_string().into(); | 694 | let full: SharedString = path.display().to_string().into(); |
| 695 | Some( | 695 | Some( |
crates/app/src/ui/overlays.rsmodified+9 -12
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | use crate::*; | 3 | use crate::*; |
| 4 | use crate::ui::widgets::*; | 4 | use crate::ui::widgets::*; |
| 5 | -use crate::ui::stance::below_picture_floor; | 5 | +use crate::ui::stance::menu_floor; |
| 6 | use crate::ui::type_scale::{self, Typeset}; | 6 | use crate::ui::type_scale::{self, Typeset}; |
| 7 | 7 | ||
| 8 | impl Player { | 8 | impl Player { |
| @@ -662,16 +662,16 @@ impl Player { | |||
| 662 | // The height the card is *placed* by and the height its list is drawn | 662 | // The height the card is *placed* by and the height its list is drawn |
| 663 | // to are one number: placed by a taller one, the card would hang off the | 663 | // to are one number: placed by a taller one, the card would hang off the |
| 664 | // window's floor -- the very thing the clamp is for. | 664 | // window's floor -- the very thing the clamp is for. |
| 665 | - let list_h = menu_rows_h(rows.len(), viewport); | ||
| 666 | // §5/§11 check 6: the picture is never covered. A right-click high on | 665 | // §5/§11 check 6: the picture is never covered. A right-click high on |
| 667 | // the window would otherwise hang the menu at the pointer, straight | 666 | // the window would otherwise hang the menu at the pointer, straight |
| 668 | // over the screen -- clamped below it into the bench/ledger/dock | 667 | // over the screen -- clamped below it into the bench/ledger/dock |
| 669 | // footprint instead, darkroom only (the legacy tree has no such | 668 | // footprint instead, darkroom only (the legacy tree has no such |
| 670 | - // fixed split to clamp against). | 669 | + // fixed split to clamp against). The list is sized against that same |
| 671 | - let mut at = menu.at; | 670 | + // footprint (`room`), not the whole window, so a menu taller than |
| 672 | - if self.darkroom { | 671 | + // the footprint scrolls inside its own plate instead of walking its |
| 673 | - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); | 672 | + // clamped top edge back up over the picture ([`menu_floor`]). |
| 674 | - } | 673 | + let (at, room) = menu_floor(menu.at, viewport, self.darkroom); |
| 674 | + let list_h = menu_rows_h(rows.len(), room); | ||
| 675 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); | 675 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); |
| 676 | let full: SharedString = source | 676 | let full: SharedString = source |
| 677 | .map(|source| source.path.display().to_string()) | 677 | .map(|source| source.path.display().to_string()) |
| @@ -832,11 +832,8 @@ impl Player { | |||
| 832 | .collect(); | 832 | .collect(); |
| 833 | // The window's own room, and the list scrolls only where the window has | 833 | // The window's own room, and the list scrolls only where the window has |
| 834 | // none -- the clip menu's rule, one function for both. | 834 | // none -- the clip menu's rule, one function for both. |
| 835 | - let list_h = menu_rows_h(rows.len(), viewport); | 835 | + let (at, room) = menu_floor(picker.at, viewport, darkroom); |
| 836 | - let mut at = picker.at; | 836 | + let list_h = menu_rows_h(rows.len(), room); |
| 837 | - if darkroom { | ||
| 838 | - at.y = px(f32::from(at.y).max(below_picture_floor(f32::from(viewport.height)))); | ||
| 839 | - } | ||
| 840 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); | 837 | let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); |
| 841 | Some( | 838 | Some( |
| 842 | scrim() | 839 | scrim() |
crates/app/src/ui/stance.rsmodified+54 -0
| @@ -42,6 +42,60 @@ pub(crate) fn below_picture_floor(viewport_h: f32) -> f32 { | |||
| 42 | (viewport_h - TIME_BAND_H - BENCH_H - LEDGER_H).max(0.) | 42 | (viewport_h - TIME_BAND_H - BENCH_H - LEDGER_H).max(0.) |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 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 | + | ||
| 45 | thread_local! { | 99 | thread_local! { |
| 46 | // FAULT 3: the picture region's own laid-out box, measured each frame by | 100 | // FAULT 3: the picture region's own laid-out box, measured each frame by |
| 47 | // a [`bounds_probe`] the same shape `timeband_stance`'s contact strip | 101 | // a [`bounds_probe`] the same shape `timeband_stance`'s contact strip |