fix(number_wheel): resolve text-align instead of always painting from the left - #411
Merged
Merged
Conversation
… 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.
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 #410.
Symptom
A
number_wheelin a full-width box withtext-align: centerlands hard againstthe left edge, while the
textlabel under it centres correctly.Cause
paint_contentstarted its draw loop at a literal origin and never readstyle.text_alignor the layout width:This is the same defect #337 fixed in
gradient_text's draw loop.text,rich_text,counterandgradient_textall resolve alignment against theirbox;
number_wheelwas the one that was missed.It stayed invisible because
NumberWheelIntrinsicshrinks 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_wper 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
text_align_center_centres_the_reels_in_the_boxtext_align_right_ends_the_reels_on_the_box_edgeno_text_align_still_starts_at_the_box_left_edgea_box_with_no_usable_width_falls_back_to_the_left_edge0, negative,inf,NaNReverting the offset to
0.0fails the first two with the reported symptom:Gate
cargo fmt --all --checkclean ·cargo clippy --workspace --all-targets --features rustmotion/studio -D warningsclean ·cargo test --workspace1771 passed.