Struct RichTextLayout
pub struct RichTextLayout { /* private fields */ }Expand description
A laid-out block of attributed text.
Implementations§
§impl RichTextLayout
impl RichTextLayout
pub fn shape_plain(
fs: &mut FontSystem,
text: &str,
style: &TextStyle,
max_width: Option<f32>,
) -> 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
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
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
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 fragment_line_count(&self, available_lines: usize) -> usize
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
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 add_underline(&mut self, range: Range<usize>)
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
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
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)
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)>
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)
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)
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
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)>
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
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)>
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
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
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)>
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)>>
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)>>
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)>>
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)>
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§
impl Freeze for RichTextLayout
impl !RefUnwindSafe for RichTextLayout
impl Send for RichTextLayout
impl Sync for RichTextLayout
impl Unpin for RichTextLayout
impl UnsafeUnpin for RichTextLayout
impl !UnwindSafe for RichTextLayout
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
§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