Force line height in TextFields with strut#27612
Conversation
|
Requires engine roll with flutter/engine#7734 to pass tests. |
HansMuller
left a comment
There was a problem hiding this comment.
This looks good. Some of the test are a little hard to judge because the relationship between the vertical dimensions they're checking and the text style etc isn't obvious.
|
This change depends on flutter/engine#7734 and will include an engine roll. |
| /// Equivalent to having no strut at all. All lines will be laid out according to | ||
| /// the properties defined in [TextStyle]. | ||
| /// | ||
| /// Default strut is not the same as [StrutStyle.disabled]. |
There was a problem hiding this comment.
I believe that you mean StrutStyle.disabled != StrutStyle().
This line is a little confusing; maybe it doesn't bear saying at all?
There was a problem hiding this comment.
Yeah, the distinction is between omitting it and having it inherit vs passing [StrutStyle.disabled]. I guess if they dont disable it, it isnt particularly jarring as it doesnt have any direct impact that would be visible.
There was a problem hiding this comment.
But yeah, it would be inherently true that there was a difference or else it wouldnt exist (in a well designed API at least). I'll remove it.
| /// to lock all lines to the height of the base [TextStyle], provided by | ||
| /// [style]. This ensures the typed text fits within the alotted space. | ||
| /// | ||
| /// If null, the strut used will is inherit values from the [style] and will |
There was a problem hiding this comment.
If null, a [StrutStyle] based on [style], with [StrutStyle.forceStrutHeight] set to true, will be used. If [style] is null (the default) then the theme's [TextStyle] will be used instead.
However: we don't seem to be defaulting style to the theme's style?
There was a problem hiding this comment.
This behavior is actually inherited from the TextStyle taking the theme's style, which the StrutStyle then in turn inherits.
| /// instead. | ||
| /// | ||
| /// To disable strut-based vertical alignment and allow dynamic vertical | ||
| /// layout based on the glyphs typed, passing [StrutStyle.disabled] will |
There was a problem hiding this comment.
passing [StrutStyle.disabled] will make strut take no effect => use [StrutStyle]
|
|
||
| expect( | ||
| tester.getSize(find.byType(CupertinoTextField)), | ||
| const Size(200, 63), // 29 is the height of the default font * 3 (17 * 3) + decoration (12). |
There was a problem hiding this comment.
NICE. Thanks for these explanations!
matthew-carroll
left a comment
There was a problem hiding this comment.
More comments to come...our Cupertino review meeting ran out of time.
| /// | ||
| /// To disable strut-based vertical alignment and allow dynamic vertical | ||
| /// layout based on the glyphs typed, use [StrutStyle.disabled]. | ||
| /// {@endtemplate} |
There was a problem hiding this comment.
Would you mind adding a URL reference to something that explains the concept of a strut in general? It's an odd name for those that are not already familiar with it.
There was a problem hiding this comment.
I can put a link to https://www.w3.org/TR/CSS2/visudet.html#line-height in the docs for StrutStyle. Sticking the link everywhere strut is used might cause a bit too much clutter.
There was a problem hiding this comment.
I was just recommending that it be added to this template. The other places where this template appears is likely to be the first and only interaction most developers have with this concept, so it seemed like a good place for an external reference.
There was a problem hiding this comment.
https://en.wikipedia.org/wiki/Strut_(typesetting) may also be a good more generic albeit brief reference.
There was a problem hiding this comment.
Ahh my bad, missed that this was the template! That's a good idea.
| } | ||
| final CupertinoThemeData themeData = CupertinoTheme.of(context); | ||
| final TextStyle textStyle = widget.style ?? themeData.textTheme.textStyle; | ||
| final TextStyle textStyle = themeData.textTheme.textStyle.merge(widget.style); |
There was a problem hiding this comment.
This is technically a breaking change. Can you elaborate on why this was changed? Also, do you plan to announce this breaking change when merged?
There was a problem hiding this comment.
I think I should talk to someone more familiar with Cupertino about the exact desired behavior here. This is the behavior in material, and the way strut inherits the textStyle's properties is dependent on the textstyle being complete.
There was a problem hiding this comment.
Talked with xster and we have agreed the change here is reasonable. I have sent a breaking change announce out and added the API break tag. The change here should be minor and can be bypassed with the inherit: false parameter in TextStyle
| } | ||
|
|
||
| @override | ||
| String toStringShort() => '$runtimeType'; |
There was a problem hiding this comment.
Is there a reason that this is the desired behavior?
There was a problem hiding this comment.
This was based around the same override in text_style.dart:935 where presumably, the full toString that includes all of the properties, is often times too long and makes output unreadable. A similar argument can be applied to StrutStyle, which also contains a large number of potentially cluttering properties that are not necessarily relevant in the short version of the toString.
Fixes #20183
This uses strut to force line heights to stay consistent even when taller glyphs are typed. This guarantees the TextField height is large enough to contain the text as well as prevents clipping of the text.
When not explicitly provided, the strut is derived from the TextStyle of the textfield. Strut can be completely disabled by passing StrutStyle.disabled(), which will have the effect of no strut at all.
Since CJK fonts are frequently taller than alphanumeric fonts, Textfields with the font set to alphanumeric fonts tend to experience less line spacing between CJK text than usual. The opposite is also true, where alphanumeric text will see more line spacing than normal when a CJK font is set.
git log --oneline --no-merges 33bb91c..21c5919
21c5919 [re-land] Use all font managers to discover fonts for strut. (#7803)
5809ade Make the layout of dynamic patch bundle similar to APK. (#7925)
e2a449a Move canvas clear after preroll (#7923)
8529dbc Remove unused FML file export.h (#7926)
f80928a Roll src/third_party/skia fdd15284affe..ee1c8a733e5b (15 commits) (#7924)
93f339f fix Memory leak when using PlatformView [IOS] #24714 (#7919)
2d33e77 Roll src/third_party/skia 969659dbb313..fdd15284affe (2 commits) (#7922)
6d4edf2 Roll src/third_party/skia 9431161ca973..969659dbb313 (3 commits) (#7921)