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
impl TextLayout
Sourcepub fn selection(&self, anchor: Cursor, focus: Cursor) -> TextSelection
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.
Sourcepub fn clear_selection_geometry_cache()
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.
Sourcepub fn begin_selection(&self, anchor: Cursor, focus: Cursor) -> TextSelection
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.
Sourcepub fn begin_selection_from_byte_range(
&self,
start_byte: usize,
end_byte: usize,
) -> TextSelection
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.
Sourcepub fn collapsed_selection(&self, cursor: Cursor) -> TextSelection
pub fn collapsed_selection(&self, cursor: Cursor) -> TextSelection
Creates a new collapsed selection at the given cursor.
Sourcepub fn selection_from_byte_range(
&self,
start_byte: usize,
end_byte: usize,
) -> TextSelection
pub fn selection_from_byte_range( &self, start_byte: usize, end_byte: usize, ) -> TextSelection
Creates a Parley selection from a source-text byte range.
Sourcepub fn selection_from_byte_positions(
&self,
anchor_byte: usize,
focus_byte: usize,
) -> Option<TextSelection>
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.
Sourcepub fn begin_selection_from_byte_positions(
&self,
anchor_byte: usize,
focus_byte: usize,
) -> Option<TextSelection>
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.
Sourcepub fn selection_text_range(&self, selection: &TextSelection) -> Range<usize>
pub fn selection_text_range(&self, selection: &TextSelection) -> Range<usize>
Converts a Parley selection into a byte range in the original source text.
Sourcepub fn new_with_text(
text: &str,
attrs_list: AttrsList,
align: Option<Alignment>,
) -> Self
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.
Sourcepub fn set_text(
&mut self,
text: &str,
attrs_list: AttrsList,
align: Option<Alignment>,
)
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.
Sourcepub fn set_text_wrap_mode(&mut self, text_wrap_mode: TextWrapMode)
pub fn set_text_wrap_mode(&mut self, text_wrap_mode: TextWrapMode)
Sets the primary wrap mode used when reflowing the layout.
Sourcepub fn set_overflow_wrap(&mut self, overflow_wrap: OverflowWrap)
pub fn set_overflow_wrap(&mut self, overflow_wrap: OverflowWrap)
Sets the emergency wrap behavior used when wrapping is enabled.
Sourcepub fn set_tab_width(&mut self, tab_width: usize)
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.
Sourcepub fn set_size(&mut self, width: f32, height: f32)
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.
Sourcepub fn clear_size(&mut self)
pub fn clear_size(&mut self)
Removes any explicit layout size and reflows without a width constraint.
Sourcepub fn set_align(&mut self, align: Option<Alignment>)
pub fn set_align(&mut self, align: Option<Alignment>)
Sets horizontal alignment for wrapped text.
Sourcepub fn parley_layout(&self) -> &Layout<TextBrush>
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.
Sourcepub fn visual_line_count(&self) -> usize
pub fn visual_line_count(&self) -> usize
Returns the number of visual lines currently in the layout.
Sourcepub fn hit_test(&self, point: Point) -> Option<Cursor>
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.
Sourcepub fn cursor_point(&self, idx: usize, affinity: Affinity) -> Point
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.
Sourcepub fn line_metrics_at(
&self,
idx: usize,
affinity: Affinity,
) -> Option<LineMetrics>
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.
Sourcepub fn cursor_to_byte_index(&self, cursor: &Cursor) -> usize
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.
Sourcepub fn selection_geometry_with(
&self,
selection: &TextSelection,
f: impl FnMut(f64, f64, f64, f64),
)
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.
Sourcepub fn selection_geometry_with_line_metrics(
&self,
selection: &TextSelection,
f: impl FnMut(f64, f64, f64, f64),
)
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.
Sourcepub fn visual_line_y(&self, nth: usize) -> Option<f32>
pub fn visual_line_y(&self, nth: usize) -> Option<f32>
Returns the baseline y coordinate for the nth visual line.
Sourcepub fn visual_line_text_range(&self, nth: usize) -> Option<Range<usize>>
pub fn visual_line_text_range(&self, nth: usize) -> Option<Range<usize>>
Returns the source-text byte range covered by the nth visual line.
Sourcepub fn visual_bounds_y(&self) -> Option<(f32, f32)>
pub fn visual_bounds_y(&self) -> Option<(f32, f32)>
Returns the top and bottom extents of the visual line boxes.
Sourcepub fn centering_bounds_y(&self) -> Option<(f32, f32)>
pub fn centering_bounds_y(&self) -> Option<(f32, f32)>
Returns the vertical bounds used when visually centering this layout.
Trait Implementations§
Source§impl Clone for TextLayout
impl Clone for TextLayout
Source§fn clone(&self) -> TextLayout
fn clone(&self) -> TextLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextLayout
impl Debug for TextLayout
Auto Trait Implementations§
impl Freeze for TextLayout
impl !RefUnwindSafe for TextLayout
impl Send for TextLayout
impl Sync for TextLayout
impl Unpin for TextLayout
impl UnsafeUnpin for TextLayout
impl !UnwindSafe for TextLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().