forge
Explore
Log in

Don't you dare go Hollow

20 Hz stops wrapping and a maximized EQ card stops hiding its own controls

Browse files at this commit

a333a46d58a8397b58a057a5ed4b219592576398Ahmet Kaan GümüşParent: f429c6e
  • fix
    • 20 Hz stops wrapping and a maximized EQ card stops hiding its own controls
Show full message
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.rsmodified+59 -0
@@ -188,6 +188,65 @@ pub(crate) const EQ_TICKS: [(f32, &str); 5] = [
188188 /// named at the corners instead.
189189 pub(crate) const EQ_DB_GRID: [f32; 2] = [6., -6.];
190190
191+/// How wide an end tick's own label box has to be so "20 Hz" reads as one
192+/// line rather than wrapping onto two ("20" over "Hz") -- driven live and
193+/// found doing exactly that at a fixed 24 px box once the end ticks were
194+/// anchored to the graph's edge instead of centred on it (the anchor alone
195+/// was not the whole fix). Sized off the label's own character count at the
196+/// size it is actually drawn, using the list-truncation ladder's already
197+/// -calibrated characters-to-pixels ratio ([`crate::layout::LIST_CHAR_W`] at
198+/// [`crate::ui::type_scale::CHORD_METADATA_MIN_PX`]) rather than a second
199+/// magic pixel count -- so a future type-scale bump (this one already moved
200+/// once this session) widens the box along with the text instead of
201+/// re-wrapping it.
202+pub(crate) fn eq_tick_end_w(label: &str, text_px: f32) -> f32 {
203+ label.chars().count() as f32 * crate::layout::LIST_CHAR_W
204+ / crate::ui::type_scale::CHORD_METADATA_MIN_PX
205+ * text_px
206+}
207+
208+#[cfg(test)]
209+mod eq_graph_maximize_tests {
210+ use super::*;
211+
212+ /// D2's regression class: the maximized card revealed LESS than docked
213+ /// at the same bench, because the graph claimed a fixed slice (a flat
214+ /// `EQ_GRAPH_MAX_H`) that left nothing for the rows below it, forcing a
215+ /// scroll docked never needed at the same bench. This binary has no
216+ /// `TestAppContext`, so it cannot read the flex layout gpui actually
217+ /// paints back -- this is a value-level pin on the two numbers the fix
218+ /// (`crates/app/src/ui/cards.rs`'s `graph_maximized` branch, `flex_1()`
219+ /// between a floor and a ceiling rather than a fixed height) depends on,
220+ /// not a substitute for driving a maximize at a small bench: the
221+ /// maximized graph's floor must be the *same* constant docked draws its
222+ /// fixed height at (so maximized can never show less graph than docked,
223+ /// whatever room is left over for the graph to grow into), and that
224+ /// floor must not exceed its own ceiling (an inverted `min_h`/`max_h`
225+ /// clamp is a layout-time panic, not a compile-time one).
226+ #[test]
227+ fn maximized_graph_floor_matches_docked_and_never_exceeds_its_own_ceiling() {
228+ assert_eq!(eq_graph_h(false), EQ_GRAPH_H, "docked height must be the floor maximized also uses");
229+ assert!(EQ_GRAPH_H <= EQ_GRAPH_MAX_H);
230+ }
231+}
232+
233+#[cfg(test)]
234+mod eq_tick_end_w_tests {
235+ use super::*;
236+
237+ /// The defect measured live: a fixed 24 px box wrapped "20 Hz" (5 chars)
238+ /// at the dark theme's 11 px end-tick size. The derived width must clear
239+ /// that box, and must grow, not shrink, if a future scale bump raises
240+ /// the size fed in.
241+ #[test]
242+ fn wide_enough_for_the_widest_end_label_and_grows_with_the_type_scale() {
243+ let dark_w = eq_tick_end_w("20 Hz", crate::ui::type_scale::CHORD_METADATA_MIN_PX);
244+ assert!(dark_w > 24., "{dark_w} must clear the old fixed box");
245+ let bumped_w = eq_tick_end_w("20 Hz", crate::ui::type_scale::CHORD_METADATA_MIN_PX + 4.);
246+ assert!(bumped_w > dark_w);
247+ }
248+}
249+
191250
192251 /// How many played samples one spectrum frame is transformed from. A power of
193252 /// two ([`fft`] is radix-2) and the whole of the engine's tap: 1024 at 48 kHz
crates/app/src/ui/cards.rsmodified+34 -6
@@ -1377,14 +1377,24 @@ impl Player {
13771377 }))
13781378 })
13791379 .collect();
1380+ // Maximized used to claim a fixed 320 px slice for the graph
1381+ // regardless of how much room a small bench actually left the card,
1382+ // so the numbers/buttons rows below it were the ones squeezed into a
1383+ // scroll -- docked, at the same bench, showed all of them with no
1384+ // scroll at all. `flex_1` between the docked floor and the maximized
1385+ // ceiling lets the graph take whatever is *actually* left after the
1386+ // rows below it claim their own natural height first, the same
1387+ // leftover-space idiom `dock_stance::dock_sources` already uses for
1388+ // its own scroll region.
1389+ let graph_maximized = dark && self.card_maximized;
13801390 let graph = div()
13811391 // Ided like the band rows it replaces: what the pointer presses on
13821392 // is one element with its own hitbox, which is what a drag is
13831393 // tracked from.
13841394 .id("eq-graph")
13851395 .relative()
1386- .flex_none()
1387- .h(px(eq_graph_h(dark && self.card_maximized)))
1396+ .when(graph_maximized, |d| d.flex_1().min_h(px(EQ_GRAPH_H)).max_h(px(EQ_GRAPH_MAX_H)))
1397+ .when(!graph_maximized, |d| d.flex_none().h(px(eq_graph_h(false))))
13881398 .rounded(px(3.))
13891399 .bg(rgb(if dark { DARK_HAIRLINE() } else { BG_HOVER_DIM() }))
13901400 .cursor_pointer()
@@ -1472,13 +1482,20 @@ impl Player {
14721482 // bare "z", "20k" lost its "k" and half its trailing "0".
14731483 // Anchored to the graph's own edge instead and read inward,
14741484 // both now sit wholly inside the plot they label.
1475- let div = div().absolute().bottom(px(1.)).w(px(24.));
1485+ // The end boxes are widened to their own label at the size
1486+ // they draw at (`eq_tick_end_w`), not just anchored -- an
1487+ // anchor alone still let "20 Hz" wrap onto two lines inside
1488+ // a box narrower than the text. `.whitespace_nowrap()` is
1489+ // the platform's own backstop, so a mis-measured box clips
1490+ // or overhangs instead of silently wrapping again.
1491+ let end_px = if dark { type_scale::CHORD_METADATA_MIN_PX } else { 9. };
1492+ let div = div().absolute().bottom(px(1.)).whitespace_nowrap();
14761493 let div = if i == 0 {
1477- div.left(px(0.)).text_align(TextAlign::Left)
1494+ div.w(px(eq_tick_end_w(label, end_px))).left(px(0.)).text_align(TextAlign::Left)
14781495 } else if i == EQ_TICKS.len() - 1 {
1479- div.right(px(0.)).text_align(TextAlign::Right)
1496+ div.w(px(eq_tick_end_w(label, end_px))).right(px(0.)).text_align(TextAlign::Right)
14801497 } else {
1481- div.left(relative(eq_x(*freq))).ml(px(-12.)).text_align(TextAlign::Center)
1498+ div.w(px(24.)).left(relative(eq_x(*freq))).ml(px(-12.)).text_align(TextAlign::Center)
14821499 };
14831500 div
14841501 .when(dark, |d| {
@@ -1551,6 +1568,11 @@ impl Player {
15511568 // ran off the top and its buttons off the bottom, with
15521569 // neither reachable. Capped here, scrolled below.
15531570 .max_h(relative(1.))
1571+ // Maximized also *claims* the room the cap above
1572+ // only allows: `flex_1()`/`max_h` on the graph below
1573+ // has nothing to grow into if the card itself still
1574+ // hugs its own content height.
1575+ .when(graph_maximized, |d| d.h(relative(1.)))
15541576 .on_mouse_down(MouseButton::Left, swallow)
15551577 .flex()
15561578 .flex_col()
@@ -1566,6 +1588,12 @@ impl Player {
15661588 // makes the cap above a scroll rather than a
15671589 // clip; the rows themselves keep their heights.
15681590 .min_h(px(0.))
1591+ // Maximized: stretch to the room the card
1592+ // above now claims, so the graph's own
1593+ // `flex_1` (above) has the leftover space to
1594+ // grow into instead of the card just hugging
1595+ // its content and leaving none.
1596+ .when(graph_maximized, |d| d.flex_1())
15691597 .overflow_y_scroll()
15701598 .track_scroll(&self.eq_scroll)
15711599 .flex()