pub trait PlatformTextLayout:
Send
+ Sync
+ Debug {
Show 15 methods
// Required methods
fn len(&self) -> usize;
fn line_count(&self) -> usize;
fn size(&self) -> Size<Pixels>;
fn byte_index_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
) -> Result<usize, usize>;
fn caret_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
) -> Result<CaretPosition, CaretPosition>;
fn caret_bounds(
&self,
caret: CaretPosition,
line_height: Pixels,
) -> Option<Bounds<Pixels>>;
fn normalized_caret(&self, caret: CaretPosition) -> CaretPosition;
fn adjacent_visual_caret(
&self,
caret: CaretPosition,
direction: VisualDirection,
) -> Option<CaretPosition>;
fn selection_bounds(
&self,
byte_range: Range<usize>,
line_height: Pixels,
) -> Vec<Bounds<Pixels>>;
fn logical_cluster_before(
&self,
caret: CaretPosition,
) -> Option<Range<usize>>;
fn logical_cluster_after(
&self,
caret: CaretPosition,
) -> Option<Range<usize>>;
fn caret_movement(
&self,
caret: CaretPosition,
movement: TextMovement,
vertical_navigation_x: Option<Pixels>,
) -> CaretMovement;
fn selection_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
kind: TextSelectionKind,
) -> Range<usize> ⓘ;
// Provided methods
fn inline_geometry(
&self,
range: Range<usize>,
) -> Option<Vec<InlineRangeGeometry>> { ... }
fn inline_geometry_for_ranges(
&self,
ranges: &[Range<usize>],
) -> Vec<Vec<InlineRangeGeometry>> { ... }
}Expand description
The text interaction model that a backend provides for one laid-out string.
GPUI calls these methods for hit testing, caret movement, and selection. The
backend does this work because only it knows the glyph clusters, bidi
runs, and line breaks. Application code does not implement or call this trait
directly. Use the methods on ShapedTextLayout instead.
Byte positions are UTF-8 boundaries. Geometry is in GPUI layout coordinates, using the caller-provided line height. Implementations must preserve visual order and caret affinity.
A cluster is one backend-defined caret step. It may contain several Unicode scalar values, such as a combining sequence or an emoji ZWJ sequence. Logical clusters are independent of visual direction and soft-wrapped rows.
Required Methods§
Sourcefn line_count(&self) -> usize
fn line_count(&self) -> usize
Returns the number of visual lines, after wrapping and clamping.
Sourcefn size(&self) -> Size<Pixels>
fn size(&self) -> Size<Pixels>
Returns the natural size of the layout that the backend reports.
Sourcefn byte_index_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
) -> Result<usize, usize>
fn byte_index_from_pixel_point( &self, pixel_point: Point<Pixels>, line_height: Pixels, ) -> Result<usize, usize>
Returns the UTF-8 byte index of the cluster under a point in GPUI layout coordinates.
Returns Ok when the point is inside a visual row. Otherwise it returns
Err with the closest index.
Sourcefn caret_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
) -> Result<CaretPosition, CaretPosition>
fn caret_from_pixel_point( &self, pixel_point: Point<Pixels>, line_height: Pixels, ) -> Result<CaretPosition, CaretPosition>
Returns the closest caret for a point in GPUI layout coordinates.
Points outside a visual row return Err.
Sourcefn caret_bounds(
&self,
caret: CaretPosition,
line_height: Pixels,
) -> Option<Bounds<Pixels>>
fn caret_bounds( &self, caret: CaretPosition, line_height: Pixels, ) -> Option<Bounds<Pixels>>
Returns the caret bounds in GPUI layout coordinates.
Sourcefn normalized_caret(&self, caret: CaretPosition) -> CaretPosition
fn normalized_caret(&self, caret: CaretPosition) -> CaretPosition
Snaps a caret to a native cluster boundary.
Sourcefn adjacent_visual_caret(
&self,
caret: CaretPosition,
direction: VisualDirection,
) -> Option<CaretPosition>
fn adjacent_visual_caret( &self, caret: CaretPosition, direction: VisualDirection, ) -> Option<CaretPosition>
Returns the adjacent caret stop in visual order.
Sourcefn selection_bounds(
&self,
byte_range: Range<usize>,
line_height: Pixels,
) -> Vec<Bounds<Pixels>>
fn selection_bounds( &self, byte_range: Range<usize>, line_height: Pixels, ) -> Vec<Bounds<Pixels>>
Returns bounds for a UTF-8 byte range in visual order.
Sourcefn logical_cluster_before(&self, caret: CaretPosition) -> Option<Range<usize>>
fn logical_cluster_before(&self, caret: CaretPosition) -> Option<Range<usize>>
Returns the atomic logical cluster before the caret.
Sourcefn logical_cluster_after(&self, caret: CaretPosition) -> Option<Range<usize>>
fn logical_cluster_after(&self, caret: CaretPosition) -> Option<Range<usize>>
Returns the atomic logical cluster after the caret.
Sourcefn caret_movement(
&self,
caret: CaretPosition,
movement: TextMovement,
vertical_navigation_x: Option<Pixels>,
) -> CaretMovement
fn caret_movement( &self, caret: CaretPosition, movement: TextMovement, vertical_navigation_x: Option<Pixels>, ) -> CaretMovement
Returns the caret and retained horizontal coordinate after applying a movement.
Sourcefn selection_from_pixel_point(
&self,
pixel_point: Point<Pixels>,
line_height: Pixels,
kind: TextSelectionKind,
) -> Range<usize> ⓘ
fn selection_from_pixel_point( &self, pixel_point: Point<Pixels>, line_height: Pixels, kind: TextSelectionKind, ) -> Range<usize> ⓘ
Returns the word or line selected at a point in GPUI layout coordinates.
Provided Methods§
Sourcefn inline_geometry(
&self,
range: Range<usize>,
) -> Option<Vec<InlineRangeGeometry>>
fn inline_geometry( &self, range: Range<usize>, ) -> Option<Vec<InlineRangeGeometry>>
Native range rectangles and their visual line indices, without selection-only extensions.
Returns None for an empty input range. A nonempty range can produce an empty vector when
it has no drawable geometry. Backends supporting inline flow should preserve actual
vertical metrics here.
Sourcefn inline_geometry_for_ranges(
&self,
ranges: &[Range<usize>],
) -> Vec<Vec<InlineRangeGeometry>>
fn inline_geometry_for_ranges( &self, ranges: &[Range<usize>], ) -> Vec<Vec<InlineRangeGeometry>>
Returns native geometry for several ranges in input order.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".