Struct embedded_graphics::mono_font::MonoTextStyleBuilder[][src]

pub struct MonoTextStyleBuilder<'a, C> { /* fields omitted */ }
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.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Casts the value.

Should always be Self

Casts the value.

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

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.

Casts the value.