pub struct LayoutLine {
pub runs: Vec<PositionedRun>,
pub y: f32,
pub ascent: f32,
pub descent: f32,
pub leading: f32,
pub line_height: f32,
pub width: f32,
pub char_range: Range<usize>,
}Fields§
§runs: Vec<PositionedRun>§y: f32Baseline y relative to block top (set by block layout).
ascent: f32§descent: f32§leading: f32§line_height: f32Total line height: ascent + descent + leading.
width: f32Actual content width (sum of run advances).
char_range: Range<usize>Character range in the block’s text.
Implementations§
Source§impl LayoutLine
impl LayoutLine
Sourcepub fn x_for_offset(&self, offset: usize) -> f32
pub fn x_for_offset(&self, offset: usize) -> f32
Find the x coordinate for a char offset within this line.
Equivalent to Self::x_for_offset_with_affinity with the
default (downstream) affinity — the caret attaches to the text
before the offset.
Sourcepub fn x_for_offset_with_affinity(
&self,
offset: usize,
affinity: CursorAffinity,
) -> f32
pub fn x_for_offset_with_affinity( &self, offset: usize, affinity: CursorAffinity, ) -> f32
Find the x coordinate for a char offset, disambiguating a
direction boundary with affinity.
Builds the line’s caret stops in visual order — direction-aware,
so an RTL run’s caret for its lowest offset sits at its rightmost
edge — then returns the x of the stop matching offset.
One offset can produce two stops. Where an LTR run meets an RTL one, the boundary offset is both the trailing edge of the run before it and the leading edge of the run after it, and those sit at completely different x — often at opposite ends of the line. Neither is “the” answer: which one the writer means depends on which side they arrived from, so it is the caller’s to say. Picking the leftmost, as this used to, put the caret at the far end of the line whenever the seam ran the other way.
Downstream attaches the caret to the text before the offset (the
trailing stop), Upstream to the text after it (the leading
stop) — the same “before or after” question affinity already
answers at a soft-wrap boundary.
Sourcepub fn is_direction_boundary(&self, offset: usize) -> bool
pub fn is_direction_boundary(&self, offset: usize) -> bool
Whether offset sits on a direction boundary within this line —
i.e. whether Self::x_for_offset_with_affinity would return
different x for the two affinities.
The widget layer needs this to know when moving the caret across a seam has to flip affinity rather than leave it alone.
Trait Implementations§
Source§impl Clone for LayoutLine
impl Clone for LayoutLine
Source§fn clone(&self) -> LayoutLine
fn clone(&self) -> LayoutLine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more