Struct embedded_graphics::mono_font::MonoTextStyleBuilder
source · [−]pub struct MonoTextStyleBuilder<'a, C> { /* private fields */ }
Expand description
Text style builder for monospaced fonts.
Use this builder to create MonoTextStyle
s 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
sourceimpl<C> MonoTextStyleBuilder<'_, C>
impl<C> MonoTextStyleBuilder<'_, C>
sourceimpl<'a, C> MonoTextStyleBuilder<'a, C>
impl<'a, C> MonoTextStyleBuilder<'a, C>
sourcepub fn font<'b>(self, font: &'b MonoFont<'b>) -> MonoTextStyleBuilder<'b, C>
pub fn font<'b>(self, font: &'b MonoFont<'b>) -> MonoTextStyleBuilder<'b, C>
Sets the font.
sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Enables strikethrough using the text color.
sourcepub fn reset_text_color(self) -> Self
pub fn reset_text_color(self) -> Self
Resets the text color to transparent.
sourcepub fn reset_background_color(self) -> Self
pub fn reset_background_color(self) -> Self
Resets the background color to transparent.
sourcepub fn reset_underline(self) -> Self
pub fn reset_underline(self) -> Self
Removes the underline decoration.
sourcepub fn reset_strikethrough(self) -> Self
pub fn reset_strikethrough(self) -> Self
Removes the strikethrough decoration.
sourceimpl<C: PixelColor> MonoTextStyleBuilder<'_, C>
impl<C: PixelColor> MonoTextStyleBuilder<'_, C>
sourcepub fn text_color(self, text_color: C) -> Self
pub fn text_color(self, text_color: C) -> Self
Sets the text color.
sourcepub fn background_color(self, background_color: C) -> Self
pub fn background_color(self, background_color: C) -> Self
Sets the background color.
sourcepub fn underline_with_color(self, underline_color: C) -> Self
pub fn underline_with_color(self, underline_color: C) -> Self
Enables underline with a custom color.
sourcepub fn strikethrough_with_color(self, strikethrough_color: C) -> Self
pub fn strikethrough_with_color(self, strikethrough_color: C) -> Self
Enables strikethrough with a custom color.
sourceimpl<'a, C: PixelColor> MonoTextStyleBuilder<'a, C>
impl<'a, C: PixelColor> MonoTextStyleBuilder<'a, C>
sourcepub fn build(self) -> MonoTextStyle<'a, C>
pub 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
sourceimpl<'a, C: Clone> Clone for MonoTextStyleBuilder<'a, C>
impl<'a, C: Clone> Clone for MonoTextStyleBuilder<'a, C>
sourcefn clone(&self) -> MonoTextStyleBuilder<'a, C>
fn clone(&self) -> MonoTextStyleBuilder<'a, C>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>
impl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>
sourceimpl<'a, C: PixelColor> From<&'_ MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>
impl<'a, C: PixelColor> From<&'_ MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>
sourcefn from(style: &MonoTextStyle<'a, C>) -> Self
fn from(style: &MonoTextStyle<'a, C>) -> Self
Performs the conversion.
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>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcepub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcepub fn checked_cast_from(src: Src) -> Option<Dst>
pub fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcepub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcepub fn overflowing_cast_from(src: Src) -> (Dst, bool)
pub fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcepub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcepub fn saturating_cast_from(src: Src) -> Dst
pub fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcepub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcepub fn unwrapped_cast_from(src: Src) -> Dst
pub fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcepub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcepub fn wrapping_cast_from(src: Src) -> Dst
pub fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.