Trait embedded_graphics::text::renderer::TextRenderer [−][src]
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[src]
type Color: PixelColor[src]Color type.
Required methods
fn draw_string<D>(
&self,
text: &str,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error> where
D: DrawTarget<Color = Self::Color>, [src]
fn draw_string<D>(
&self,
text: &str,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error> where
D: DrawTarget<Color = Self::Color>, [src]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.
fn draw_whitespace<D>(
&self,
width: u32,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error> where
D: DrawTarget<Color = Self::Color>, [src]
fn draw_whitespace<D>(
&self,
width: u32,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error> where
D: DrawTarget<Color = Self::Color>, [src]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[src]
fn measure_string(
&self,
text: &str,
position: Point,
baseline: Baseline
) -> TextMetrics[src]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[src]
fn line_height(&self) -> u32[src]Returns the default line height.
The line height is defined as the vertical distance between the baseline of two adjacent lines in pixels.
Implementors
impl<C: PixelColor> TextRenderer for MonoTextStyle<'_, C>[src]
impl<C: PixelColor> TextRenderer for MonoTextStyle<'_, C>[src]type Color = C
fn draw_string<D>(
&self,
text: &str,
position: Point,
baseline: Baseline,
target: &mut D
) -> Result<Point, D::Error> where
D: DrawTarget<Color = Self::Color>, [src]
&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>, [src]
&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[src]
&self,
text: &str,
position: Point,
baseline: Baseline
) -> TextMetrics