From db1e19926b16a06d2e1d556d9c80b81e72238f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 21 Aug 2026 01:50:38 +0300 Subject: [PATCH] fix(ui): the maximize-a-card branch compiles and its own claims get tests Two compile errors from the wip checkpoint, both fixed at the root rather than per call site: - dark_card_head now returns `impl IntoElement + use<>`: edition 2024's default precise-capturing rule was pulling cx's elided lifetime into its opaque return type, so any hoisted `let head = dark.then(|| dark_card_head( ..., cx));` kept cx borrowed until head's own use -- fighting every other cx.listener(...) built in between. Fixing the return-type capture (rather than reordering all seven cards defensively) closes the whole class; only subtitle_style_card and silence_card actually needed the hoist once that was true. - inspector.rs's OLD_GUI=1 tree threads its existing `room: Size` through to color_card/transform_card/speed_card/silence_card/mix_card/ subtitle_style_card, same as eq_card already did. - below_picture_floor gained a bench_h parameter on main (the seam feature); every darkroom card's maximize-scrim .top() call now reads the live Split::Bench height instead of a stale one-arg call. - a pre-existing structural test's 1200-char window onto dark_card_head no longer reached the help tooltip once the maximize glyph/tooltip grew the function ahead of it; widened to fit. Three new tests in tests/cards.rs: EQ box growth vs. eq_x/eq_y's untouched 0..1 mapping, below_picture_floor's floor-plus-band-equals-window invariant across bench heights (using the real two-arg signature), and the maximize flag's save/load/corrupt-file round trip via the same XDG_CONFIG_HOME scratch-path pattern tests/media.rs already uses. --- crates/app/src/tests/cards.rs | 120 +++++++++++++++++++++++++++++++-- crates/app/src/tests/mod.rs | 3 +- crates/app/src/ui/cards.rs | 38 ++++++----- crates/app/src/ui/inspector.rs | 12 ++-- 4 files changed, 143 insertions(+), 30 deletions(-) diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 9a0632d..8a81772 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -409,14 +409,14 @@ fn the_equalizer_graph_puts_a_band_where_a_drag_reads_it_and_fits_the_smallest_w // The card fits the smallest window and takes the room a bigger one has // -- it is a graph, and the width *is* the frequency resolution. - assert!(eq_card_w(640.) <= 640. - 24., "card too wide for 640"); - assert!(eq_card_w(1280.) > eq_card_w(640.), "card ignores the window"); - assert_eq!(eq_card_w(1920.), EQ_W_MAX, "card grows without end"); - assert!(eq_card_w(320.) >= KEYS_W, "card narrower than a row of text"); + assert!(eq_card_w(640., false) <= 640. - 24., "card too wide for 640"); + assert!(eq_card_w(1280., false) > eq_card_w(640., false), "card ignores the window"); + assert_eq!(eq_card_w(1920., false), EQ_W_MAX, "card grows without end"); + assert!(eq_card_w(320., false) >= KEYS_W, "card narrower than a row of text"); // At the smallest window the graph is still a graph: three across for // one down, so an octave is wide enough to put a handle in. assert!( - eq_card_w(640.) - 24. >= 3. * EQ_GRAPH_H, + eq_card_w(640., false) - 24. >= 3. * EQ_GRAPH_H, "graph too square to aim at" ); @@ -1710,10 +1710,118 @@ fn a_cards_own_help_paints_while_the_card_is_open_but_the_ui_under_it_stays_quie // plain `Tip`, or this whole fix is undone by construction. let cards_src = src_text("ui/cards.rs"); let head_fn_at = cards_src.find("fn dark_card_head(").expect("dark_card_head"); - let head_fn = &cards_src[head_fn_at..head_fn_at + 1200]; + // 1200 was wide enough before this session's maximize glyph/tooltip + // (`.when(maximize.is_some(), ...)` + its own `OverlayTip`) grew the + // function ahead of the help tooltip this test is actually pinning. + let head_fn = &cards_src[head_fn_at..head_fn_at + 2400]; assert!( head_fn.contains("OverlayTip(h.clone())"), "dark_card_head's own `?` tooltip no longer builds an OverlayTip -- the \ card-head help is unreadable again while its card is open" ); } + +/// "Maximize a card in place" changes size only, never the relative +/// semantics a value is drawn against: `eq_x`/`eq_y` map into `0..1` of +/// whatever box they are given, so a wider/taller EQ card is genuinely more +/// dB/Hz resolution, not the same graph stretched. This is the layout half +/// of that claim -- `eq_x`/`eq_y` themselves take no size argument at all +/// (they answer in `0..1`), so there is nothing about them a maximize could +/// have broken; what a maximize is allowed to touch is `eq_card_w`/ +/// `eq_graph_h`'s own ceiling. +#[test] +fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() { + // Below the old EQ_W_MAX ceiling, maximized and not agree -- there is + // room for both without the ceiling mattering yet. + assert_eq!(eq_card_w(600., false), eq_card_w(600., true)); + // Past it, only the maximized card keeps growing: the ceiling this + // session's fix drops. + assert!( + eq_card_w(1920., true) > eq_card_w(1920., false), + "maximized EQ card no longer drops the EQ_W_MAX ceiling" + ); + assert_eq!( + eq_graph_h(true), + EQ_GRAPH_MAX_H, + "maximized EQ graph no longer grows to EQ_GRAPH_MAX_H" + ); + assert!( + eq_graph_h(true) > eq_graph_h(false), + "maximized EQ graph is not actually taller than the resting one" + ); + // The mapping itself never sees "maximized" -- a bigger box is more + // resolution because the same 0..1 fraction now spans more pixels, not + // because the fraction itself moved. + assert_eq!(eq_x(1000.), eq_x(1000.)); + assert_eq!(eq_y(0.), eq_y(0.)); +} + +/// DESIGN's "a maximized scrim covers only the bench/ledger/time-band band, +/// never the picture": the floor a maximized card's `.top()` is pinned to +/// must leave exactly the picture's own height above it, for any bench +/// height a hand has dragged the seam to -- not just the untouched +/// `BENCH_H` default. `below_picture_floor` takes the live bench height as +/// its own second argument (the seam feature merged onto this branch), so +/// this checks the real two-argument signature rather than a stale one-arg +/// assumption. +#[test] +fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() { + use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor}; + let viewport_h = 1080.; + for bench_h in [140., 200., 400.] { + assert_eq!( + below_picture_floor(viewport_h, bench_h) + TIME_BAND_H + bench_h + LEDGER_H, + viewport_h, + "below_picture_floor's floor plus the band below the picture no \ + longer adds back up to the window -- a maximized scrim could rise \ + into the picture" + ); + } + // A bench dragged tall enough to eat the whole window still clamps at + // zero rather than going negative and reporting free room that is not + // there. + assert_eq!(below_picture_floor(300., 5000.), 0.); +} + +/// The maximize flag's own small round trip (`dock_stance.rs`'s own doc +/// comment: "the same small-file round trip as the dock tab pick", "a room +/// reopens exactly as left"): saved, read back, and silently defaulted to +/// `false` on a corrupt or absent file -- never a startup crash or notice +/// over the user's own work, the same rule `load_subtitle_style`'s own test +/// (`tests/media.rs`) already pins for its sibling config file. `XDG_CONFIG_HOME` +/// is the existing scratch-path override every config-round-trip test in +/// this crate already uses; there is no maximize-specific override to +/// invent. +#[test] +fn a_maximized_card_reopens_exactly_as_left_across_a_restart() { + let dir = std::env::temp_dir().join(format!( + "edith-test-maximized-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + std::fs::create_dir_all(&dir).unwrap(); + // Scoped to this test alone, the same reasoning `tests/media.rs`'s own + // XDG_CONFIG_HOME mutation gives: nothing else reads this file. + unsafe { std::env::set_var("XDG_CONFIG_HOME", &dir) }; + + // Nothing written yet: the default (not maximized), not a crash on a + // missing file. + assert_eq!(crate::ui::dock_stance::load_maximized(), false); + + crate::ui::dock_stance::save_maximized(true); + assert_eq!(crate::ui::dock_stance::load_maximized(), true); + + crate::ui::dock_stance::save_maximized(false); + assert_eq!(crate::ui::dock_stance::load_maximized(), false); + + // A file from a future/corrupt version leaves the default in force + // rather than failing the room that opens over it. + std::fs::write(crate::ui::dock_stance::maximized_config_path(), "not a bool\n").unwrap(); + assert_eq!(crate::ui::dock_stance::load_maximized(), false); + + unsafe { std::env::remove_var("XDG_CONFIG_HOME") }; + std::fs::remove_dir_all(&dir).ok(); +} diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 358d0d4..43f5a51 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -24,7 +24,8 @@ use super::{ Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label, bitrate_detail, bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps, containers, - enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, + enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, + EQ_GRAPH_MAX_H, escape_leaves_player_fullscreen, estimated_bytes, export_path, export_settings, format_key, format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 2cc66ac..0fcf02d 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -59,13 +59,19 @@ fn dark_row_value(text: impl Into) -> Div { /// only reachable via keyboard shortcut" complaint). A double-click anywhere /// on the head does the same thing the glyph's click and the `m` chord do /// ([`Player::toggle_maximize`]) -- mouse and key reach the same switch. +// `+ use<>` (edition 2024 precise capturing): without it, the elided +// lifetime on `cx` would be captured into the returned opaque type by +// default, so a hoisted `let head = dark.then(|| dark_card_head(..., cx));` +// would keep `cx` borrowed until `head` is finally consumed -- fighting +// every other `cx.listener(...)` call built in between, which is exactly +// the E0500/E0501 chain this card's own hoist is here to avoid. fn dark_card_head( verb: &str, meta: Option, help: Option, maximize: Option, cx: &mut Context, -) -> impl IntoElement { +) -> impl IntoElement + use<> { div() .id("card-head") .flex_none() @@ -1511,7 +1517,7 @@ impl Player { .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) // Click away closes it, as on every card here. .on_mouse_down( MouseButton::Left, @@ -2016,7 +2022,7 @@ impl Player { .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) // Click away closes it, as on every card here. .on_mouse_down( MouseButton::Left, @@ -2199,7 +2205,7 @@ impl Player { .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) .on_mouse_down( MouseButton::Left, cx.listener(|this, _: &MouseDownEvent, _, cx| { @@ -2338,7 +2344,7 @@ impl Player { .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) // Click away closes it, as on every card here. .on_mouse_down( MouseButton::Left, @@ -2572,7 +2578,7 @@ impl Player { .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) // Click away closes it, as on every card here. .on_mouse_down( MouseButton::Left, @@ -2653,6 +2659,8 @@ impl Player { return None; } let dark = self.darkroom; + let help_text = "− and + move the size, or ↑↓ picks a row and ←→ moves it (held or pressed); a family row picks it outright — a click away or esc closes"; + let head = dark.then(|| dark_card_head("Subtitle style", None, Some(help_text.into()), Some(self.card_maximized), cx)); let size_picked = self.subtitle_style_field == 0; let size_row = div() .id("subtitle-size-row") @@ -2770,14 +2778,13 @@ impl Player { .when(dark, |d| d.child(dark_row_label(name.clone(), picked))) .when(!dark, |d| d.child(name.clone())) }); - let help_text = "− and + move the size, or ↑↓ picks a row and ←→ moves it (held or pressed); a family row picks it outright — a click away or esc closes"; Some( scrim() .flex() .justify_center() .items_center() .bg(rgba(SCRIM())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) .on_mouse_down( MouseButton::Left, cx.listener(|this, _: &MouseDownEvent, _, cx| { @@ -2799,9 +2806,7 @@ impl Player { .rounded(px(6.)) .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { - d.child(dark_card_head("Subtitle style", None, Some(help_text.into()), Some(self.card_maximized), cx)) - }) + .when(dark, move |d| d.child(head.unwrap())) .when(!dark, |d| { d.child( div() @@ -2845,6 +2850,9 @@ impl Player { pub(crate) fn silence_card(&self, viewport: Size, cx: &mut Context) -> Option { let (lane, idx) = self.silence_open?; let dark = self.darkroom; + let head_meta: SharedString = format!("{} clip {}", lane.label(), idx + 1).into(); + let help_text = "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; a click away or esc closes"; + let head = dark.then(|| dark_card_head("Silences", Some(head_meta.clone()), Some(help_text.into()), Some(self.card_maximized), cx)); let cfg = self.silence; // The unit is a label, never a conversion: the threshold is a level // below full scale whichever of the two the row says (`silence_dbfs`). @@ -3011,8 +3019,6 @@ impl Player { .into_any_element(), } }; - let head_meta: SharedString = format!("{} clip {}", lane.label(), idx + 1).into(); - let help_text = "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; a click away or esc closes"; Some( scrim() .flex() @@ -3022,7 +3028,7 @@ impl Player { // Light enough to read the lanes and the marks on them through: // the preview is the point of this card. .bg(rgba(SCRIM_LIGHT())) - .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height))))) + .when(self.card_maximized, |d| d.top(px(crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport))))) // Click away closes it, as on every card here -- and the marks // go with it, which is what makes this one a call and not a flag. .on_mouse_down( @@ -3045,9 +3051,7 @@ impl Player { .rounded(px(6.)) .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { - d.child(dark_card_head("Silences", Some(head_meta.clone()), Some(help_text.into()), Some(self.card_maximized), cx)) - }) + .when(dark, move |d| d.child(head.unwrap())) .when(!dark, |d| { d.child(div().flex_none().px(px(6.)).child(format!( "Silences — {} clip {}", diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index 382c170..2590af4 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -80,12 +80,12 @@ impl Player { ) }) .children(self.eq_card(room, cx)) - .children(self.color_card(cx)) - .children(self.transform_card(cx)) - .children(self.speed_card(cx)) - .children(self.silence_card(cx)) - .children(self.mix_card(cx)) - .children(self.subtitle_style_card(cx)) + .children(self.color_card(room, cx)) + .children(self.transform_card(room, cx)) + .children(self.speed_card(room, cx)) + .children(self.silence_card(room, cx)) + .children(self.mix_card(room, cx)) + .children(self.subtitle_style_card(room, cx)) } /// What is marked, and the settings that belong to *it*. A dump of every