pub trait CharacterWidthCache {
    type Scalar: Scalar;

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

    fn width(&mut self, text: &str, font_size: u32) -> Self::Scalar { ... }
    fn format_lines(
        &mut self,
        text: &str,
        max_width: Self::Scalar,
        format: TextFormat<Self::Scalar>
    ) -> Vec<String> { ... } fn max_line_width(
        &mut self,
        text: &str,
        max_width: Self::Scalar,
        format: TextFormat<Self::Scalar>
    ) -> Self::Scalar { ... } fn justify_text<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>
    ) -> PositionedLines<R::Vector>
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn text_fits_horizontal<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>
    ) -> bool
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn text_fits_vertical<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>
    ) -> bool
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn text_fits<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>
    ) -> bool
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn fit_max_font_size<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>
    ) -> u32
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn fit_min_height<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>,
        delta: Self::Scalar
    ) -> Self::Scalar
    where
        R: Rectangle<Scalar = Self::Scalar>
, { ... } fn fit_min_width<R>(
        &mut self,
        text: &str,
        rect: R,
        format: TextFormat<Self::Scalar>,
        delta: Self::Scalar
    ) -> Self::Scalar
    where
        R: Rectangle<Scalar = 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

The scalar type for the width

Required Methods

Get the width of a character at a font size

Provided Methods

Get the width of a string at a font_size

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

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

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

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

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

Check if text with the given format fits within a rectangle

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

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.

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.

Implementors