[][src]Struct embedded_graphics::style::TextStyleBuilder

pub struct TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
{ /* fields omitted */ }

Text style builder.

Use this builder to create TextStyles for Text.

The text_style! macro can also be used to create TextStyles, but with a shorter syntax. See the text_style! documentation for examples.

Examples

Render yellow text on a blue background

This uses the Font6x8 font, but other fonts can also be used.

use embedded_graphics::{
    fonts::{Font6x8, Text},
    pixelcolor::Rgb565,
    prelude::*,
    style::{TextStyle, TextStyleBuilder},
};

let style: TextStyle<Rgb565, Font6x8> = TextStyleBuilder::new(Font6x8)
    .text_color(Rgb565::YELLOW)
    .background_color(Rgb565::BLUE)
    .build();

let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);

Render black text on white background using macros

This uses the Font8x16 font with the egtext! and text_style! macros for shorter code.

use embedded_graphics::{
    egtext,
    fonts::{Font8x16, Text},
    pixelcolor::Rgb565,
    prelude::*,
    style::TextStyle,
    text_style,
};

let style = text_style!(
    font = Font8x16,
    text_color = Rgb565::WHITE,
    background_color = Rgb565::BLACK
);

let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);

Transparent background

If a property is ommitted, it will remain at its default value in the resulting TextStyle returned by .build(). This example draws white text with no background at all.

use embedded_graphics::{
    egtext,
    fonts::{Font6x8, Text},
    pixelcolor::Rgb565,
    prelude::*,
    style::{TextStyle, TextStyleBuilder},
    text_style,
};

let style: TextStyle<Rgb565, Font6x8> = TextStyleBuilder::new(Font6x8)
    .text_color(Rgb565::WHITE)
    .build();

let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);

Methods

impl<C, F> TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

pub fn new(font: F) -> Self[src]

Creates a new text style builder with a given font.

pub fn text_color(&mut self, text_color: C) -> &mut Self[src]

Sets the text color.

pub fn background_color(&mut self, background_color: C) -> &mut Self[src]

Sets the background color.

pub fn build(&self) -> TextStyle<C, F>[src]

Builds the text style.

Trait Implementations

impl<C: Debug, F: Debug> Debug for TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

impl<C: Eq, F: Eq> Eq for TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

impl<C: PartialEq, F: PartialEq> PartialEq<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

impl<C, F> StructuralEq for TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

impl<C, F> StructuralPartialEq for TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
[src]

Auto Trait Implementations

impl<C, F> Send for TextStyleBuilder<C, F> where
    C: Send,
    F: Send

impl<C, F> Sync for TextStyleBuilder<C, F> where
    C: Sync,
    F: Sync

impl<C, F> Unpin for TextStyleBuilder<C, F> where
    C: Unpin,
    F: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,