Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout {
    pub runs: Vec<GlyphRun>,
    pub decos: Vec<Deco>,
    pub lines: Vec<LineInfo>,
    pub inner: Rect,
    pub content_height: f64,
    pub content_width: f64,
    pub font_scale: f64,
    pub line_reduction: f64,
    pub overflow: bool,
    pub rotation: f64,
    pub para_lines: Vec<(usize, usize)>,
    pub boundaries: Vec<Vec<bool>>,
}

Fields§

§runs: Vec<GlyphRun>§decos: Vec<Deco>§lines: Vec<LineInfo>§inner: Rect

Inner text box (insets applied), shape-local.

§content_height: f64

Height of the laid-out text (before anchoring).

§content_width: f64

Widest line.

§font_scale: f64

Autofit font scale used (1 = none).

§line_reduction: f64§overflow: bool§rotation: f64

Text rotation about the shape centre, degrees (vertical text = 90/270).

§para_lines: Vec<(usize, usize)>

Per paragraph: (first line index, line count).

§boundaries: Vec<Vec<bool>>

Per paragraph: whether a caret may stand at each character offset 0..=len (grapheme boundaries), for logical caret movement.

Implementations§

Source§

impl TextLayout

Source

pub fn line_of(&self, pos: Pos) -> Option<usize>

The line containing a caret position (the later line at a soft wrap boundary).

Source

pub fn line_of_affine(&self, pos: Pos, affinity: Affinity) -> Option<usize>

The line containing a caret position: at a soft wrap boundary, the earlier line for an upstream caret and the later one for a downstream caret.

Source

pub fn caret(&self, pos: Pos) -> Option<(f64, f64, f64)>

Caret line segment (x, top, bottom) in shape-local, unrotated coordinates (downstream).

Source

pub fn caret_at(&self, pos: Pos, affinity: Affinity) -> Option<(f64, f64, f64)>

Caret line segment (x, top, bottom) for a position and affinity: downstream at the leading edge of the character after the boundary, upstream at the trailing edge of the one before.

Source

pub fn hit(&self, p: Point) -> Pos

Nearest caret position for a point.

Source

pub fn hit_affinity(&self, p: Point) -> (Pos, Affinity)

Nearest caret position for a point, with the affinity that keeps the caret on the side of the character that was hit (bidi text has two carets at a direction change).

Source

pub fn move_caret( &self, pos: Pos, affinity: Affinity, forward: bool, mode: MoveMode, ) -> (Pos, Affinity)

Move a caret one grapheme: logically (forward = towards the end of the text, crossing paragraphs) or visually (forward = to the right on screen, continuing on the next or previous line in the paragraph’s direction at the line’s edge).

Source

pub fn selection_rects(&self, a: Pos, b: Pos) -> Vec<Rect>

Selection highlight rectangles between two positions: per line, the union of the visual boxes of the selected characters (one logical range can be several boxes in bidi text).

Source

pub fn composition_underlines(&self, a: Pos, b: Pos) -> Vec<(f64, f64, f64)>

Underlines for text an input method is composing, from a to b (#101): (x0, x1, y) per visual span, a little below each line’s baseline (PowerPoint underlines the composition in place). A composition that wraps gets one underline per line.

Source

pub fn vertical(&self, pos: Pos, down: bool, x: f64) -> Pos

Vertical caret movement: the position on the line above/below closest to x.

Source

pub fn line_index(&self, pos: Pos, affinity: Affinity) -> Option<usize>

The line a caret is on. An upstream caret at the start of a soft-wrapped line (where End leaves it, after the previous line’s trailing spaces) belongs to the line before.

Source

pub fn vertical_affine( &self, pos: Pos, affinity: Affinity, down: bool, x: f64, ) -> (Pos, Affinity)

Up/Down from a caret with its affinity: the position on the line above/below nearest x.

Source

pub fn line_bounds(&self, pos: Pos) -> (Pos, Pos)

Start/end of the visual line containing pos (logical: Home/End).

Source

pub fn line_bounds_affine(&self, pos: Pos, affinity: Affinity) -> (Pos, Pos)

Start/end of the visual line a caret with this affinity is on.

Source

pub fn line_end_caret(&self, pos: Pos, affinity: Affinity) -> (Pos, Affinity)

Where End puts the caret: after a soft wrap, past the line’s trailing spaces at the start of the next line with upstream affinity (so it is still drawn on this line), else the end of the paragraph.

Source

pub fn caret_drawn( &self, pos: Pos, affinity: Affinity, ) -> Option<(f64, f64, f64)>

The caret to draw (x, top, bottom): an upstream caret after a soft wrap is drawn at the end of the line it belongs to.

Source

pub fn bounds(&self) -> Rect

Bounding box of all glyphs/lines (shape-local).

Trait Implementations§

Source§

impl Clone for TextLayout

Source§

fn clone(&self) -> Self

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

impl Debug for TextLayout

Source§

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

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

impl Default for TextLayout

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> 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> 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> 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 = !

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.