pub trait TextService {
Show 18 methods
// Required methods
fn prepare(
&mut self,
input: &TextInput,
constraints: TextConstraints,
) -> (TextBlobId, TextMetrics);
fn release(&mut self, blob: TextBlobId);
// Provided methods
fn prepare_str(
&mut self,
text: &str,
style: &TextStyle,
constraints: TextConstraints,
) -> (TextBlobId, TextMetrics) { ... }
fn prepare_rich(
&mut self,
rich: &AttributedText,
base_style: &TextStyle,
constraints: TextConstraints,
) -> (TextBlobId, TextMetrics) { ... }
fn measure(
&mut self,
input: &TextInput,
constraints: TextConstraints,
) -> TextMetrics { ... }
fn measure_str(
&mut self,
text: &str,
style: &TextStyle,
constraints: TextConstraints,
) -> TextMetrics { ... }
fn measure_rich(
&mut self,
rich: &AttributedText,
base_style: &TextStyle,
constraints: TextConstraints,
) -> TextMetrics { ... }
fn caret_x(&mut self, _blob: TextBlobId, _index: usize) -> Px { ... }
fn hit_test_x(&mut self, _blob: TextBlobId, _x: Px) -> usize { ... }
fn selection_rects(
&mut self,
_blob: TextBlobId,
_range: (usize, usize),
_out: &mut Vec<Rect>,
) { ... }
fn first_line_metrics(
&mut self,
_blob: TextBlobId,
) -> Option<TextLineMetrics> { ... }
fn first_line_ink_metrics(
&mut self,
_blob: TextBlobId,
) -> Option<TextInkMetrics> { ... }
fn last_line_metrics(
&mut self,
_blob: TextBlobId,
) -> Option<TextLineMetrics> { ... }
fn last_line_ink_metrics(
&mut self,
_blob: TextBlobId,
) -> Option<TextInkMetrics> { ... }
fn selection_rects_clipped(
&mut self,
blob: TextBlobId,
range: (usize, usize),
clip: Rect,
out: &mut Vec<Rect>,
) { ... }
fn caret_stops(&mut self, _blob: TextBlobId, _out: &mut Vec<(usize, Px)>) { ... }
fn caret_rect(
&mut self,
_blob: TextBlobId,
_index: usize,
_affinity: CaretAffinity,
) -> Rect { ... }
fn hit_test_point(
&mut self,
_blob: TextBlobId,
_point: Point,
) -> HitTestResult { ... }
}Required Methods§
fn prepare( &mut self, input: &TextInput, constraints: TextConstraints, ) -> (TextBlobId, TextMetrics)
fn release(&mut self, blob: TextBlobId)
Provided Methods§
fn prepare_str( &mut self, text: &str, style: &TextStyle, constraints: TextConstraints, ) -> (TextBlobId, TextMetrics)
fn prepare_rich( &mut self, rich: &AttributedText, base_style: &TextStyle, constraints: TextConstraints, ) -> (TextBlobId, TextMetrics)
fn measure( &mut self, input: &TextInput, constraints: TextConstraints, ) -> TextMetrics
fn measure_str( &mut self, text: &str, style: &TextStyle, constraints: TextConstraints, ) -> TextMetrics
fn measure_rich( &mut self, rich: &AttributedText, base_style: &TextStyle, constraints: TextConstraints, ) -> TextMetrics
Sourcefn caret_x(&mut self, _blob: TextBlobId, _index: usize) -> Px
fn caret_x(&mut self, _blob: TextBlobId, _index: usize) -> Px
Returns the X offset (in logical px) of the caret at index within the prepared text blob.
Coordinate space: relative to the text origin (x=0 at the beginning of the line).
Notes:
indexis a byte offset into the UTF-8 text, clamped to valid char boundaries (ADR 0044).- Implementations may clamp to the nearest representable caret position.
Sourcefn hit_test_x(&mut self, _blob: TextBlobId, _x: Px) -> usize
fn hit_test_x(&mut self, _blob: TextBlobId, _x: Px) -> usize
Performs hit-testing for a single-line text blob and returns the nearest caret byte index.
Coordinate space: x is relative to the text origin (x=0 at the beginning of the line).
Sourcefn selection_rects(
&mut self,
_blob: TextBlobId,
_range: (usize, usize),
_out: &mut Vec<Rect>,
)
fn selection_rects( &mut self, _blob: TextBlobId, _range: (usize, usize), _out: &mut Vec<Rect>, )
Computes selection rectangles for a single-line selection range.
Coordinate space: rects are relative to the text origin (x=0, y=0 at top of text box).
Geometry contract:
- For a non-empty range (
start != end), conforming implementations should emit rectangles with positive height (and should avoid emitting zero-width rectangles).
Sourcefn first_line_metrics(&mut self, _blob: TextBlobId) -> Option<TextLineMetrics>
fn first_line_metrics(&mut self, _blob: TextBlobId) -> Option<TextLineMetrics>
Best-effort first-line font extents for a prepared text blob.
This is primarily intended for mechanism-level vertical placement policies in fixed-height
controls. Implementations should return None if the data is unavailable or expensive to
compute.
Sourcefn first_line_ink_metrics(
&mut self,
_blob: TextBlobId,
) -> Option<TextInkMetrics>
fn first_line_ink_metrics( &mut self, _blob: TextBlobId, ) -> Option<TextInkMetrics>
Best-effort first-line ink extents (ascent/descent) for a prepared text blob.
This differs from first_line_metrics when the line box is fixed (e.g.
TextLineHeightPolicy::FixedFromStyle) but the shaped content includes taller fallback
glyphs (emoji/CJK/etc). Callers may use this to detect potential clipping and apply
padding or a different line-height preset.
Sourcefn last_line_metrics(&mut self, _blob: TextBlobId) -> Option<TextLineMetrics>
fn last_line_metrics(&mut self, _blob: TextBlobId) -> Option<TextLineMetrics>
Best-effort last-line font extents for a prepared multi-line text blob.
This is primarily intended for mechanism-level vertical placement and overflow handling
policies. Implementations should return None if the data is unavailable or expensive to
compute.
Sourcefn last_line_ink_metrics(&mut self, _blob: TextBlobId) -> Option<TextInkMetrics>
fn last_line_ink_metrics(&mut self, _blob: TextBlobId) -> Option<TextInkMetrics>
Best-effort last-line ink extents (ascent/descent) for a prepared multi-line text blob.
This is intended for avoiding bottom-edge clipping in fixed line-box layouts when the last line contains tall fallback glyphs (emoji/CJK/etc).
Sourcefn selection_rects_clipped(
&mut self,
blob: TextBlobId,
range: (usize, usize),
clip: Rect,
out: &mut Vec<Rect>,
)
fn selection_rects_clipped( &mut self, blob: TextBlobId, range: (usize, usize), clip: Rect, out: &mut Vec<Rect>, )
Computes selection rectangles and clips them to clip in the same coordinate space.
This is intended for large multi-line selections where generating rectangles for off-screen lines is wasteful. Implementations may override this to cull work earlier.
Coordinate space: rects and clip are relative to the text origin (x=0, y=0 at top of text box).
Sourcefn caret_stops(&mut self, _blob: TextBlobId, _out: &mut Vec<(usize, Px)>)
fn caret_stops(&mut self, _blob: TextBlobId, _out: &mut Vec<(usize, Px)>)
Extracts the precomputed caret stop table (byte index -> x offset) for a single-line blob.
This is primarily intended for UI hit-testing in event handlers, which do not have access to the text service.
Sourcefn caret_rect(
&mut self,
_blob: TextBlobId,
_index: usize,
_affinity: CaretAffinity,
) -> Rect
fn caret_rect( &mut self, _blob: TextBlobId, _index: usize, _affinity: CaretAffinity, ) -> Rect
Returns the caret rectangle (in logical px) for the given index.
Coordinate space: rect is relative to the text origin (x=0, y=0 at the top of the text box).
Notes:
- Single-line implementations may ignore affinity.
- Multi-line implementations should use affinity to disambiguate positions at line breaks.
- Conforming implementations should return a rectangle with positive height.
Sourcefn hit_test_point(&mut self, _blob: TextBlobId, _point: Point) -> HitTestResult
fn hit_test_point(&mut self, _blob: TextBlobId, _point: Point) -> HitTestResult
Hit-test a point in the text’s local coordinate space and return a caret index and affinity.
Coordinate space: point is relative to the text origin (x=0, y=0 at the top of the text box).