-
Notifications
You must be signed in to change notification settings - Fork 1.2k
TextAlign and WritingDirection Parity for Fabric TextInput #15340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
TextAlign and WritingDirection Parity for Fabric TextInput #15340
Conversation
…xtInput - Add support for textAlign='justify' using PFA_JUSTIFY flag - Implement writingDirection (baseWritingDirection) support for 'ltr', 'rtl', and 'auto' - Make textAlign='auto' (Natural) respect RTL writing direction - Set PFM_RTLPARA and PFE_RTLPARA flags for RTL text - Achieves full parity with Paper XAML implementation
| // Ensure RTL flag is not set | ||
| m_pf.wEffects &= ~PFE_RTLPARA; | ||
| } | ||
| // WritingDirection::Natural uses default behavior (no specific RTL setting) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case the direction needs to come from layoutMetrics().layoutDirection, since direction could be overridden at any point in the tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| m_pf.cTabCount = 1; | ||
| m_pf.rgxTabs[0] = lDefaultTab; | ||
|
|
||
| /* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets delete the old code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
Can any of these flags affect layout? If so, similar changes will be needed in WindowsTextLayoutManager - which is where layout is performed. |
Yes, the PFE_RTLPARA and PFA_LEFT/RIGHT/CENTER/JUSTIFY flags DO affect text layout and measurement. However, WindowsTextLayoutManager currently does NOT handle baseWritingDirection/WritingDirection - it only handles TextAlignment. |
- TextInput now properly handles textAlign (Left, Right, Center, Justified, Natural) - TextInput now properly handles writingDirection/baseWritingDirection (LTR, RTL, Natural) - WritingDirection::Natural uses layoutMetrics.layoutDirection since direction can be overridden at any point in the tree - Added matching support in WindowsTextLayoutManager for text measurement - WindowsTextLayoutManager now sets DWRITE_READING_DIRECTION based on baseWritingDirection - TextAlignment::Natural now respects reading direction (RTL = trailing, LTR = leading) - Fixes layout affecting flags that impact text measurement throughout the system
- Only call SetReadingDirection when baseWritingDirection is explicitly specified - Avoids breaking existing text layouts that don't specify writingDirection - Fixes LegacyControlStyleTest snapshot failure - Natural alignment still respects RTL when baseWritingDirection is set
Can we fix that? We cannot have TextInput and TextLayoutManager disagree on the size, otherwise we'll get bad sizing behaviors in certain layouts. |
Done that in the latest commit. |
Description
Type of Change
Why
The Fabric Composition architecture had incomplete support for the
textAlignproperty and no support for thewritingDirectionproperty in TextInput components. Specifically:'justify'alignment option that Paper XAML fully supportsThis created feature gaps where:
What
Implemented complete
textAlignandwritingDirectionsupport in Fabric TextInput to achieve full parity with Paper XAML implementation:1. textAlign Property Enhancements:
'justify'alignment using RichEdit's PFA_JUSTIFY flag'auto'/Natural alignment to properly respect writing direction:2. writingDirection Property Implementation:
baseWritingDirectionfrom TextAttributes (inherited from BaseTextProps)'ltr'(Left-to-Right): Explicitly sets LTR paragraph direction'rtl'(Right-to-Left): Sets PFM_RTLPARA and PFE_RTLPARA flags in RichEdit'auto'/Natural: Uses default behavior (no explicit RTL flags)Technical Implementation:
Modified
WindowsTextInputComponentView::UpdateParaFormat()to:This implementation leverages RichEdit's native paragraph formatting capabilities through the PARAFORMAT2 structure, ensuring proper rendering of both alignment and text direction.
Screenshots
No screenshots needed. This implements standard text alignment and direction behaviors that match Paper architecture.
Testing
textAlign='justify' Testing:
textAlign='auto' with RTL Testing:
writingDirection Explicit Testing:
All textAlign Values Verified:
'left'→ PFA_LEFT'right'→ PFA_RIGHT'center'→ PFA_CENTER'justify'→ PFA_JUSTIFY (NEW)'auto'→ Respects RTL (FIXED)Changelog
Should this change be included in the release notes: yes
Implemented complete textAlign and writingDirection support for Fabric TextInput. Users can now justify text alignment and control text direction for internationalized applications. The textAlign='auto' option now properly respects RTL writing direction. This achieves full parity with Paper XAML implementation and improves support for right-to-left languages.
Related Work
Breaking Changes
None. These are additive features that don't change existing behavior.
Microsoft Reviewers: Open in CodeFlow