Skip to content

fix(gradient_text): honour text-align instead of drawing every line at x=0 - #342

Merged
LeadcodeDev merged 1 commit into
mainfrom
fix/gradient-text-align
Sep 26, 2026
Merged

LeadcodeDev merged 1 commit into
mainfrom
fix/gradient-text-align

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #337. Closes #157.

The fault

GradientText::paint's draw loop passed a literal x = 0.0 and never read
style.text-align. A gradient_text and a text sharing a box and a
text-align: center therefore disagreed: the plain one centred, the gradient
one sat at the box's left edge.

Same rule as text.rs now — each line placed within the box width, Start and
Justify falling back to the left edge like every other left-ish value.

The part that is not obvious

The gradient endpoints had to move with the text. The shader is built once
across the whole block, spanning 0..text_w. Shifting the glyphs right while
leaving the shader pinned at the box's left edge would push a centred block's
last glyphs past the end stop, where they would all come out the clamped final
colour. The block occupies text_w — the widest line — so that line's own
alignment offset is what the endpoints shift by.

#157 is the same component

examples/ferriskey-presentation.json carried the one geometry violation on
main, and it predates this fix:

gradient_text natural width is 404px but only 400px available

Three parallel stat columns declare width: 400 and font-size: 122, and
~10MB is the widest of the three strings. The font-size parity across the
columns is the point of the row, so shrinking one column's type would break the
design; all three boxes widen to 420 instead. Six lines changed.

It is an authoring error, not an engine fault — worth saying plainly, since the
issue title left open which it was.

Verification

Four pixel-level tests, measuring painted ink rather than the offset the code
computes.

Two of them fail against the old x = 0.0, checked by reverting the offset:

centred gradient_text should sit on the box centre 300,
painted [1, 144] with centre 72.5

A third pins the untouched left-aligned default: every scenario written before
this read gradient_text as left-aligned whatever text-align said, and a file
that never set it has to render identically. The fourth catches a fix that moves
the glyphs without moving the gradient, by comparing the last glyph's colour
centred against left-aligned.

cargo test --workspace green, clippy and fmt clean.
rustmotion validate -f examples/ferriskey-presentation.json now passes both
passes.

Still open on gradient_text

Nothing here touches #339 (style.clip-path read by nothing), which is the
third of the three defects the expression-parity chantier left behind.

…t x=0

The draw loop passed a literal `x = 0.0` and never read `style.text-align`,
so a `gradient_text` and a `text` sharing a box and a `text-align: center`
disagreed: the plain one centred, the gradient one sat at the box's left
edge. Same rule as `text.rs` now, `Start`/`Justify` falling back to the left
edge like every other left-ish value.

The gradient endpoints had to move with it. The shader is defined once across
the whole block, so pinned at the box's left edge it would end before a
centred block's last glyphs and they would all come out the clamped end
colour — the block occupies the widest line, so that line's own offset is
what shifts the span.

`examples/ferriskey-presentation.json` carried the first geometry violation
this exposes, and it predates the fix: three parallel stat columns declare
`width: 400` and `font-size: 122`, and `~10MB` measures 404px `nowrap`.
Widening all three to 420 keeps the font-size parity that is the point of the
row, where shrinking one column's type would break it.

Four pixel-level tests. Two of them fail against the old `x = 0.0` (the
centred line painted [1, 144] in a 600px box); the third pins the untouched
left-aligned default, and the fourth catches a fix that moves the glyphs
without moving the gradient.

Closes #337
Closes #157
@LeadcodeDev LeadcodeDev added the bug Something isn't working label Sep 26, 2026
@LeadcodeDev LeadcodeDev self-assigned this Sep 26, 2026
@LeadcodeDev
LeadcodeDev merged commit 9e1828d into main Sep 26, 2026
4 checks passed
@LeadcodeDev
LeadcodeDev deleted the fix/gradient-text-align branch September 26, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant