[][src]Struct embedded_text::prelude::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);

Implementations

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

pub fn new(font: F) -> TextStyleBuilder<C, F>[src]

Creates a new text style builder with a given font.

pub fn text_color(self, text_color: C) -> TextStyleBuilder<C, F>[src]

Sets the text color.

pub fn background_color(self, background_color: C) -> TextStyleBuilder<C, F>[src]

Sets the background color.

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

Builds the text style.

Trait Implementations

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

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

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

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

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

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

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

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

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

Auto Trait Implementations

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

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

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

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.