Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout;

Implementations§

Source§

impl TextLayout

Source

pub fn new() -> Self

Source

pub fn break_into_lines( &self, font_context: &FontContext, text: &str, max_width: f64, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, hyphens: Hyphens, lang: Option<&str>, ) -> Vec<BrokenLine>

Break a string into lines that fit within max_width.

Uses a greedy line-breaking algorithm with optional hyphenation. When hyphens is Auto, long words that don’t fit are split at syllable boundaries using the Knuth-Liang algorithm. When Manual, only soft hyphens (U+00AD) in the text are used as break points.

Source

pub fn shape_text( &self, font_context: &FontContext, text: &str, font_family: &str, font_weight: u32, font_style: FontStyle, ) -> Option<Vec<ShapedGlyph>>

Shape text and return shaped glyphs for a custom font. Returns None for standard fonts or if shaping fails.

Source

pub fn break_runs_into_lines( &self, font_context: &FontContext, chars: &[StyledChar], max_width: f64, hyphens: Hyphens, lang: Option<&str>, ) -> Vec<RunBrokenLine>

Break multi-style text (runs) into lines that fit within max_width.

Source

pub fn measure_widest_word( &self, font_context: &FontContext, text: &str, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, hyphens: Hyphens, lang: Option<&str>, ) -> f64

Measure the widest single word in a string (min-content width).

When hyphens is Auto, returns the widest syllable width instead of the widest word, since hyphenation allows breaking within words.

Source

pub fn measure_width( &self, font_context: &FontContext, text: &str, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, ) -> f64

Measure the width of a string on a single line.

Source

pub fn break_into_lines_optimal( &self, font_context: &FontContext, text: &str, max_width: f64, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, hyphens: Hyphens, lang: Option<&str>, justify: bool, ) -> Vec<BrokenLine>

Break text into lines using the Knuth-Plass optimal algorithm.

Falls back to greedy breaking if KP finds no feasible solution.

Source

pub fn break_runs_into_lines_optimal( &self, font_context: &FontContext, chars: &[StyledChar], max_width: f64, hyphens: Hyphens, lang: Option<&str>, justify: bool, ) -> Vec<RunBrokenLine>

Break multi-style text into lines using the Knuth-Plass optimal algorithm.

Falls back to greedy breaking if KP finds no feasible solution.

Source

pub fn truncate_with_ellipsis( &self, font_context: &FontContext, lines: Vec<BrokenLine>, max_width: f64, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, ) -> Vec<BrokenLine>

Truncate lines to a single line with ellipsis appended if it exceeds max_width.

Source

pub fn truncate_clip( &self, font_context: &FontContext, lines: Vec<BrokenLine>, max_width: f64, font_size: f64, font_family: &str, font_weight: u32, font_style: FontStyle, letter_spacing: f64, ) -> Vec<BrokenLine>

Truncate lines to a single line by clipping (no indicator appended).

Source

pub fn truncate_runs_with_ellipsis( &self, font_context: &FontContext, lines: Vec<RunBrokenLine>, max_width: f64, ) -> Vec<RunBrokenLine>

Truncate multi-style run lines to a single line with ellipsis.

Source

pub fn truncate_runs_clip( &self, font_context: &FontContext, lines: Vec<RunBrokenLine>, max_width: f64, ) -> Vec<RunBrokenLine>

Truncate multi-style run lines to a single line by clipping.

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V