Trait CharacterWidthCache

Source
pub trait CharacterWidthCache {
    type Scalar: Scalar;

    // Required method
    fn char_width(&mut self, character: char, font_size: u32) -> Self::Scalar;

    // Provided methods
    fn width(&mut self, text: &str, font_size: u32) -> Self::Scalar { ... }
    fn format_lines<F>(
        &mut self,
        text: &str,
        max_width: Self::Scalar,
        format: F,
    ) -> Vec<String>
       where F: Into<TextFormat<Self::Scalar>> { ... }
    fn max_line_width<F>(
        &mut self,
        text: &str,
        max_width: Self::Scalar,
        format: F,
    ) -> Self::Scalar
       where F: Into<TextFormat<Self::Scalar>> { ... }
    fn justify_text<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
    ) -> PositionedLines<R::Vector>
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn text_fits_horizontal<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
    ) -> bool
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn text_fits_vertical<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
    ) -> bool
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn text_fits<R, F>(&mut self, text: &str, rect: R, format: F) -> bool
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn fit_max_font_size<R, F>(&mut self, text: &str, rect: R, format: F) -> u32
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn fit_min_height<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
        delta: Self::Scalar,
    ) -> Self::Scalar
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
    fn fit_min_width<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
        delta: Self::Scalar,
    ) -> Self::Scalar
       where R: Rectangle<Scalar = Self::Scalar>,
             F: Into<TextFormat<Self::Scalar>> { ... }
}
Expand description

Defines behavior of a cache of character widths.

In general, determining the width of a character glyphs with a given font size is a non-trivial calculation. Caching a width calculation for each characters and font size ensures that the calculation is only done once for each pair.

Required Associated Types§

Source

type Scalar: Scalar

The scalar type for the width

Required Methods§

Source

fn char_width(&mut self, character: char, font_size: u32) -> Self::Scalar

Get the width of a character at a font size

Provided Methods§

Source

fn width(&mut self, text: &str, font_size: u32) -> Self::Scalar

Get the width of a string at a font_size

Source

fn format_lines<F>( &mut self, text: &str, max_width: Self::Scalar, format: F, ) -> Vec<String>
where F: Into<TextFormat<Self::Scalar>>,

Split a string into a list of lines of text with the given format where no line is wider than the given max width. Newlines (\n) in the string are respected

Source

fn max_line_width<F>( &mut self, text: &str, max_width: Self::Scalar, format: F, ) -> Self::Scalar
where F: Into<TextFormat<Self::Scalar>>,

Get the width of the widest line after performing the calculation of CharacterWidthCache::format_lines

Source

fn justify_text<R, F>( &mut self, text: &str, rect: R, format: F, ) -> PositionedLines<R::Vector>
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Calculate a set of positioned lines of text with the given format that fit within the given rectangle

Source

fn text_fits_horizontal<R, F>(&mut self, text: &str, rect: R, format: F) -> bool
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Check if text with the given format fits within a rectangle’s width

Source

fn text_fits_vertical<R, F>(&mut self, text: &str, rect: R, format: F) -> bool
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Check if text with the given format fits within a rectangle’s height

Source

fn text_fits<R, F>(&mut self, text: &str, rect: R, format: F) -> bool
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Check if text with the given format fits within a rectangle

Source

fn fit_max_font_size<R, F>(&mut self, text: &str, rect: R, format: F) -> u32
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Determine the maximum font size for text with the given format that will still allow the text to fit within a rectangle

Source

fn fit_min_height<R, F>( &mut self, text: &str, rect: R, format: F, delta: Self::Scalar, ) -> Self::Scalar
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Determine the minumum height for a rectangle such that text with the given format will still fit within the rectangle

The given delta value defines how much to increment the rectangle’s height on each check. Lower deltas will yield more accurate results, but will take longer to computer.

Source

fn fit_min_width<R, F>( &mut self, text: &str, rect: R, format: F, delta: Self::Scalar, ) -> Self::Scalar
where R: Rectangle<Scalar = Self::Scalar>, F: Into<TextFormat<Self::Scalar>>,

Determine the minumum width for a rectangle such that text with the given format will still fit within the rectangle

The given delta value defines how much to increment the rectangle’s width on each check. Lower deltas will yield more accurate results, but will take longer to computer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'f, S> CharacterWidthCache for Glyphs<'f, S>
where S: Scalar,

Source§

impl<C> CharacterWidthCache for C
where C: CharacterCache,