Skip to main content

LineLayout

Struct LineLayout 

Source
pub struct LineLayout {
    pub font_size: Pixels,
    pub width: Pixels,
    pub ascent: Pixels,
    pub descent: Pixels,
    pub runs: Vec<ShapedRun>,
    pub len: usize,
}
Expand description

A laid out and styled line of text

Fields§

§font_size: Pixels

The font size for this line

§width: Pixels

The width of the line

§ascent: Pixels

The ascent of the line

§descent: Pixels

The descent of the line

§runs: Vec<ShapedRun>

The shaped runs that make up this line

§len: usize

The length of the line in utf-8 bytes

Implementations§

Source§

impl LineLayout

Source

pub fn index_for_x(&self, x: Pixels) -> Option<usize>

The index for the character at the given x coordinate

Source

pub fn closest_index_for_x(&self, x: Pixels) -> usize

closest_index_for_x returns the character boundary closest to the given x coordinate (e.g. to handle aligning up/down arrow keys)

Source

pub fn x_for_index(&self, index: usize) -> Pixels

The x position of the character at the given index

Source

pub fn font_id_for_index(&self, index: usize) -> Option<FontId>

The corresponding Font at the given index

Source

pub fn split_at(&self, byte_index: usize) -> (LineLayout, LineLayout)

Split this layout at a byte index, returning (prefix, suffix).

  • prefix contains glyphs for bytes [0, byte_index) with original positions. Its width equals the x-advance up to the split point.
  • suffix contains glyphs for bytes [byte_index, len) with positions shifted left so the first glyph starts at x=0, and byte indices rebased to 0.
  • font_size, ascent, and descent are copied to both halves.

Trait Implementations§

Source§

impl Debug for LineLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LineLayout

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.