Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout { /* private fields */ }
Expand description

A Floem wrapper around a Parley text layout.

This type owns the source text, shaping result, wrapping configuration, and the tab-expansion mapping Floem uses for editor-style tab handling.

Use this when you need:

  • shaping and wrapping text for painting
  • hit testing and cursor geometry
  • visual-line text ranges and metrics

This is a higher-level Floem wrapper, not a direct re-export of Parley’s layout type.

Implementations§

Source§

impl TextLayout

Source

pub fn selection(&self, anchor: Cursor, focus: Cursor) -> TextSelection

Creates a selection without clearing the cached selection outline bounds.

Use this when updating an existing selection rather than beginning a new one.

Source

pub fn clear_selection_geometry_cache()

Clears the cached glyph outline bounds used for selection geometry.

Floem uses this cache to avoid repeatedly scaling glyph outlines when selection rectangles need ink-tight horizontal bounds. Callers that treat selection as a short-lived interaction can clear it when starting a new selection to keep the cache from growing across unrelated gestures.

Source

pub fn begin_selection(&self, anchor: Cursor, focus: Cursor) -> TextSelection

Creates a new selection and clears the cached selection outline bounds.

This is the preferred entry point when beginning a new user selection. It makes the outline-bounds cache invalidation explicit and local to the selection-construction API instead of requiring callers to remember a separate cache-management step.

Source

pub fn begin_selection_from_byte_range( &self, start_byte: usize, end_byte: usize, ) -> TextSelection

Creates a new selection from a source-text byte range and clears the cached selection outline bounds.

Use this when a new selection starts from byte offsets rather than from existing Parley cursors.

Source

pub fn collapsed_selection(&self, cursor: Cursor) -> TextSelection

Creates a new collapsed selection at the given cursor.

Source

pub fn selection_from_byte_range( &self, start_byte: usize, end_byte: usize, ) -> TextSelection

Creates a Parley selection from a source-text byte range.

Source

pub fn selection_from_byte_positions( &self, anchor_byte: usize, focus_byte: usize, ) -> Option<TextSelection>

Creates a selection from source-text byte positions while preserving anchor/focus direction.

Source

pub fn begin_selection_from_byte_positions( &self, anchor_byte: usize, focus_byte: usize, ) -> Option<TextSelection>

Creates a new selection from source-text byte positions while preserving anchor/focus direction and clearing the cached selection outline bounds.

Source

pub fn selection_text_range(&self, selection: &TextSelection) -> Range<usize>

Converts a Parley selection into a byte range in the original source text.

Source

pub fn new() -> Self

Creates an empty text layout with Floem’s default wrapping settings.

Source

pub fn new_with_text( text: &str, attrs_list: AttrsList, align: Option<Alignment>, ) -> Self

Creates a new layout and immediately sets its text and attributes.

Source

pub fn set_text( &mut self, text: &str, attrs_list: AttrsList, align: Option<Alignment>, )

Replaces the text content and style spans for this layout.

This rebuilds the underlying Parley layout and reapplies the current wrapping configuration.

Source

pub fn set_text_wrap_mode(&mut self, text_wrap_mode: TextWrapMode)

Sets the primary wrap mode used when reflowing the layout.

Source

pub fn set_overflow_wrap(&mut self, overflow_wrap: OverflowWrap)

Sets the emergency wrap behavior used when wrapping is enabled.

Source

pub fn set_tab_width(&mut self, tab_width: usize)

Sets the visual width of tab characters in spaces.

When set, Floem expands tabs before shaping and keeps a mapping between original and display byte indices so hit-testing still refers back to the source text.

Source

pub fn set_size(&mut self, width: f32, height: f32)

Sets the layout bounds used for reflow.

Width changes trigger line breaking and optional alignment.

Source

pub fn clear_size(&mut self)

Removes any explicit layout size and reflows without a width constraint.

Source

pub fn set_align(&mut self, align: Option<Alignment>)

Sets horizontal alignment for wrapped text.

Source

pub fn text(&self) -> &str

Returns the original source text for this layout.

Source

pub fn parley_layout(&self) -> &Layout<TextBrush>

Returns the underlying Parley layout.

This is an escape hatch for code that genuinely needs direct Parley access and should be used sparingly.

Source

pub fn visual_line_count(&self) -> usize

Returns the number of visual lines currently in the layout.

Source

pub fn size(&self) -> Size

Returns the overall layout size in layout coordinates.

Source

pub fn hit_test(&self, point: Point) -> Option<Cursor>

Performs hit testing and returns the nearest Parley cursor.

The returned cursor remains in display/layout coordinates. Use cursor_to_byte_index when you need a byte index in the original source text.

Source

pub fn cursor_point(&self, idx: usize, affinity: Affinity) -> Point

Returns the cursor’s visual point for a source-text byte index.

The resulting point is in layout coordinates, with x at the cursor position and y at the line baseline.

Source

pub fn line_metrics_at( &self, idx: usize, affinity: Affinity, ) -> Option<LineMetrics>

Returns the visual line metrics for the line containing the given byte index.

The returned metrics are copied from Parley because Parley’s public line wrapper does not allow us to return a borrowed &LineMetrics directly from this wrapper type.

Source

pub fn cursor_to_byte_index(&self, cursor: &Cursor) -> usize

Converts a Parley cursor back into a byte index in the original source text.

This reverses Floem’s internal tab-expansion mapping when tab handling is enabled.

Source

pub fn selection_geometry_with( &self, selection: &TextSelection, f: impl FnMut(f64, f64, f64, f64), )

Iterates selection rectangles for a Parley selection using raw cursor geometry.

Source

pub fn selection_geometry_with_line_metrics( &self, selection: &TextSelection, f: impl FnMut(f64, f64, f64, f64), )

Iterates selection rectangles for a Parley selection using full visual-line metrics.

This is the geometry helper to use for painted selection backgrounds.

Compared with selection_geometry_with, this method:

  • expands each rectangle vertically to the containing line’s full min_coord..max_coord
  • expands horizontal bounds to the actual glyph outline bounds of the selected text

The vertical expansion is important for consistent full-line selection backgrounds. The horizontal expansion is important because cursor/advance-based selection geometry is not always wide enough to cover italic or otherwise overhanging glyph outlines.

The x extents are computed by:

  • starting from Parley’s selection geometry for the selected line fragment
  • scanning the selected glyphs on that line
  • unioning in cached Swash outline bounds for those glyphs

Complexity:

  • baseline Parley selection coverage is proportional to the number of selected line fragments
  • the additional Floem work here is proportional to the number of selected runs/clusters/glyphs on the affected lines
  • outline extraction itself is cached by font blob, font index, glyph id, size, normalized coords, and skew, so repeated paints normally pay lookup cost rather than outline-scaling cost

In practice, this is more expensive than raw cursor-box geometry but is only intended for selection painting, where correct ink coverage matters more than the absolute minimum amount of work.

Source

pub fn visual_line_y(&self, nth: usize) -> Option<f32>

Returns the baseline y coordinate for the nth visual line.

Source

pub fn visual_line_text_range(&self, nth: usize) -> Option<Range<usize>>

Returns the source-text byte range covered by the nth visual line.

Source

pub fn visual_bounds_y(&self) -> Option<(f32, f32)>

Returns the top and bottom extents of the visual line boxes.

Source

pub fn centering_bounds_y(&self) -> Option<(f32, f32)>

Returns the vertical bounds used when visually centering this layout.

Source

pub fn draw(&self, renderer: &mut Renderer, origin: impl Into<Point>)

Draws the layout at the given origin using Floem’s renderer wrapper.

Trait Implementations§

Source§

impl Clone for TextLayout

Source§

fn clone(&self) -> TextLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextLayout

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WasmNotSync for T
where T: Sync,