Expose 3 new methods with text metrics in RenderParagraph (#65150)
This commit is contained in:
committed by
GitHub
parent
0d8de393aa
commit
bb59993ac6
@@ -784,7 +784,9 @@ class TextPainter {
|
||||
return _caretMetrics.offset;
|
||||
}
|
||||
|
||||
/// Returns the tight bounded height of the glyph at the given [position].
|
||||
/// {@template flutter.painting.textPainter.getFullHeightForCaret}
|
||||
/// Returns the strut bounded height of the glyph at the given `position`.
|
||||
/// {@endtemplate}
|
||||
///
|
||||
/// Valid only after [layout] has been called.
|
||||
double? getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
|
||||
|
||||
@@ -744,6 +744,15 @@ class RenderParagraph extends RenderBox
|
||||
return _textPainter.getOffsetForCaret(position, caretPrototype);
|
||||
}
|
||||
|
||||
/// {@macro flutter.painting.textPainter.getFullHeightForCaret}
|
||||
///
|
||||
/// Valid only after [layout].
|
||||
double? getFullHeightForCaret(TextPosition position) {
|
||||
assert(!debugNeedsLayout);
|
||||
_layoutTextWithConstraints(constraints);
|
||||
return _textPainter.getFullHeightForCaret(position, Rect.zero);
|
||||
}
|
||||
|
||||
/// Returns a list of rects that bound the given selection.
|
||||
///
|
||||
/// A given selection might have more than one rect if this text painter
|
||||
|
||||
@@ -36,6 +36,17 @@ void main() {
|
||||
expect(offset50.dy, greaterThan(offset5.dy));
|
||||
});
|
||||
|
||||
test('getFullHeightForCaret control test', () {
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
const TextSpan(text: _kText,style: TextStyle(fontSize: 10.0)),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
layout(paragraph);
|
||||
|
||||
final double height5 = paragraph.getFullHeightForCaret(const TextPosition(offset: 5));
|
||||
expect(height5, equals(10.0));
|
||||
});
|
||||
|
||||
test('getPositionForOffset control test', () {
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
const TextSpan(text: _kText),
|
||||
|
||||
Reference in New Issue
Block a user