Skip to main content

LayoutLine

Struct LayoutLine 

Source
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: f32

Baseline y relative to block top (set by block layout).

§ascent: f32§descent: f32§leading: f32§line_height: f32

Total line height: ascent + descent + leading.

§width: f32

Actual content width (sum of run advances).

§char_range: Range<usize>

Character range in the block’s text.

Implementations§

Source§

impl LayoutLine

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LayoutLine

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

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.