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

impl<C> MonoTextStyleBuilder<'_, C>[src]

pub fn new() -> Self[src]

Creates a new text style builder.

impl<'a, C> MonoTextStyleBuilder<'a, C>[src]

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

Sets the font.

pub fn underline(self) -> Self[src]

Enables underline using the text color.

pub fn strikethrough(self) -> Self[src]

Enables strikethrough using the text color.

pub fn reset_text_color(self) -> Self[src]

Resets the text color to transparent.

pub fn reset_background_color(self) -> Self[src]

Resets the background color to transparent.

pub fn reset_underline(self) -> Self[src]

Removes the underline decoration.

pub fn reset_strikethrough(self) -> Self[src]

Removes the strikethrough decoration.

impl<C: PixelColor> MonoTextStyleBuilder<'_, C>[src]

pub fn text_color(self, text_color: C) -> Self[src]

Sets the text color.

pub fn background_color(self, background_color: C) -> Self[src]

Sets the background color.

pub fn underline_with_color(self, underline_color: C) -> Self[src]

Enables underline with a custom color.

pub fn strikethrough_with_color(self, strikethrough_color: C) -> Self[src]

Enables strikethrough with a custom color.

impl<'a, C: PixelColor> MonoTextStyleBuilder<'a, C>[src]

pub fn build(self) -> MonoTextStyle<'a, C>[src]

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

impl<'a, C: Clone> Clone for MonoTextStyleBuilder<'a, C>[src]

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

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>[src]

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

Formats the value using the given formatter. Read more

impl<'a, C: PixelColor> From<&'_ MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>[src]

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

Performs the conversion.

impl<'a, C: Copy> Copy for MonoTextStyleBuilder<'a, C>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

pub fn lossless_try_into(self) -> Option<Dst>[src]

Performs the conversion.

impl<Src, Dst> LossyInto<Dst> for Src where
    Dst: LossyFrom<Src>, 
[src]

pub fn lossy_into(self) -> Dst[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

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

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

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

pub fn is_in_subset(&self) -> bool

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

pub fn to_subset_unchecked(&self) -> SS

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

pub fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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.

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

Performs the conversion.

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.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V