feat(text-editor): add configurable leadingDistribution to TextEditorStyle#789
Open
faizahmaddae wants to merge 1 commit intohm21:stablefrom
Open
feat(text-editor): add configurable leadingDistribution to TextEditorStyle#789faizahmaddae wants to merge 1 commit intohm21:stablefrom
faizahmaddae wants to merge 1 commit intohm21:stablefrom
Conversation
…Style Add a new leadingDistribution property to TextEditorStyle that controls how extra leading is distributed above and below text glyphs. Default: TextLeadingDistribution.proportional (preserves existing behavior). When set to TextLeadingDistribution.even, glyphs are vertically centered within their line height bounds, fixing visual misalignment of text inside rounded background rects at line heights > 1.0. Changes: - TextEditorStyle: new leadingDistribution property with copyWith support - RoundedBackgroundTextField: both builders read from config instead of hardcoding proportional - RoundedBackgroundText: new leadingDistribution parameter on both constructors, wired to parent TextSpan and debugFillProperties - LayerWidgetTextItem: passes config value to RoundedBackgroundText so saved layers match the editing style
1efc4b8 to
6fa2bdc
Compare
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.
Problem
The text editor hardcodes
TextLeadingDistribution.proportionalin three places acrossRoundedBackgroundTextFieldandRoundedBackgroundText. With proportional distribution, extra leading is split according to the ascent:descent ratio (~75%/25% for Latin fonts), causing glyphs to sit in the lower portion of their rounded background rects whenlineHeight > 1.0.Visual effect
This makes the text appear visually misaligned inside its background at any non-default line height.
Root cause
TextLeadingDistribution.proportionaldistributes extra leading proportionally to ascent and descent. Since ascent >> descent for most fonts, the majority of extra space goes above the glyph, pushing it downward within the line bounds. This is the Flutter default for backward compatibility, butTextLeadingDistribution.even(50/50 split) produces visually centered results.The value was hardcoded in:
RoundedBackgroundTextField._buildBackgroundText()— background paintRoundedBackgroundTextField._buildEditableText()— editable text inputRoundedBackgroundTextconstructors — standalone rendering for saved layersSolution
Add a configurable
leadingDistributionproperty toTextEditorStyle(default:TextLeadingDistribution.proportionalfor full backward compatibility). All three hardcoded sites now read from the config.Changes
TextEditorStyleleadingDistributionproperty withcopyWithsupportRoundedBackgroundTextFieldwidget.configs.style.leadingDistributionRoundedBackgroundTextleadingDistributionparameter on both constructors, wired to parentTextSpanstyle anddebugFillPropertiesLayerWidgetTextItemRoundedBackgroundTextfor consistent saved-layer renderingUsage
Backward compatibility
TextLeadingDistribution.proportional— zero behavior change for existing usersTextEditorStyleconfigs