Trait embedded_graphics::text::renderer::TextRenderer
source · [−]pub trait TextRenderer {
type Color: PixelColor;
fn draw_string<D>(
&self,
text: &str,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error>
where
D: DrawTarget<Color = Self::Color>;
fn draw_whitespace<D>(
&self,
width: u32,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error>
where
D: DrawTarget<Color = Self::Color>;
fn measure_string(
&self,
text: &str,
position: Point,
baseline: Baseline
) -> TextMetrics;
fn line_height(&self) -> u32;
}
Expand description
Text renderer.
The TextRenderer
trait is used to integrate text renderers into embedded-graphics. Users should
not call it directly and instead use the functions provided by the Text
type.
Associated Types
type Color: PixelColor
type Color: PixelColor
Color type.
Required methods
Draws a string.
The method returns the start position of the next character to allow chaining of multiple draw calls.
Implementation notes
This method must not interpret any control characters and only render a single line of text.
Any control character in the text
should be handled the same way as any other character
that isn’t included in the font.
Draws whitespace of the given width.
The method returns the start position of the next character to allow chaining of multiple draw calls.
fn measure_string(
&self,
text: &str,
position: Point,
baseline: Baseline
) -> TextMetrics
fn measure_string(
&self,
text: &str,
position: Point,
baseline: Baseline
) -> TextMetrics
Returns the text metrics for a string.
Implementation notes
The returned bounding box must be independent of the text color. This is different to the
Dimensions
trait, which should return a zero sized bounding box for completely transparent
drawables. But this behavior would make it impossible to correctly layout text which
contains a mixture of transparent and non transparent words.
This method must not interpret any control characters and only render a single line of text.
Any control character in the text
should be handled the same way as any other character
that isn’t included in the font.
fn line_height(&self) -> u32
fn line_height(&self) -> u32
Returns the default line height.
The line height is defined as the vertical distance between the baseline of two adjacent lines in pixels.