plotters_backend

Trait BackendTextStyle

Source
pub trait BackendTextStyle {
    type FontError: Error + Sync + Send + 'static;

    // Required methods
    fn family(&self) -> FontFamily<'_>;
    fn layout_box(
        &self,
        text: &str,
    ) -> Result<((i32, i32), (i32, i32)), Self::FontError>;
    fn draw<E, DrawFunc: FnMut(i32, i32, BackendColor) -> Result<(), E>>(
        &self,
        text: &str,
        pos: BackendCoord,
        draw: DrawFunc,
    ) -> Result<Result<(), E>, Self::FontError>;

    // Provided methods
    fn color(&self) -> BackendColor { ... }
    fn size(&self) -> f64 { ... }
    fn transform(&self) -> FontTransform { ... }
    fn style(&self) -> FontStyle { ... }
    fn anchor(&self) -> Pos { ... }
}
Expand description

The trait that abstracts a style of a text.

This is used because the the backend crate have no knowledge about how the text handling is implemented in plotters.

But the backend still wants to know some information about the font, for the backend doesn’t handles text drawing, may want to call the draw method which is implemented by the plotters main crate. While for the backend that handles the text drawing, those font information provides instructions about how the text should be rendered: color, size, slant, anchor, font, etc.

This trait decouples the detailed implementation about the font and the backend code which wants to perform some operation on the font.

Required Associated Types§

Source

type FontError: Error + Sync + Send + 'static

The error type of this text style implementation

Required Methods§

Source

fn family(&self) -> FontFamily<'_>

Source

fn layout_box( &self, text: &str, ) -> Result<((i32, i32), (i32, i32)), Self::FontError>

Source

fn draw<E, DrawFunc: FnMut(i32, i32, BackendColor) -> Result<(), E>>( &self, text: &str, pos: BackendCoord, draw: DrawFunc, ) -> Result<Result<(), E>, Self::FontError>

Provided Methods§

Source

fn color(&self) -> BackendColor

Source

fn size(&self) -> f64

Source

fn transform(&self) -> FontTransform

Source

fn style(&self) -> FontStyle

Source

fn anchor(&self) -> Pos

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§