fix(render): floor the axes so chrome cannot erase it, one title row per titled axis

Two findings on the pass-1 fix:

- The reserved strips were clamped only to the viewport, so a title wider than a
  narrow panel took the rest of it and the axes collapsed: draw_traces() returned
  on a zero-width rect (no trace drawn, nothing reported) and a zero-height one
  flattened every trace onto a single row. The chrome is now capped at half the
  viewport -- the label strip is served first, the title strip takes what is left
  of that allowance -- an over-long title is clipped to its strip by a walk that
  both measures and stages it, and draw_traces() tests the height as well as the
  width.
- Every titled y axis was staged at the same centred position inside one strip, so
  a Left/Right pair of titles overprinted. Each titled axis now owns a text line:
  the x strip grows one line per titled x axis (x_title_height), and the y runs
  stack down the axes-tall strip, which needs no extra width for it.

Tests: `narrow_panel_with_a_long_y_title_still_draws` and
`short_panel_with_an_x_title_still_draws` pin the floor (the axes keeps half the
panel and the trace still covers the columns, with the title clipped into its
strip), `titled_axis_pairs_get_their_own_rows` pins one text row per titled axis
in both directions, and `layout_stacks_one_title_line_per_titled_axis` pins the
strip sizing. All fail against the pass-1 sources.
This commit is contained in:
Martino Ferrari committed 2026-09-27 23:33:06 +02:00
1 parent 8f45108559
commit 1f5aa11de2
6 files changed
+330 -51

No files matched your search

+9
View File
@@ -202,6 +202,15 @@ class Renderer {
/// Lays one run of text out at a framebuffer position and stages it, shifting
/// it into viewport space. Returns the pen past the run.
Vec2 stage_text(Vec2 pos_px, const char* utf8);
/// Width of the longest prefix of `utf8` that fits `budget_px`, at the size the
/// text pipeline draws with: exactly what `stage_text_clipped()` stages.
f32 clipped_text_width(const char* utf8, f32 budget_px) const;
/// Stages as much of `utf8` as fits `budget_px` at `pos_px` and returns the
/// width it staged. Titles are the runs that need this: a title longer than the
/// strip the layout reserved for it is cut there, rather than being allowed to
/// grow the strip (which would shrink the plot) or to spill over the tick labels
/// and the data (which is the defect the strips exist to prevent).
f32 stage_text_clipped(Vec2 pos_px, const char* utf8, f32 budget_px);
void draw_grid(const Plot& plot);
void draw_axis_lines(const Plot& plot);