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§

source§

impl<'a, C> MonoTextStyleBuilder<'a, C>where C: PixelColor,

source

pub const fn new() -> Self

Creates a new text style builder.

source

pub const fn font<'b>( self, font: &'b MonoFont<'b> ) -> MonoTextStyleBuilder<'b, C>

Sets the font.

source

pub const fn underline(self) -> Self

Enables underline using the text color.

source

pub const fn strikethrough(self) -> Self

Enables strikethrough using the text color.

source

pub const fn reset_text_color(self) -> Self

Resets the text color to transparent.

source

pub const fn reset_background_color(self) -> Self

Resets the background color to transparent.

source

pub const fn reset_underline(self) -> Self

Removes the underline decoration.

source

pub const fn reset_strikethrough(self) -> Self

Removes the strikethrough decoration.

source

pub const fn text_color(self, text_color: C) -> Self

Sets the text color.

source

pub const fn background_color(self, background_color: C) -> Self

Sets the background color.

source

pub const fn underline_with_color(self, underline_color: C) -> Self

Enables underline with a custom color.

source

pub const fn strikethrough_with_color(self, strikethrough_color: C) -> Self

Enables strikethrough with a custom color.

source

pub const fn build(self) -> MonoTextStyle<'a, C>

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§

source§

impl<'a, C: Clone> Clone for MonoTextStyleBuilder<'a, C>

source§

fn clone(&self) -> MonoTextStyleBuilder<'a, C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, C> Format for MonoTextStyleBuilder<'a, C>where C: Format,

source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
source§

impl<'a, C> From<&MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>where C: PixelColor,

source§

fn from(style: &MonoTextStyle<'a, C>) -> Self

Converts to this type from the input type.
source§

impl<'a, C: Copy> Copy for MonoTextStyleBuilder<'a, C>

Auto Trait Implementations§

§

impl<'a, C> !RefUnwindSafe for MonoTextStyleBuilder<'a, C>

§

impl<'a, C> Send for MonoTextStyleBuilder<'a, C>where C: Send,

§

impl<'a, C> Sync for MonoTextStyleBuilder<'a, C>where C: Sync,

§

impl<'a, C> Unpin for MonoTextStyleBuilder<'a, C>where C: Unpin,

§

impl<'a, C> !UnwindSafe for MonoTextStyleBuilder<'a, C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

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

§

fn to_subset(&self) -> Option<SS>

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.