-
Notifications
You must be signed in to change notification settings - Fork 6k
Add/expose API for Paragraph.getBoxesForRange styles. #6644
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -947,6 +947,68 @@ class ParagraphConstraints { | |
| String toString() => '$runtimeType(width: $width)'; | ||
| } | ||
|
|
||
| /// Defines various ways to vertically bound the boxes returned by | ||
| /// [Paragraph.getBoxesForRange]. | ||
| enum BoxHeightStyle { | ||
| /// Provide tight bounding boxes that fit heights per run. This style may result | ||
| /// in uneven bounding boxes that do not nicely connect with the boxes above, | ||
| /// below, and adjacent. | ||
| tight, | ||
|
|
||
| /// The height of the boxes will be the maximum height of all runs in the | ||
| /// line. All boxes in the same line will be the same height. This does not | ||
| /// guarantee that the boxes will cover the entire vertical height of the line | ||
| /// when there is additional line spacing. | ||
| /// | ||
| /// See [RectHeightStyle.includeLineSpacingTop], [RectHeightStyle.includeLineSpacingMiddle], | ||
| /// and [RectHeightStyle.includeLineSpacingBottom] for styles that will cover | ||
| /// the entire line. | ||
| max, | ||
|
|
||
| /// Extends the top and bottom edge of the bounds to fully cover any line | ||
| /// spacing. | ||
| /// | ||
| /// The top and bottom of each box will cover half of the | ||
| /// space above and half of the space below the line. The text should be | ||
| /// centered vertically within the box. | ||
|
||
| /// | ||
| /// {@template flutter.dart:ui.boxHeightStyle.includeLineSpacing} | ||
| /// The top edge of each line should be the same as the bottom edge | ||
| /// of the line above. There should be no gaps in vertical coverage given any | ||
| /// amount of line spacing. Line spacing is not included above the first line | ||
| /// below the last line due to no additional space present there. | ||
|
||
| /// {@endtemplate} | ||
| includeLineSpacingMiddle, | ||
|
|
||
| /// Extends the top edge of the bounds to fully cover any line spacing. | ||
| /// | ||
| /// The line spacing will be added to the top of the box. | ||
| /// | ||
| /// {@macro flutter.dart:ui.rectHeightStyle.includeLineSpacing} | ||
| includeLineSpacingTop, | ||
|
|
||
| /// Extends the bottom edge of the bounds to fully cover any line spacing. | ||
| /// | ||
| /// The line spacing will be added to the bottom of the box. | ||
| /// | ||
| /// {@macro flutter.dart:ui.boxHeightStyle.includeLineSpacing} | ||
| includeLineSpacingBottom, | ||
| } | ||
|
|
||
| /// Defines various ways to horizontally bound the boxes returned by | ||
| /// [Paragraph.getBoxesForRange]. | ||
| enum BoxWidthStyle { | ||
| // Provide tight bounding boxes that fit widths to the runs of each line | ||
| // independently. | ||
| tight, | ||
|
|
||
| /// Adds up to two additional boxes as needed at the beginning and/or end | ||
| /// of each line so that the widths of the boxes in line are the same width | ||
| /// as the widest line in the paragraph. The additional boxes are only added | ||
| /// when the first/last box does not span the max width of the paragraph. | ||
|
||
| max, | ||
| } | ||
|
|
||
| /// A paragraph of text. | ||
| /// | ||
| /// A paragraph retains the size and position of each glyph in the text and can | ||
|
|
@@ -1010,7 +1072,18 @@ class Paragraph extends NativeFieldWrapperClass2 { | |
| void _layout(double width) native 'Paragraph_layout'; | ||
|
|
||
| /// Returns a list of text boxes that enclose the given text range. | ||
| List<TextBox> getBoxesForRange(int start, int end) native 'Paragraph_getRectsForRange'; | ||
| /// | ||
| /// [boxHeightStyle] and [boxWidthStyle] allow customization of how the boxes | ||
|
||
| /// are bound vertically and horizontally. Both style parameters default to | ||
| /// the tight option, which will provide close fitting boxes and will not | ||
|
||
| /// account for any line spacing. | ||
| /// | ||
| /// See [BoxHeightStyle] and [BoxWidthStyle] for full descriptions of each option. | ||
| List<TextBox> getBoxesForRange(int start, int end, {BoxHeightStyle boxHeightStyle = BoxHeightStyle.tight, BoxWidthStyle boxWidthStyle = BoxWidthStyle.tight}) { | ||
| return _getBoxesForRange(start, end, boxHeightStyle.index, boxWidthStyle.index); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert that the arguments aren't null (and mention in the docs that they must not be null) |
||
| } | ||
|
|
||
| List<TextBox> _getBoxesForRange(int start, int end, int boxHeightStyle, int boxWidthStyle) native 'Paragraph_getRectsForRange'; | ||
|
|
||
| /// Returns the text position closest to the given offset. | ||
| TextPosition getPositionForOffset(Offset offset) { | ||
|
|
||
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.
above and below are both adjacent.
Maybe just "adjacent boxes"?