Skip to content

fix(textblock): Align right-to-left text relative to FlowDirection - #26699

Open
Xiaoy312 wants to merge 7 commits into
masterfrom
dev/xygu/20261124/fix-rtl-textblock-alignment
Open

Xiaoy312 wants to merge 7 commits into
masterfrom
dev/xygu/20261124/fix-rtl-textblock-alignment

Conversation

@Xiaoy312

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24904

PR Type:

🐞 Bugfix

What changed? 🚀

Under FlowDirection="RightToLeft", a TextBlock with the default TextAlignment drew its text at the visual left edge on Uno; WinUI draws it at the right. WinUI mirrors a right-to-left text element, so TextAlignment.Left/Right mean start/end. Uno suppresses that mirror for text surfaces (UIElement.GetFlowDirectionTransform) and lays lines out unmirrored, but UnicodeText read Left/Right as physical sides.

  • UnicodeText: alignments are now relative to the element's FlowDirection and mapped to visual sides when a line is placed (draw, caret, selection and hit-testing all share that offset). The TextBox default (content-detected) alignment keeps its behavior.
  • DetectFromContent now picks the side from the text's direction; it used to behave like Left.
  • Justify: the unstretched last line starts where its own text starts, whatever the FlowDirection (measured on native WinUI: right-to-left Latin text ends on the left, Arabic on the right).
  • RichEditBox: per-paragraph and uniform paragraph alignments go through the same mapping, so a paragraph no longer jumps sides when another paragraph's alignment changes.
  • Docs: behavior-change note in doc/articles/migrating-to-uno-7/behavior.md (apps using an Uno-only TextAlignment="Right" workaround should drop it).

RichTextBlock is unaffected (its ported WinUI layout already flips).

Validation

  • Runtime, Skia Desktop: new tests in Given_TextBlock (TextBlock rows for each alignment × flow × Latin/Arabic, Hyperlink, wrapped Justify, FlowDirection change, TextBox, RichEditBox uniform → mixed). With the fix reverted, the right-to-left rows fail (10/17 for the first version; the RichEditBox case fails without its fix). Full Given_TextBlock*/Given_TextBox*/Given_RichEditBox*/Given_PasswordBox* run: 1553 cases, 0 failed.
  • Runtime, native WinUI (WinAppSDK): the new tests run there too and pass; they set the expected sides. Not covered: WinUI stretches even a single-line Arabic Justify across the width (kashida), which Uno doesn't do; those rows were left out.

Known follow-ups (not in this PR)

PR Checklist ✅

Behavior change: right-to-left TextBlock/TextBox/RichEditBox text with Left (default) or Right alignment moves to the other side, matching WinUI. Apps that set TextAlignment="Right" only on Uno to work around the old behavior should remove it (see the 7.0 migration note).

🤖 Generated with Claude Code

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248907 found UI Test snapshots differences: skia-linux-screenshots: 252, skia-windows-screenshots: 265

Details
  • skia-linux-screenshots: 252 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Buttons.png-dark
    • Buttons.png
    • Accessibility_Showcase.png
    • AnimatedVisualsTestbedPage.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BasicAcrylicBrushTest.png-dark
    • Basics.png-dark
    • BasicAcrylicBrushTest.png
    • Basics.png
    • Border_CornerRadius_Binding.png-dark
    • BitmapIcon_Foreground.png-dark
    • Border_CornerRadius_Binding.png
    • BitmapIcon_Foreground.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
  • skia-windows-screenshots: 265 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_AutomationId.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • AnimatedBackVisualSourceSamplePage.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png-dark

@Xiaoy312
Xiaoy312 marked this pull request as ready for review November 24, 2026 21:00
@mergify

mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248940 found UI Test snapshots differences: skia-linux-screenshots: 206, skia-windows-screenshots: 274

Details
  • skia-linux-screenshots: 206 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AppWindowTitleBar Properties.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • BasicAcrylicBrushTest.png-dark
    • Basics.png-dark
    • BasicAcrylicBrushTest.png
    • Basics.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
  • skia-windows-screenshots: 274 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • AppWindowTitleBar Properties.png
    • BasicAcrylicBrushTest2.png-dark

Xiaoy312 and others added 7 commits November 24, 2026 18:53
Under FlowDirection RightToLeft, WinUI's TextAlignment Left/Right mean
start/end, so a default-aligned TextBlock draws at the visual right.
UnicodeText laid lines out unmirrored but read Left/Right as physical
sides. Map element-level alignments to visual sides, treat Justify's
last line as start-aligned, and honor DetectFromContent.

Fixes #24904

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A uniform paragraph alignment reaches UnicodeText as the element-level
alignment, which is now flow-relative, while mixed alignments arrive per
line and were still read as physical sides. Under RightToLeft a paragraph
jumped sides once another paragraph's alignment changed. Map all three
sources the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document that UnicodeText alignments are relative to its flowDirection
and that its caller must not be mirrored, and share the width-dependence
check between the empty and non-empty layout paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the right-to-left alignment tests out of the Skia-only block so the
WinAppSDK head runs them too. Add Center, wrapped Justify, Hyperlink,
FlowDirection change, default TextBox with LTR content, and a RichEditBox
case that keeps a paragraph's side when alignments become mixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Native WinUI starts the unstretched last line of justified text where
its own text starts: a RightToLeft TextBlock with Latin text puts it on
the left, Arabic on the right, under either FlowDirection. Stop mapping
Justify through the flow direction and align by the line's direction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261124/fix-rtl-textblock-alignment branch from 0081b41 to 71f1cb0 Compare November 24, 2026 23:54
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248954 found UI Test snapshots differences: skia-linux-screenshots: 244, skia-windows-screenshots: 286

Details
  • skia-linux-screenshots: 244 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • AppWindowTitleBar Properties.png
    • Basics.png-dark
    • Basics.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • CornerRadiusControls.png-dark
    • CornerRadiusControls.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • ButtonClippingTestsControl.png-dark
  • skia-windows-screenshots: 286 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CenteredGridinGridwithtwofixedsizechildren.png-dark
    • CenteredGridinGridwithtwofixedsizechildren.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RightToLeft TextBlock draws its text at the left edge with the default TextAlignment (WinUI draws it at the right)

3 participants