pub trait TextHitSource {
// Required methods
fn offset_at(&self, point: Point) -> usize;
fn caret_rect(&self, offset: usize) -> Rect;
fn word_range_at(&self, offset: usize) -> Range<usize> ⓘ;
fn line_range_at(&self, offset: usize) -> Range<usize> ⓘ;
fn selection(&self) -> Range<usize> ⓘ;
fn set_selection(&mut self, range: Range<usize>);
fn selection_bounds(&self) -> Option<Rect>;
fn viewport(&self) -> Rect;
fn document_len(&self) -> usize;
fn is_editable(&self) -> bool;
// Provided methods
fn allows_copy(&self) -> bool { ... }
fn clipboard_actions(&self) -> ClipboardActions { ... }
}Expand description
The geometry and selection state of one text surface, as the touch controller needs to see it.
§Relationship to TextSurface
The two do not overlap and neither subsumes the other. TextSurface answers
“perform this command” — undo, cut, paste — for a host that routes a
chord or a menu row into whatever has focus. This trait answers “where is
the text”, which is what a finger needs. The one place they meet is
clipboard_actions, which says which commands to
offer; invoking them stays with TextSurface, so there is exactly one
implementation of each command.
Required Methods§
Sourcefn caret_rect(&self, offset: usize) -> Rect
fn caret_rect(&self, offset: usize) -> Rect
The caret rectangle at offset — a thin, line-height-tall rectangle.
Handles hang off it, so a host that returns a zero-height rectangle gets
handles that sit on the baseline.
Sourcefn word_range_at(&self, offset: usize) -> Range<usize> ⓘ
fn word_range_at(&self, offset: usize) -> Range<usize> ⓘ
The word containing offset, for the long-press selection.
Sourcefn selection(&self) -> Range<usize> ⓘ
fn selection(&self) -> Range<usize> ⓘ
The current selection, as a half-open offset range. An empty range is a collapsed caret.
Sourcefn set_selection(&mut self, range: Range<usize>)
fn set_selection(&mut self, range: Range<usize>)
Move the selection. Called on every sample of a handle drag, so an implementation that rebuilds the document here will be felt.
Sourcefn selection_bounds(&self) -> Option<Rect>
fn selection_bounds(&self) -> Option<Rect>
The selection’s bounding rectangle, or None when nothing is selected.
Deliberately one rectangle and not a list of per-line rectangles: the
only consumer is the toolbar’s
AboveSelection
placement, which wants the block to hang above, and the engines behind
the shipped editors expose a union box rather than per-line geometry. A
surface that has per-line rectangles should still return their union.
Sourcefn viewport(&self) -> Rect
fn viewport(&self) -> Rect
The visible rectangle of this surface. Affordances are clamped into it, and a caret outside it has no handle.
Sourcefn document_len(&self) -> usize
fn document_len(&self) -> usize
The largest offset a caret may take — the length of the text.
Not geometry, and not in the original contract: a handle is exposed to assistive technology as a slider, and a slider without a maximum announces a position out of nothing. Every engine behind the shipped editors knows this number.
Sourcefn is_editable(&self) -> bool
fn is_editable(&self) -> bool
Does this surface accept edits? A read-only surface shows no caret handle and offers only what it can honour.
Provided Methods§
Sourcefn allows_copy(&self) -> bool
fn allows_copy(&self) -> bool
May its contents leave the process at all? A password field says no, and then neither Cut nor Copy is offered.
Sourcefn clipboard_actions(&self) -> ClipboardActions
fn clipboard_actions(&self) -> ClipboardActions
Which clipboard commands to offer for the current state. Derived from
the three questions above; see ClipboardActions.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".