Trait embedded_graphics::text::renderer::TextRenderer

source ·
pub trait TextRenderer {
    type Color: PixelColor;

    // 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>;
    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.

Required Associated Types§

source

type Color: PixelColor

Color type.

Required Methods§

source

fn draw_string<D>( &self, text: &str, position: Point, baseline: Baseline, target: &mut D, ) -> Result<Point, D::Error>
where D: DrawTarget<Color = Self::Color>,

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.

source

fn draw_whitespace<D>( &self, width: u32, position: Point, baseline: Baseline, target: &mut D, ) -> Result<Point, D::Error>
where D: DrawTarget<Color = Self::Color>,

Draws whitespace of the given width.

The method returns the start position of the next character to allow chaining of multiple draw calls.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementors§