-
Notifications
You must be signed in to change notification settings - Fork 6k
Tight Paragraph Width #8530
Tight Paragraph Width #8530
Conversation
ddfb0d7 to
54e347c
Compare
|
Note to self: There is a very similar enum BoxWidthStyle, any possible reuse? |
54e347c to
5de3316
Compare
|
@GaryQian Can you give me a review on my approach here? I'll talk to Hans when he's around as well. I put the enum inside of the engine, so users will have to import it from |
lib/ui/text.dart
Outdated
| if (fontFamily != null) { | ||
| if (widthType != null) { | ||
| result[0] |= 1 << 6; | ||
| result[6] = widthType.index; |
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.
Since this is a binary value, it is possible to compress this into much smaller than the 32 bit int you are using now, but for now, this is OK. The benefit of what you have is that it is consistent and more readable. A more compressed version would be harder to read and maintain.
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.
It looks like I'm going to remove widthType, so this won't be a problem anymore.
lib/ui/text.dart
Outdated
| FontWeight fontWeight, | ||
| FontStyle fontStyle, | ||
| StrutStyle strutStyle, | ||
| TextWidthType widthType, |
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.
So since dart:ui is a more base level library, we may want to consider handling the switching between full and tight completely in the framework as an abstraction over dart:ui. At the dart:ui level, I think it makes more sense for both widths to be available in the getter for the width. Either make the width getter property take the enum or make a separate getter for the tight width.
The idea of innately possessing a tight or full width is more of a framework-level issue, and dart:ui (and below) shouldn't really have the paragraph preemptively pick its width as it would now with a setting in ParagraphStyle.
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 it makes sense for the setting to be in ParagraphStyle, but have the framework consult it or otherwise extract the widthType from the ParagraphStyle to choose with dart:ui method to call.
This would mean it isnt necessary to pass the widthType all the way down into Libtxt in the initial passing of ParagraphStyle into native.
third_party/txt/src/txt/paragraph.cc
Outdated
| return a.code_units.start < b.code_units.start; | ||
| }); | ||
|
|
||
| if (paragraph_style_.width_type == TextWidthType::tight) { |
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.
(see above comments for context) LibTxt should be able to indiscriminately provide the metrics for both width types. By making the paragraph "choose" which width to provide, we are artificially hiding a potentially useful metric from the users of this quite low level API.
This hiding makes more sense if done completely in the framework level.
|
The implementation of the libtxt->dart:ui layers seems to be good though! |
a17a9b7 to
1941f16
Compare
|
@GaryQian Ready for re-review. Now I'm setting a |
|
Implementation looks good. Do you think you can add a simple test to txt/tests/paragraph_unittests.cc? |
lib/ui/text.dart
Outdated
| double get height native 'Paragraph_height'; | ||
|
|
||
| /// The distance from the left edge of the leftmost character to the right | ||
| /// edge of the rightmost character in the paragraph. |
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.
glyph may be a more precise word for this concept
third_party/txt/src/txt/paragraph.h
Outdated
| double GetMaxWidth() const; | ||
|
|
||
| // Returns the tight width found in Layout(), which is defined as the | ||
| // horizontal distance from the left edge of the leftmost character to the |
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.
glyph (same as above)
666e555 to
8f68d3b
Compare
| // no line perfectly spans the width of the full line, so tight_width_ is less | ||
| // than width_. | ||
| ASSERT_DOUBLE_EQ(paragraph->width_, available_width); | ||
| ASSERT_TRUE(paragraph->tight_width_ < paragraph->width_); |
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.
You should be able to compare against either hardcoded values or the right edge of the right-most getRectsForRange box.
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.
Good call.
|
@GaryQian I used |
|
Sounds good! |
GaryQian
left a comment
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.
LGTM!
flutter/engine@06fea14...4b9966f git log 06fea14..4b9966f --no-merges --oneline 4b9966f Add an adjustment to the line width check in LineBreaker::addWordBreak (flutter/engine#8623) 60bb866 Roll src/third_party/skia a94670bd08cd..2c2240f66805 (2 commits) (flutter/engine#8632) a144f17 Tight Paragraph Width (flutter/engine#8530) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff (cbracken@google.com), and stop the roller if necessary.
|
Thank you so much , exactly what I need. I almost gave up on flutter before seeing this. |




Closes flutter/flutter#26585
Paragraph currently sets its width to be the maximum space allowed for it when it wraps beyond one line. This creates extra empty space when you want to draw something with a tight container:
This PR will enable the drawing of a paragraph with a width only as wide as it needs to be to contain wrapping text tightly.
Solution
I propose we add an enum to
Textto allow the user to choose how width will be calculated.TextWidthType.tightwill render like a chat bubble:TextWidthType.full, the default, will render like it always has:Text(overflowingString),Concerns
The naming was hastily chosen. I worry that users will expect that
TextWidthType.fullwill cause the Text to render full width for a single line of text. Following existing behavior, it will not.