From a333a46d58a8397b58a057a5ed4b219592576398 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 06:12:15 +0300 Subject: [PATCH] fix(ui): 20 Hz stops wrapping and a maximized EQ card stops hiding its own controls The end-tick anchor fix left the boxes at a fixed 24px, narrower than "20 Hz" at the dark theme's 11px mono, so it wrapped to two lines instead of clipping. Widened both end boxes to their own label's width at the size they draw (eq_tick_end_w, derived from the list-truncation ladder's existing chars-to-pixels ratio so a future type-scale bump widens the box instead of re-wrapping it), plus whitespace_nowrap() as a backstop. The maximized EQ graph also claimed a flat EQ_GRAPH_MAX_H slice regardless of how much room a small bench actually left, pushing the Band/Flatten/Spectrum rows into a scroll the docked card never needed at the same bench. The graph now flex_1()s between the docked floor and the maximized ceiling, taking whatever room the rows below it leave over instead of claiming a fixed slice first. --- crates/app/src/audio_cards.rs | 59 +++++++++++++++++++++++++++++++++++ crates/app/src/ui/cards.rs | 40 ++++++++++++++++++++---- 2 files changed, 93 insertions(+), 6 deletions(-) diff --git a/crates/app/src/audio_cards.rs b/crates/app/src/audio_cards.rs index 08189d4..daf7f66 100644 --- a/crates/app/src/audio_cards.rs +++ b/crates/app/src/audio_cards.rs @@ -188,6 +188,65 @@ pub(crate) const EQ_TICKS: [(f32, &str); 5] = [ /// named at the corners instead. pub(crate) const EQ_DB_GRID: [f32; 2] = [6., -6.]; +/// How wide an end tick's own label box has to be so "20 Hz" reads as one +/// line rather than wrapping onto two ("20" over "Hz") -- driven live and +/// found doing exactly that at a fixed 24 px box once the end ticks were +/// anchored to the graph's edge instead of centred on it (the anchor alone +/// was not the whole fix). Sized off the label's own character count at the +/// size it is actually drawn, using the list-truncation ladder's already +/// -calibrated characters-to-pixels ratio ([`crate::layout::LIST_CHAR_W`] at +/// [`crate::ui::type_scale::CHORD_METADATA_MIN_PX`]) rather than a second +/// magic pixel count -- so a future type-scale bump (this one already moved +/// once this session) widens the box along with the text instead of +/// re-wrapping it. +pub(crate) fn eq_tick_end_w(label: &str, text_px: f32) -> f32 { + label.chars().count() as f32 * crate::layout::LIST_CHAR_W + / crate::ui::type_scale::CHORD_METADATA_MIN_PX + * text_px +} + +#[cfg(test)] +mod eq_graph_maximize_tests { + use super::*; + + /// D2's regression class: the maximized card revealed LESS than docked + /// at the same bench, because the graph claimed a fixed slice (a flat + /// `EQ_GRAPH_MAX_H`) that left nothing for the rows below it, forcing a + /// scroll docked never needed at the same bench. This binary has no + /// `TestAppContext`, so it cannot read the flex layout gpui actually + /// paints back -- this is a value-level pin on the two numbers the fix + /// (`crates/app/src/ui/cards.rs`'s `graph_maximized` branch, `flex_1()` + /// between a floor and a ceiling rather than a fixed height) depends on, + /// not a substitute for driving a maximize at a small bench: the + /// maximized graph's floor must be the *same* constant docked draws its + /// fixed height at (so maximized can never show less graph than docked, + /// whatever room is left over for the graph to grow into), and that + /// floor must not exceed its own ceiling (an inverted `min_h`/`max_h` + /// clamp is a layout-time panic, not a compile-time one). + #[test] + fn maximized_graph_floor_matches_docked_and_never_exceeds_its_own_ceiling() { + assert_eq!(eq_graph_h(false), EQ_GRAPH_H, "docked height must be the floor maximized also uses"); + assert!(EQ_GRAPH_H <= EQ_GRAPH_MAX_H); + } +} + +#[cfg(test)] +mod eq_tick_end_w_tests { + use super::*; + + /// The defect measured live: a fixed 24 px box wrapped "20 Hz" (5 chars) + /// at the dark theme's 11 px end-tick size. The derived width must clear + /// that box, and must grow, not shrink, if a future scale bump raises + /// the size fed in. + #[test] + fn wide_enough_for_the_widest_end_label_and_grows_with_the_type_scale() { + let dark_w = eq_tick_end_w("20 Hz", crate::ui::type_scale::CHORD_METADATA_MIN_PX); + assert!(dark_w > 24., "{dark_w} must clear the old fixed box"); + let bumped_w = eq_tick_end_w("20 Hz", crate::ui::type_scale::CHORD_METADATA_MIN_PX + 4.); + assert!(bumped_w > dark_w); + } +} + /// How many played samples one spectrum frame is transformed from. A power of /// two ([`fft`] is radix-2) and the whole of the engine's tap: 1024 at 48 kHz diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index de1e0f2..2c66462 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -1377,14 +1377,24 @@ impl Player { })) }) .collect(); + // Maximized used to claim a fixed 320 px slice for the graph + // regardless of how much room a small bench actually left the card, + // so the numbers/buttons rows below it were the ones squeezed into a + // scroll -- docked, at the same bench, showed all of them with no + // scroll at all. `flex_1` between the docked floor and the maximized + // ceiling lets the graph take whatever is *actually* left after the + // rows below it claim their own natural height first, the same + // leftover-space idiom `dock_stance::dock_sources` already uses for + // its own scroll region. + let graph_maximized = dark && self.card_maximized; let graph = div() // Ided like the band rows it replaces: what the pointer presses on // is one element with its own hitbox, which is what a drag is // tracked from. .id("eq-graph") .relative() - .flex_none() - .h(px(eq_graph_h(dark && self.card_maximized))) + .when(graph_maximized, |d| d.flex_1().min_h(px(EQ_GRAPH_H)).max_h(px(EQ_GRAPH_MAX_H))) + .when(!graph_maximized, |d| d.flex_none().h(px(eq_graph_h(false)))) .rounded(px(3.)) .bg(rgb(if dark { DARK_HAIRLINE() } else { BG_HOVER_DIM() })) .cursor_pointer() @@ -1472,13 +1482,20 @@ impl Player { // bare "z", "20k" lost its "k" and half its trailing "0". // Anchored to the graph's own edge instead and read inward, // both now sit wholly inside the plot they label. - let div = div().absolute().bottom(px(1.)).w(px(24.)); + // The end boxes are widened to their own label at the size + // they draw at (`eq_tick_end_w`), not just anchored -- an + // anchor alone still let "20 Hz" wrap onto two lines inside + // a box narrower than the text. `.whitespace_nowrap()` is + // the platform's own backstop, so a mis-measured box clips + // or overhangs instead of silently wrapping again. + let end_px = if dark { type_scale::CHORD_METADATA_MIN_PX } else { 9. }; + let div = div().absolute().bottom(px(1.)).whitespace_nowrap(); let div = if i == 0 { - div.left(px(0.)).text_align(TextAlign::Left) + div.w(px(eq_tick_end_w(label, end_px))).left(px(0.)).text_align(TextAlign::Left) } else if i == EQ_TICKS.len() - 1 { - div.right(px(0.)).text_align(TextAlign::Right) + div.w(px(eq_tick_end_w(label, end_px))).right(px(0.)).text_align(TextAlign::Right) } else { - div.left(relative(eq_x(*freq))).ml(px(-12.)).text_align(TextAlign::Center) + div.w(px(24.)).left(relative(eq_x(*freq))).ml(px(-12.)).text_align(TextAlign::Center) }; div .when(dark, |d| { @@ -1551,6 +1568,11 @@ impl Player { // ran off the top and its buttons off the bottom, with // neither reachable. Capped here, scrolled below. .max_h(relative(1.)) + // Maximized also *claims* the room the cap above + // only allows: `flex_1()`/`max_h` on the graph below + // has nothing to grow into if the card itself still + // hugs its own content height. + .when(graph_maximized, |d| d.h(relative(1.))) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() @@ -1566,6 +1588,12 @@ impl Player { // makes the cap above a scroll rather than a // clip; the rows themselves keep their heights. .min_h(px(0.)) + // Maximized: stretch to the room the card + // above now claims, so the graph's own + // `flex_1` (above) has the leftover space to + // grow into instead of the card just hugging + // its content and leaving none. + .when(graph_maximized, |d| d.flex_1()) .overflow_y_scroll() .track_scroll(&self.eq_scroll) .flex()