pub trait IntoTextStyle<'a> {
    fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
   where
        P: HasDimension
; fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>
   where
        C: Color
, { ... } fn with_anchor<C>(self, pos: Pos) -> TextStyleBuilder<'a, Self>
   where
        C: Color
, { ... } }
Expand description

Trait for values that can be converted into TextStyle values

Required Methods

Converts the value into a TextStyle value.

parent is used in some cases to convert a font size from points to pixels.

Example
use plotters::prelude::*;
let drawing_area = SVGBackend::new("into_text_style.svg", (200, 100)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
let text_style = ("sans-serif", 20, &RED).into_text_style(&drawing_area);
drawing_area.draw_text("This is a big red label", &text_style, (10, 50)).unwrap();

The result is a text label styled accordingly:

Provided Methods

Specifies the color of the text element

Example
use plotters::prelude::*;
let drawing_area = SVGBackend::new("with_color.svg", (200, 100)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
let text_style = ("sans-serif", 20).with_color(RED).into_text_style(&drawing_area);
drawing_area.draw_text("This is a big red label", &text_style, (10, 50)).unwrap();

The result is a text label styled accordingly:

See also

FontDesc::color()

IntoTextStyle::into_text_style() for a more succinct example

Specifies the position of the text anchor relative to the text element

Example
use plotters::{prelude::*,style::text_anchor::{HPos, Pos, VPos}};
let anchor_position = (200,100);
let anchor_left_bottom = Pos::new(HPos::Left, VPos::Bottom);
let anchor_right_top = Pos::new(HPos::Right, VPos::Top);
let drawing_area = SVGBackend::new("with_anchor.svg", (400, 200)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
drawing_area.draw(&Circle::new(anchor_position, 5, RED.filled()));
let text_style_right_top = BLACK.with_anchor::<RGBColor>(anchor_right_top).into_text_style(&drawing_area);
drawing_area.draw_text("The anchor sits at the right top of this label", &text_style_right_top, anchor_position);
let text_style_left_bottom = BLACK.with_anchor::<RGBColor>(anchor_left_bottom).into_text_style(&drawing_area);
drawing_area.draw_text("The anchor sits at the left bottom of this label", &text_style_left_bottom, anchor_position);

The result has a red pixel at the center and two text labels positioned accordingly:

See also

TextStyle::pos()

Implementations on Foreign Types

Implementors