Skip to content

fix(number_wheel): resolve text-align instead of always painting from the left - #411

Merged
LeadcodeDev merged 1 commit into
mainfrom
fix/number-wheel-text-align
Sep 28, 2026
Merged

LeadcodeDev merged 1 commit into
mainfrom
fix/number-wheel-text-align

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #410.

Symptom

A number_wheel in a full-width box with text-align: center lands hard against
the left edge, while the text label under it centres correctly.

Cause

paint_content started its draw loop at a literal origin and never read
style.text_align or the layout width:

let mut x = 0.0f32;   // the whole strip is laid out from here

This is the same defect #337 fixed in gradient_text's draw loop. text,
rich_text, counter and gradient_text all resolve alignment against their
box; number_wheel was the one that was missed.

It stayed invisible because NumberWheelIntrinsic shrinks the box to the digits,
so it only shows once the box is wider than the strip — which is exactly when
someone asks for centring.

Fix

Measure the strip's total advance (fixed-glyph widths plus digit_w per reel),
resolve the alignment offset against layout.width, and start the loop there.
A non-finite or non-positive width falls back to the left edge rather than
painting off-screen; that is the case both the intrinsic measure and a degenerate
flex slot produce.

Tests

Test
text_align_center_centres_the_reels_in_the_box ink centre within 6 px of the box centre, left margin > 100 px
text_align_right_ends_the_reels_on_the_box_edge last ink within 8 px of the box edge
no_text_align_still_starts_at_the_box_left_edge the default is unchanged
a_box_with_no_usable_width_falls_back_to_the_left_edge 0, negative, inf, NaN

Reverting the offset to 0.0 fails the first two with the reported symptom:

a centred number_wheel must sit on the box centre 500, painted [3, 130] with centre 66.5
a right-aligned number_wheel must end on the box edge 1000, last ink at 130

Gate

cargo fmt --all --check clean · cargo clippy --workspace --all-targets --features rustmotion/studio -D warnings clean · cargo test --workspace 1771 passed.

… the left

paint_content started its draw loop at a literal origin and never read
style.text_align or the layout width, so a number_wheel in a full-width
box with text-align: center landed at x = 3 while the text label under it
centred correctly.

This is the same defect #337 fixed in gradient_text's draw loop. Every
other text-like leaf -- text, rich_text, counter, gradient_text --
resolves alignment against its box; number_wheel was the one that was
missed. It stayed invisible because NumberWheelIntrinsic shrinks the box
to the digits, so it only shows once the box is wider than the strip,
which is exactly when someone asks for centring.

The strip's total advance is fixed-glyph widths plus digit_w per reel.
A non-finite or non-positive width falls back to the left edge rather
than painting off-screen, which is the case the intrinsic measure and a
degenerate flex slot both produce.
@LeadcodeDev LeadcodeDev added the bug Something isn't working label Sep 28, 2026
@LeadcodeDev LeadcodeDev self-assigned this Sep 28, 2026
@LeadcodeDev
LeadcodeDev merged commit a660e1e into main Sep 28, 2026
4 checks passed
@LeadcodeDev
LeadcodeDev deleted the fix/number-wheel-text-align branch September 28, 2026 09:28
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

Development

Successfully merging this pull request may close these issues.

number_wheel ignores text-align: the reels always paint from the left edge of their box

1 participant