Trait fit_text::CharacterWidthCache[][src]

pub trait CharacterWidthCache: Sized {
Show 13 methods fn char_width(&mut self, character: char, font_size: u32) -> f64; fn width(&mut self, text: &str, font_size: u32) -> f64 { ... }
fn format_lines<S, F>(
        &mut self,
        text: S,
        max_width: f64,
        format: F
    ) -> Vec<String>
    where
        S: AsRef<str>,
        F: Into<TextFormat>
, { ... }
fn max_line_width<S, F>(
        &mut self,
        text: S,
        max_width: f64,
        format: F
    ) -> f64
    where
        S: AsRef<str>,
        F: Into<TextFormat>
, { ... }
fn justify_text<S, R, F>(
        &mut self,
        text: S,
        rect: R,
        format: F
    ) -> PositionedLines<R::Vector>
    where
        S: AsRef<str>,
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn justify_meta_fragments<I, M, S, R, F>(
        &mut self,
        fragments: I,
        rect: R,
        format: F
    ) -> PositionedLinesMeta<R::Vector, M>
    where
        I: IntoIterator<Item = (S, M)>,
        M: Clone,
        S: AsRef<str>,
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn text_fits_horizontal<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F
    ) -> bool
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn text_fits_vertical<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F
    ) -> bool
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn text_fits<R, F>(&mut self, text: &str, rect: R, format: F) -> bool
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn fit_max_font_size<R, F>(&mut self, text: &str, rect: R, format: F) -> u32
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn fit_min_height<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
        delta: f64
    ) -> f64
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn fit_min_width<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F,
        delta: f64
    ) -> f64
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
fn ideal_text_size<R, F>(
        &mut self,
        text: &str,
        rect: R,
        format: F
    ) -> TextFormat
    where
        R: Rectangle,
        R::Vector: Vector2<Scalar = f64>,
        F: Into<TextFormat>
, { ... }
}
Expand description

Defines behavior of a cache of character widths.

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

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

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

This is useful when you have multiple fragments of text each with some associated metadata, such as a color. Fragments that are split between lines will have their metadata cloned

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.

Determine the correct text size based on the given TextFormat

Implementors