Skip to main content

PlatformTextLayout

Trait PlatformTextLayout 

Source
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§

Source

fn len(&self) -> usize

Returns the length of the source text in UTF-8 bytes.

Source

fn line_count(&self) -> usize

Returns the number of visual lines, after wrapping and clamping.

Source

fn size(&self) -> Size<Pixels>

Returns the natural size of the layout that the backend reports.

Source

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.

Source

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.

Source

fn caret_bounds( &self, caret: CaretPosition, line_height: Pixels, ) -> Option<Bounds<Pixels>>

Returns the caret bounds in GPUI layout coordinates.

Source

fn normalized_caret(&self, caret: CaretPosition) -> CaretPosition

Snaps a caret to a native cluster boundary.

Source

fn adjacent_visual_caret( &self, caret: CaretPosition, direction: VisualDirection, ) -> Option<CaretPosition>

Returns the adjacent caret stop in visual order.

Source

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.

Source

fn logical_cluster_before(&self, caret: CaretPosition) -> Option<Range<usize>>

Returns the atomic logical cluster before the caret.

Source

fn logical_cluster_after(&self, caret: CaretPosition) -> Option<Range<usize>>

Returns the atomic logical cluster after the caret.

Source

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.

Source

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§

Source

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.

Source

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".

Implementors§