Skip to main content

TextMeasure

Struct TextMeasure 

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

The width a run of text lays out to, shaped exactly as TextLayer draws it: the system sans-serif family, advanced shaping, one line.

GPU-free — it owns a font system and nothing else — so layout that depends on a measurement can be tested without a device. The fonts are the machine’s, so a width is only ever compared against another width from the same measurer, never against a written-down number.

Implementations§

Source§

impl TextMeasure

Source

pub fn new() -> Self

A measurer over the system’s fonts. Loads the font set, which is slow; build one and keep it.

Source

pub fn width(&mut self, text: &str, size: f32) -> f32

The laid-out width of text at size device pixels. 0.0 for an empty string or a size that is not positive and finite.

Source

pub fn fit<'a>( &mut self, text: &'a str, size: f32, max_width: f32, ) -> Cow<'a, str>

text shortened to fit max_width at size, with an ASCII ellipsis — fit_width over this measurer.

Trait Implementations§

Source§

impl Default for TextMeasure

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,