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§
Sourcefn into_text_style<P: HasDimension>(self, parent: &P) -> TextStyle<'a>
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§
Sourcefn with_color<C: Color>(self, color: C) -> TextStyleBuilder<'a, Self>where
Self: Sized,
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
IntoTextStyle::into_text_style()
for a more succinct example
Sourcefn with_anchor<C: Color>(self, pos: Pos) -> TextStyleBuilder<'a, Self>where
Self: Sized,
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
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.