fix(gradient_text): honour text-align instead of drawing every line at x=0 - #342
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #337. Closes #157.
The fault
GradientText::paint's draw loop passed a literalx = 0.0and never readstyle.text-align. Agradient_textand atextsharing a box and atext-align: centertherefore disagreed: the plain one centred, the gradientone sat at the box's left edge.
Same rule as
text.rsnow — each line placed within the box width,StartandJustifyfalling 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 whileleaving 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 ownalignment offset is what the endpoints shift by.
#157 is the same component
examples/ferriskey-presentation.jsoncarried the one geometry violation onmain, and it predates this fix:Three parallel stat columns declare
width: 400andfont-size: 122, and~10MBis the widest of the three strings. The font-size parity across thecolumns 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:A third pins the untouched left-aligned default: every scenario written before
this read
gradient_textas left-aligned whatevertext-alignsaid, and a filethat 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 --workspacegreen,clippyandfmtclean.rustmotion validate -f examples/ferriskey-presentation.jsonnow passes bothpasses.
Still open on gradient_text
Nothing here touches #339 (
style.clip-pathread by nothing), which is thethird of the three defects the expression-parity chantier left behind.