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§
Source§impl<'a, C> MonoTextStyleBuilder<'a, C>where
C: PixelColor,
impl<'a, C> MonoTextStyleBuilder<'a, C>where
C: PixelColor,
Sourcepub const fn font<'b>(
self,
font: &'b MonoFont<'b>,
) -> MonoTextStyleBuilder<'b, C>
pub const fn font<'b>( self, font: &'b MonoFont<'b>, ) -> MonoTextStyleBuilder<'b, C>
Sets the font.
Sourcepub const fn strikethrough(self) -> Self
pub const fn strikethrough(self) -> Self
Enables strikethrough using the text color.
Sourcepub const fn reset_text_color(self) -> Self
pub const fn reset_text_color(self) -> Self
Resets the text color to transparent.
Sourcepub const fn reset_background_color(self) -> Self
pub const fn reset_background_color(self) -> Self
Resets the background color to transparent.
Sourcepub const fn reset_underline(self) -> Self
pub const fn reset_underline(self) -> Self
Removes the underline decoration.
Sourcepub const fn reset_strikethrough(self) -> Self
pub const fn reset_strikethrough(self) -> Self
Removes the strikethrough decoration.
Sourcepub const fn text_color(self, text_color: C) -> Self
pub const fn text_color(self, text_color: C) -> Self
Sets the text color.
Sourcepub const fn background_color(self, background_color: C) -> Self
pub const fn background_color(self, background_color: C) -> Self
Sets the background color.
Sourcepub const fn underline_with_color(self, underline_color: C) -> Self
pub const fn underline_with_color(self, underline_color: C) -> Self
Enables underline with a custom color.
Sourcepub const fn strikethrough_with_color(self, strikethrough_color: C) -> Self
pub const fn strikethrough_with_color(self, strikethrough_color: C) -> Self
Enables strikethrough with a custom color.
Sourcepub const fn build(self) -> MonoTextStyle<'a, C>
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>
impl<'a, C: Clone> Clone for MonoTextStyleBuilder<'a, C>
Source§fn clone(&self) -> MonoTextStyleBuilder<'a, C>
fn clone(&self) -> MonoTextStyleBuilder<'a, C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>
impl<'a, C: Debug> Debug for MonoTextStyleBuilder<'a, C>
Source§impl<'a, C> Format for MonoTextStyleBuilder<'a, C>where
MonoTextStyle<'a, C>: Format,
impl<'a, C> Format for MonoTextStyleBuilder<'a, C>where
MonoTextStyle<'a, C>: Format,
Source§impl<'a, C> From<&MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>where
C: PixelColor,
impl<'a, C> From<&MonoTextStyle<'a, C>> for MonoTextStyleBuilder<'a, C>where
C: PixelColor,
Source§fn from(style: &MonoTextStyle<'a, C>) -> Self
fn from(style: &MonoTextStyle<'a, C>) -> Self
impl<'a, C: Copy> Copy for MonoTextStyleBuilder<'a, C>
Auto Trait Implementations§
impl<'a, C> Freeze for MonoTextStyleBuilder<'a, C>where
C: Freeze,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.