[−][src]Trait fit_text::CharacterWidthCache
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
fn char_width(&mut self, character: char, font_size: u32) -> f64
Get the width of a character at a font size
Provided methods
fn width(&mut self, text: &str, font_size: u32) -> f64
Get the width of a string at a font_size
fn format_lines<S, F>(
&mut self,
text: S,
max_width: f64,
format: F
) -> Vec<String> where
S: AsRef<str>,
F: Into<TextFormat>,
&mut self,
text: S,
max_width: f64,
format: F
) -> Vec<String> where
S: AsRef<str>,
F: Into<TextFormat>,
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<S, F>(&mut self, text: S, max_width: f64, format: F) -> f64 where
S: AsRef<str>,
F: Into<TextFormat>,
S: AsRef<str>,
F: Into<TextFormat>,
Get the width of the widest line after performing
the calculation of CharacterWidthCache::format_lines
fn justify_text<S, R, F>(
&mut self,
text: S,
rect: R,
format: F
) -> PositionedLines<R::Vector> where
S: AsRef<str>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
&mut self,
text: S,
rect: R,
format: F
) -> PositionedLines<R::Vector> where
S: AsRef<str>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
Calculate a set of positioned lines of text with the given format that fit within the given rectangle
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<Scalar = f64>,
F: Into<TextFormat>,
&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<Scalar = f64>,
F: Into<TextFormat>,
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
fn text_fits_horizontal<R, F>(&mut self, text: &str, rect: R, format: F) -> bool where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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 = f64>,
F: Into<TextFormat>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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 = f64>,
F: Into<TextFormat>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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 = f64>,
F: Into<TextFormat>,
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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: f64
) -> f64 where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
&mut self,
text: &str,
rect: R,
format: F,
delta: f64
) -> f64 where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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: f64
) -> f64 where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
&mut self,
text: &str,
rect: R,
format: F,
delta: f64
) -> f64 where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
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.
fn ideal_text_size<R, F>(
&mut self,
text: &str,
rect: R,
format: F
) -> TextFormat where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
&mut self,
text: &str,
rect: R,
format: F
) -> TextFormat where
R: Rectangle<Scalar = f64>,
F: Into<TextFormat>,
Determine the correct text size based on the given TextFormat
Implementors
impl<'f> CharacterWidthCache for BasicGlyphs<'f>
[src]
fn char_width(&mut self, character: char, font_size: u32) -> f64
[src]
impl<C> CharacterWidthCache for C where
C: CharacterCache,
[src]
C: CharacterCache,