Trait pane::CharacterWidthCache
source · 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
Required Methods
sourcefn char_width(&mut self, character: char, font_size: u32) -> Self::Scalar
fn char_width(&mut self, character: char, font_size: u32) -> Self::Scalar
Get the width of a character at a font size
Provided Methods
sourcefn width(&mut self, text: &str, font_size: u32) -> Self::Scalar
fn width(&mut self, text: &str, font_size: u32) -> Self::Scalar
Get the width of a string at a font_size
sourcefn format_lines(
&mut self,
text: &str,
max_width: Self::Scalar,
format: TextFormat<Self::Scalar>
) -> Vec<String>
fn format_lines(
&mut self,
text: &str,
max_width: Self::Scalar,
format: TextFormat<Self::Scalar>
) -> Vec<String>
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
sourcefn max_line_width(
&mut self,
text: &str,
max_width: Self::Scalar,
format: TextFormat<Self::Scalar>
) -> Self::Scalar
fn max_line_width(
&mut self,
text: &str,
max_width: Self::Scalar,
format: TextFormat<Self::Scalar>
) -> Self::Scalar
Get the width of the widest line after performing
the calculation of CharacterWidthCache::format_lines
sourcefn justify_text<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> PositionedLines<R::Vector>where
R: Rectangle<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>,
Calculate a set of positioned lines of text with the given format that fit within the given rectangle
sourcefn text_fits_horizontal<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
fn text_fits_horizontal<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
Check if text with the given format fits within a rectangle’s width
sourcefn text_fits_vertical<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
fn text_fits_vertical<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
Check if text with the given format fits within a rectangle’s height
sourcefn text_fits<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
fn text_fits<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> boolwhere
R: Rectangle<Scalar = Self::Scalar>,
Check if text with the given format fits within a rectangle
sourcefn fit_max_font_size<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> u32where
R: Rectangle<Scalar = Self::Scalar>,
fn fit_max_font_size<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>
) -> u32where
R: Rectangle<Scalar = Self::Scalar>,
Determine the maximum font size for text with the given format that will still allow the text to fit within a rectangle
sourcefn fit_min_height<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>,
delta: Self::Scalar
) -> Self::Scalarwhere
R: Rectangle<Scalar = Self::Scalar>,
fn fit_min_height<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>,
delta: Self::Scalar
) -> Self::Scalarwhere
R: Rectangle<Scalar = 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.
sourcefn fit_min_width<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>,
delta: Self::Scalar
) -> Self::Scalarwhere
R: Rectangle<Scalar = Self::Scalar>,
fn fit_min_width<R>(
&mut self,
text: &str,
rect: R,
format: TextFormat<Self::Scalar>,
delta: Self::Scalar
) -> Self::Scalarwhere
R: Rectangle<Scalar = 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.