pub trait IntoTextStyle<'a> {
    // Required method
    fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
       where P: HasDimension;

    // Provided methods
    fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>
       where C: Color,
             Self: Sized { ... }
    fn with_anchor<C>(self, pos: Pos) -> TextStyleBuilder<'a, Self>
       where C: Color,
             Self: Sized { ... }
}
Expand description

Trait for values that can be converted into TextStyle values

Required Methods§

source

fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
where P: HasDimension,

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§

source

fn with_color<C>(self, color: C) -> TextStyleBuilder<'a, Self>
where C: Color, Self: Sized,

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

source

fn with_anchor<C>(self, pos: Pos) -> TextStyleBuilder<'a, Self>
where C: Color, Self: Sized,

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()

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl IntoTextStyle<'static> for f64

source§

fn into_text_style<P>(self, _: &P) -> TextStyle<'static>
where P: HasDimension,

source§

impl IntoTextStyle<'static> for u32

source§

fn into_text_style<P>(self, _: &P) -> TextStyle<'static>
where P: HasDimension,

source§

impl<'a> IntoTextStyle<'a> for &'a str

source§

fn into_text_style<P>(self, _: &P) -> TextStyle<'a>
where P: HasDimension,

source§

impl<'a, F, T> IntoTextStyle<'a> for (F, T, FontStyle)
where F: Into<FontFamily<'a>>, T: SizeDesc,

source§

fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
where P: HasDimension,

source§

impl<'a, F, T> IntoTextStyle<'a> for (F, T)
where F: Into<FontFamily<'a>>, T: SizeDesc,

source§

fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
where P: HasDimension,

source§

impl<'a, F, T, C> IntoTextStyle<'a> for (F, T, FontStyle, &'a C)
where F: Into<FontFamily<'a>>, T: SizeDesc, C: Color,

source§

fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
where P: HasDimension,

source§

impl<'a, F, T, C> IntoTextStyle<'a> for (F, T, &'a C)
where F: Into<FontFamily<'a>>, T: SizeDesc, C: Color,

source§

fn into_text_style<P>(self, parent: &P) -> TextStyle<'a>
where P: HasDimension,

source§

impl<'a, T> IntoTextStyle<'a> for &'a T
where T: Color,

source§

fn into_text_style<P>(self, _: &P) -> TextStyle<'a>
where P: HasDimension,

Implementors§

source§

impl<'a> IntoTextStyle<'a> for FontFamily<'a>

source§

impl<'a> IntoTextStyle<'a> for FontDesc<'a>

source§

impl<'a> IntoTextStyle<'a> for TextStyle<'a>