Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout { /* private fields */ }
Expand description

A block of text shaped with a single style.

TextLayout is retained by text elements: shaping results are cached per paragraph by cosmic-text, and measurements are cached per wrap width, so re-layout after a parent resize only re-wraps lines.

Implementations§

Source§

impl TextLayout

Source

pub fn new() -> Self

Source

pub fn text(&self) -> &str

Source

pub fn style(&self) -> Option<&TextStyle>

Source

pub fn set( &mut self, ts: &mut TextSystem, text: &str, style: &TextStyle, ) -> bool

Updates text and style. Returns true if the layout (size) may have changed; paint-only style changes return false.

Source

pub fn measure(&mut self, ts: &mut TextSystem, max_width: Option<f32>) -> Size

Measures the text wrapped to max_width (None = no wrapping).

Source

pub fn layout(&mut self, ts: &mut TextSystem, width: Option<f32>) -> Size

Lays the text out for painting at the final width.

Source

pub fn size(&self) -> Size

Size at the current layout width.

Source

pub fn lines(&self) -> Vec<LineMetrics>

Visual lines at the current layout width.

Source

pub fn for_each_glyph( &self, origin: Point, scale: f32, f: impl FnMut(GlyphInstance), )

Visits every glyph positioned for an origin given in logical pixels, rendered at scale device pixels per logical pixel.

Source

pub fn hit_test(&self, point: Point) -> usize

Byte offset of the character boundary closest to point (logical px, relative to the text origin).

Source

pub fn caret_bounds(&self, offset: usize) -> Bounds

Caret rectangle for byte offset (logical px, relative to the origin).

Source

pub fn selection_bounds(&self, start: usize, end: usize) -> Vec<Bounds>

Highlight rectangles covering the byte range (logical px).

Trait Implementations§

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