Skip to main content

RichTextLayout

Struct RichTextLayout 

pub struct RichTextLayout { /* private fields */ }
Expand description

A laid-out block of attributed text.

Implementations§

§

impl RichTextLayout

pub fn shape_plain( fs: &mut FontSystem, text: &str, style: &TextStyle, max_width: Option<f32>, ) -> RichTextLayout

Shape an un-attributed paragraph with the same complete style used by crate::text_render::TextRenderer. max_width = None produces one unwrapped line (form fields); a width enables Unicode word wrapping.

pub fn block_style( base_bold: bool, size: f32, family: FontFamily, line_height_mult: f32, ) -> TextStyle

The complete style of a legacy text block for Self::shape_styled: base_bold makes the whole block bold (headings) and line_height_mult scales the default 1.4 line advance.

pub fn shape_styled( fs: &mut FontSystem, spans: &[RichSpan], style: &TextStyle, max_width: Option<f32>, align: TextAlign, underlines: Vec<(usize, usize)>, strikes: Vec<(usize, usize)>, ) -> RichTextLayout

Shape attributed spans with the same complete block style used by plain application text. This is the preferred entry point for editors and custom widgets: font family, weight, size, and leading remain one value from measurement through painting.

pub fn shape_styled_reusing( fs: &mut FontSystem, spans: &[RichSpan], style: &TextStyle, max_width: Option<f32>, align: TextAlign, underlines: Vec<(usize, usize)>, strikes: Vec<(usize, usize)>, previous: Option<RichTextLayout>, ) -> RichTextLayout

Reuse unchanged paragraphs from this renderer’s previous layout. The caller must enforce the same font-system identity and generation; font replacement or locale changes require previous = None. Exact retained inputs skip preparation; otherwise fresh paragraph construction remains authoritative for attributes and document offsets, and only compatible cosmic shape/layout caches move over.

pub fn height(&self) -> f32

Total laid-out height (at least one line tall).

pub fn fragment_line_count(&self, available_lines: usize) -> usize

Return the number of lines that may be placed in the current fragment without stranding fewer than the configured orphan/widow counts.

pub fn fragment_line_count_from( &self, first_line: usize, available_lines: usize, ) -> usize

As Self::fragment_line_count, starting at first_line for a paragraph that already spans one or more earlier fragments.

pub fn width(&self) -> f32

Widest laid-out visual line.

pub fn add_underline(&mut self, range: Range<usize>)

Add an underline decoration in this layout’s global byte space. This is used for IME preedit, where the composition is shaped and painted but has not yet entered the document model.

pub fn hit_position(&self, x: f32, y: f32) -> TextPosition

Map a local point to a byte offset and its visual boundary affinity.

pub fn hit(&self, x: f32, y: f32) -> usize

Map a local point to a byte offset (click → caret).

Prefer Self::hit_position in an editor so a mixed-BiDi boundary keeps the side that was clicked.

pub fn caret_geometry_at(&self, position: TextPosition) -> (f32, f32, f32)

Caret geometry for a byte offset and affinity: (x, top_y, height).

pub fn caret_geometry_bounded(&self, byte: usize) -> Option<(f32, f32, f32)>

Observer caret geometry with the same per-run work limits as Self::selection_rects_bounded. Missing stops and invalid positions are unavailable, never the ordinary editor’s origin fallback.

pub fn caret_geometry(&self, byte: usize) -> (f32, f32, f32)

Caret geometry for a conventional byte-only position.

pub fn visual_line_edges(&self, byte: usize) -> (usize, usize)

Logical byte positions reached by Home and End for the visual line containing byte. Paragraph direction is respected: Home is the right edge for an RTL line and the left edge for an LTR line.

pub fn visual_line_index(&self, byte: usize) -> usize

Zero-based visual row containing byte, including soft-wrapped rows.

pub fn logical_line_bands(&self, byte: usize) -> Vec<(f32, f32)>

Vertical bands for every soft-wrapped visual row belonging to the logical line that contains byte. Useful for editor chrome such as a current-line background without rebuilding a second line model.

pub fn logical_line_index(&self, byte: usize) -> usize

Zero-based logical (hard-broken) line containing byte.

pub fn logical_line_origins(&self) -> Vec<(usize, f32, f32)>

The first visual row for each logical line as (zero_based_line, top, height). Line-number gutters consume this so their baselines come from the authoritative shaped paragraph too.

pub fn visual_motion_position( &self, position: TextPosition, right: bool, ) -> TextPosition

Move one shaped caret stop toward the visual left or right. Stops are derived from grapheme boundaries inside each glyph cluster, so this respects ligatures, combining sequences, and BiDi reordering.

pub fn visual_motion(&self, byte: usize, right: bool) -> usize

Byte-only compatibility wrapper for visual caret motion.

pub fn selection_rects( &self, start: usize, end: usize, ) -> Vec<(f32, f32, f32, f32)>

Selection rectangles (x0, y0, x1, y1) for byte range [start, end).

pub fn selection_rects_bounded( &self, range: Range<usize>, band: Range<f32>, maximum: usize, ) -> Option<Vec<(f32, f32, f32, f32)>>

Selection rectangles in a vertical layout band, refusing overflow instead of returning a partial selection. Caller byte validation is unchanged. This bounded observer path also refuses a visible run with more than 65,536 glyphs or summed glyph-source bytes: the shaper’s highlight iterator internally collects its per-run spans first. Ordinary editing continues to use the unrestricted APIs below/above.

pub fn selection_rects_many( &self, ranges: &[(usize, usize)], ) -> Vec<Vec<(f32, f32, f32, f32)>>

Self::selection_rects for several byte ranges in one pass over the layout runs, in input order. A long paragraph is one logical line with many visual runs; the per-range form walks every run and every glyph of it once per range, so decorating every span of a pasted page (spell-check squiggles, find matches) was quadratic in the paragraph length. Here each run looks up only the ranges that can touch its byte extent (sorted starts plus a running maximum of ends), which yields exactly the same rectangles.

pub fn selection_rects_many_within( &self, ranges: &[(usize, usize)], top: f32, bottom: f32, ) -> Vec<Vec<(f32, f32, f32, f32)>>

Self::selection_rects_many restricted to visual lines that overlap the vertical band [top, bottom] (layout coordinates). Rectangles of lines entirely outside the band are omitted; a caller passing its clip paints exactly what the unrestricted form would have shown.

pub fn source_range_within( &self, top: f32, bottom: f32, ) -> Option<(usize, usize)>

Source byte range [start, end) covered by the visual lines that overlap the vertical band [top, bottom], or None when no line does. Callers with many decorated spans use it to skip spans that cannot reach the band before asking for their geometry.

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
§

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<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

§

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

§

impl<T> WasmNotSendSync for T

§

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