logo
pub struct MonoTextStyleBuilder<'a, C> { /* private fields */ }
Expand description

Text style builder for monospaced fonts.

Use this builder to create MonoTextStyles for Text.

Examples

Render yellow text on a blue background

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

use embedded_graphics::{
    mono_font::{ascii::FONT_6X9, MonoTextStyle, MonoTextStyleBuilder},
    pixelcolor::Rgb565,
    prelude::*,
    text::Text,
};

let style = MonoTextStyleBuilder::new()
    .font(&FONT_6X9)
    .text_color(Rgb565::YELLOW)
    .background_color(Rgb565::BLUE)
    .build();

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

Transparent background

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

use embedded_graphics::{
    mono_font::{ascii::FONT_6X9, MonoTextStyle, MonoTextStyleBuilder},
    pixelcolor::Rgb565,
    prelude::*,
    text::Text,
};

let style = MonoTextStyleBuilder::new()
    .font(&FONT_6X9)
    .text_color(Rgb565::WHITE)
    .build();

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

Modifying an existing style

The builder can also be used to modify an existing style.

use embedded_graphics::{
    mono_font::{ascii::{FONT_6X9, FONT_10X20}, MonoTextStyle, MonoTextStyleBuilder},
    pixelcolor::Rgb565,
    prelude::*,
    text::Text,
};

let style = MonoTextStyle::new(&FONT_6X9, Rgb565::YELLOW);

let style_larger = MonoTextStyleBuilder::from(&style)
    .font(&FONT_10X20)
    .build();

Implementations

Creates a new text style builder.

Sets the font.

Enables underline using the text color.

Enables strikethrough using the text color.

Resets the text color to transparent.

Resets the background color to transparent.

Removes the underline decoration.

Removes the strikethrough decoration.

Sets the text color.

Sets the background color.

Enables underline with a custom color.

Enables strikethrough with a custom color.

Builds the text style.

This method can only be called after a font was set by using the font method. All other settings are optional and they will be set to their default value if they are missing.

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

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Returns the argument unchanged.

Calls U::from(self).

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

Casts the value.

OverflowingCasts the value.

Casts the value.

Casts the value.

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.

Casts the value.

UnwrappedCasts the value.

Casts the value.

WrappingCasts the value.