logo
pub struct TextStyleBuilder<C, F> where
    C: PixelColor,
    F: Font + Clone
{ /* private fields */ }
Expand description

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

Creates a new text style builder with a given font.

Sets the text color.

Sets the background color.

Builds the text style.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.