plotters::style

Trait IntoTextStyle

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

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

Trait for values that can be converted into TextStyle values

Required Methods§

Source

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

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: Color>(self, color: C) -> TextStyleBuilder<'a, Self>
where 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: Color>(self, pos: Pos) -> TextStyleBuilder<'a, Self>
where 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()

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.

Implementations on Foreign Types§

Source§

impl IntoTextStyle<'static> for f64

Source§

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

Source§

impl IntoTextStyle<'static> for u32

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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>