Struct embedded_graphics::style::TextStyleBuilder
source · [−]pub struct TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone, { /* private fields */ }
Expand description
Text style builder.
Use this builder to create TextStyle
s for Text
.
The text_style!
macro can also be used to create TextStyle
s, but with a shorter syntax.
See the text_style!
documentation for examples.
Examples
Render yellow text on a blue background
This uses the Font6x8
font, but other fonts can also be used.
use embedded_graphics::{
fonts::{Font6x8, Text},
pixelcolor::Rgb565,
prelude::*,
style::{TextStyle, TextStyleBuilder},
};
let style: TextStyle<Rgb565, Font6x8> = TextStyleBuilder::new(Font6x8)
.text_color(Rgb565::YELLOW)
.background_color(Rgb565::BLUE)
.build();
let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);
Render black text on white background using macros
This uses the Font8x16
font with the egtext!
and text_style!
macros for shorter
code.
use embedded_graphics::{
egtext,
fonts::{Font8x16, Text},
pixelcolor::Rgb565,
prelude::*,
style::TextStyle,
text_style,
};
let style = text_style!(
font = Font8x16,
text_color = Rgb565::WHITE,
background_color = Rgb565::BLACK
);
let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);
Transparent background
If a property is ommitted, it will remain at its default value in the resulting TextStyle
returned by .build()
. This example draws white text with no background at all.
use embedded_graphics::{
egtext,
fonts::{Font6x8, Text},
pixelcolor::Rgb565,
prelude::*,
style::{TextStyle, TextStyleBuilder},
text_style,
};
let style: TextStyle<Rgb565, Font6x8> = TextStyleBuilder::new(Font6x8)
.text_color(Rgb565::WHITE)
.build();
let text = Text::new("Hello Rust!", Point::new(0, 0)).into_styled(style);
Implementations
sourceimpl<C, F> TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C, F> TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
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.
Trait Implementations
sourceimpl<C: Clone, F: Clone> Clone for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Clone, F: Clone> Clone for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourcefn clone(&self) -> TextStyleBuilder<C, F>
fn clone(&self) -> TextStyleBuilder<C, F>
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<C: Debug, F: Debug> Debug for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Debug, F: Debug> Debug for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourceimpl<C: Default, F: Default> Default for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Default, F: Default> Default for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourcefn default() -> TextStyleBuilder<C, F>
fn default() -> TextStyleBuilder<C, F>
Returns the “default value” for a type. Read more
sourceimpl<C: Hash, F: Hash> Hash for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Hash, F: Hash> Hash for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourceimpl<C: Ord, F: Ord> Ord for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Ord, F: Ord> Ord for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourceimpl<C: PartialEq, F: PartialEq> PartialEq<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: PartialEq, F: PartialEq> PartialEq<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourcefn eq(&self, other: &TextStyleBuilder<C, F>) -> bool
fn eq(&self, other: &TextStyleBuilder<C, F>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TextStyleBuilder<C, F>) -> bool
fn ne(&self, other: &TextStyleBuilder<C, F>) -> bool
This method tests for !=
.
sourceimpl<C: PartialOrd, F: PartialOrd> PartialOrd<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: PartialOrd, F: PartialOrd> PartialOrd<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
sourcefn partial_cmp(&self, other: &TextStyleBuilder<C, F>) -> Option<Ordering>
fn partial_cmp(&self, other: &TextStyleBuilder<C, F>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<C: Copy, F: Copy> Copy for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C: Eq, F: Eq> Eq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C, F> StructuralEq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
impl<C, F> StructuralPartialEq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
Auto Trait Implementations
impl<C, F> RefUnwindSafe for TextStyleBuilder<C, F> where
C: RefUnwindSafe,
F: RefUnwindSafe,
impl<C, F> Send for TextStyleBuilder<C, F> where
C: Send,
F: Send,
impl<C, F> Sync for TextStyleBuilder<C, F> where
C: Sync,
F: Sync,
impl<C, F> Unpin for TextStyleBuilder<C, F> where
C: Unpin,
F: Unpin,
impl<C, F> UnwindSafe for TextStyleBuilder<C, F> where
C: UnwindSafe,
F: UnwindSafe,
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