Struct TextStyle

pub struct TextStyle<'a> {
    pub font: FontDesc<'a>,
    pub color: BackendColor,
    pub pos: Pos,
}
Expand description

Style of a text

Fields§

§font: FontDesc<'a>

The font description

§color: BackendColor

The text color

§pos: Pos

The anchor point position

Implementations§

§

impl<'a> TextStyle<'a>

pub fn color<C>(&self, color: &'a C) -> TextStyle<'a>
where C: Color,

Sets the color of the style.

  • color: The required color
  • returns The up-to-dated text style
use plotters::prelude::*;

let style = TextStyle::from(("sans-serif", 20).into_font()).color(&RED);

pub fn transform(&self, trans: FontTransform) -> TextStyle<'a>

Sets the font transformation of the style.

  • trans: The required transformation
  • returns The up-to-dated text style
use plotters::prelude::*;

let style = TextStyle::from(("sans-serif", 20).into_font()).transform(FontTransform::Rotate90);

pub fn pos(&self, pos: Pos) -> TextStyle<'a>

Sets the anchor position.

  • pos: The required anchor position
  • returns The up-to-dated text style
use plotters::prelude::*;
use plotters::style::text_anchor::{Pos, HPos, VPos};

let pos = Pos::new(HPos::Left, VPos::Top);
let style = TextStyle::from(("sans-serif", 20).into_font()).pos(pos);
§See also

IntoTextStyle::with_anchor()

Trait Implementations§

§

impl<'a> BackendTextStyle for TextStyle<'a>

§

type FontError = <FontDataInternal as FontData>::ErrorType

The error type of this text style implementation
§

fn color(&self) -> BackendColor

§

fn size(&self) -> f64

§

fn transform(&self) -> FontTransform

§

fn style(&self) -> FontStyle

§

fn layout_box( &self, text: &str, ) -> Result<((i32, i32), (i32, i32)), <TextStyle<'a> as BackendTextStyle>::FontError>

§

fn anchor(&self) -> Pos

§

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

§

fn draw<E, DrawFunc>( &self, text: &str, pos: (i32, i32), draw: DrawFunc, ) -> Result<Result<(), E>, <TextStyle<'a> as BackendTextStyle>::FontError>
where DrawFunc: FnMut(i32, i32, BackendColor) -> Result<(), E>,

§

impl<'a> Clone for TextStyle<'a>

§

fn clone(&self) -> TextStyle<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a, 'b> From<&'b TextStyle<'a>> for TextStyle<'a>
where 'b: 'a,

Make sure that we are able to automatically copy the TextStyle

§

fn from(this: &'b TextStyle<'a>) -> TextStyle<'a>

Converts to this type from the input type.
§

impl<'a, T> From<T> for TextStyle<'a>
where T: Into<FontDesc<'a>>,

§

fn from(font: T) -> TextStyle<'a>

Converts to this type from the input type.
§

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

§

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

Converts the value into a TextStyle value. Read more
§

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

Specifies the color of the text element Read more
§

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 Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TextStyle<'a>

§

impl<'a> RefUnwindSafe for TextStyle<'a>

§

impl<'a> Send for TextStyle<'a>

§

impl<'a> Sync for TextStyle<'a>

§

impl<'a> Unpin for TextStyle<'a>

§

impl<'a> UnwindSafe for TextStyle<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromQuery for T
where T: for<'a> From<&'a str>,

Source§

fn from_query(query: &str) -> T

Create an instance of Self from a query string.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more