20 Hz stops wrapping and a maximized EQ card stops hiding its own controls
Browse files at this commita333a46d58a8397b58a057a5ed4b219592576398Parent: f429c6e- fix
- 20 Hz stops wrapping and a maximized EQ card stops hiding its own controls
2 changed files +93 -6
- crates/app/src/audio_cards.rs +59 -0
- crates/app/src/ui/cards.rs +34 -6
crates/app/src/audio_cards.rsmodified+59 -0
| @@ -188,6 +188,65 @@ pub(crate) const EQ_TICKS: [(f32, &str); 5] = [ | ||
| 188 | 188 | /// named at the corners instead. |
| 189 | 189 | pub(crate) const EQ_DB_GRID: [f32; 2] = [6., -6.]; |
| 190 | 190 | |
| 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 | + | |
| 191 | 250 | |
| 192 | 251 | /// How many played samples one spectrum frame is transformed from. A power of |
| 193 | 252 | /// 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 { | ||
| 1377 | 1377 | })) |
| 1378 | 1378 | }) |
| 1379 | 1379 | .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; | |
| 1380 | 1390 | let graph = div() |
| 1381 | 1391 | // Ided like the band rows it replaces: what the pointer presses on |
| 1382 | 1392 | // is one element with its own hitbox, which is what a drag is |
| 1383 | 1393 | // tracked from. |
| 1384 | 1394 | .id("eq-graph") |
| 1385 | 1395 | .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)))) | |
| 1388 | 1398 | .rounded(px(3.)) |
| 1389 | 1399 | .bg(rgb(if dark { DARK_HAIRLINE() } else { BG_HOVER_DIM() })) |
| 1390 | 1400 | .cursor_pointer() |
| @@ -1472,13 +1482,20 @@ impl Player { | ||
| 1472 | 1482 | // bare "z", "20k" lost its "k" and half its trailing "0". |
| 1473 | 1483 | // Anchored to the graph's own edge instead and read inward, |
| 1474 | 1484 | // 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(); | |
| 1476 | 1493 | 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) | |
| 1478 | 1495 | } 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) | |
| 1480 | 1497 | } 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) | |
| 1482 | 1499 | }; |
| 1483 | 1500 | div |
| 1484 | 1501 | .when(dark, |d| { |
| @@ -1551,6 +1568,11 @@ impl Player { | ||
| 1551 | 1568 | // ran off the top and its buttons off the bottom, with |
| 1552 | 1569 | // neither reachable. Capped here, scrolled below. |
| 1553 | 1570 | .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.))) | |
| 1554 | 1576 | .on_mouse_down(MouseButton::Left, swallow) |
| 1555 | 1577 | .flex() |
| 1556 | 1578 | .flex_col() |
| @@ -1566,6 +1588,12 @@ impl Player { | ||
| 1566 | 1588 | // makes the cap above a scroll rather than a |
| 1567 | 1589 | // clip; the rows themselves keep their heights. |
| 1568 | 1590 | .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()) | |
| 1569 | 1597 | .overflow_y_scroll() |
| 1570 | 1598 | .track_scroll(&self.eq_scroll) |
| 1571 | 1599 | .flex() |