Struct FontMetrics

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

TextMeasure implementation backed by fontdue (UI + bundled mono).

Construction probes a small list of common Linux sans-serif paths. The monospace slot first uses the bundled font. If a requested face is absent, measurement falls back to ApproxTextMeasure, so construction and measurement are infallible and portable.

§Examples

use ailloli_ui_core::FontId;
use ailloli_ui_text::{FontMetrics, TextMeasure};
let metrics = FontMetrics::new();
assert_eq!(metrics.measure("", FontId::Ui, 16), 0.0);

Implementations§

Source§

impl FontMetrics

Source

pub fn new() -> Self

Loads the bundled monospace face and probes common Linux UI-font paths.

Missing or invalid system files are silently skipped. This function does filesystem I/O but never returns an error; unavailable faces use the approximate fallback during measurement.

§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::{FontMetrics, TextMeasure};
let metrics = FontMetrics::new();
assert!(metrics.advance('x', FontId::Mono, 14) >= 0.0);

Trait Implementations§

Source§

impl Default for FontMetrics

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TextMeasure for FontMetrics

Source§

fn measure(&self, text: &str, font: FontId, px_size: u16) -> f32

Returns the estimated logical-pixel advance of text at px_size. Read more
Source§

fn advance(&self, ch: char, font: FontId, px_size: u16) -> f32

Returns the logical-pixel advance of one Unicode scalar. 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.
§

impl<T> ErasedDestructor for T
where T: 'static,