[][src]Trait pane::CharacterWidthCache

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<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>>
, { ... } }

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.

Associated Types

type Scalar: Scalar

The scalar type for the width

Loading content...

Required methods

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

Get the width of a character at a font size

Loading content...

Provided methods

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

Get the width of a string at a font_size

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

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

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

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

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

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

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

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.

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.

Loading content...

Implementors

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

type Scalar = S

impl<C> CharacterWidthCache for C where
    C: CharacterCache, 
[src]

type Scalar = f64

Loading content...