pub struct TextStyleBuilder<C, F>{ /* 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§
Source§impl<C, F> TextStyleBuilder<C, F>
impl<C, F> TextStyleBuilder<C, F>
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§
Source§impl<C, F> Clone for TextStyleBuilder<C, F>
impl<C, F> Clone for TextStyleBuilder<C, F>
Source§fn clone(&self) -> TextStyleBuilder<C, F>
fn clone(&self) -> TextStyleBuilder<C, F>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<C, F> Debug for TextStyleBuilder<C, F>
impl<C, F> Debug for TextStyleBuilder<C, F>
Source§impl<C, F> Default for TextStyleBuilder<C, F>
impl<C, F> Default for TextStyleBuilder<C, F>
Source§fn default() -> TextStyleBuilder<C, F>
fn default() -> TextStyleBuilder<C, F>
Returns the “default value” for a type. Read more
Source§impl<C, F> Hash for TextStyleBuilder<C, F>
impl<C, F> Hash for TextStyleBuilder<C, F>
Source§impl<C, F> Ord for TextStyleBuilder<C, F>
impl<C, F> Ord for TextStyleBuilder<C, F>
Source§fn cmp(&self, other: &TextStyleBuilder<C, F>) -> Ordering
fn cmp(&self, other: &TextStyleBuilder<C, F>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<C, F> PartialEq for TextStyleBuilder<C, F>
impl<C, F> PartialEq for TextStyleBuilder<C, F>
Source§impl<C, F> PartialOrd for TextStyleBuilder<C, F>
impl<C, F> PartialOrd for TextStyleBuilder<C, F>
impl<C, F> Copy for TextStyleBuilder<C, F>
impl<C, F> Eq for TextStyleBuilder<C, F>
impl<C, F> StructuralPartialEq for TextStyleBuilder<C, F>
Auto Trait Implementations§
impl<C, F> Freeze for TextStyleBuilder<C, F>
impl<C, F> RefUnwindSafe for TextStyleBuilder<C, F>where
F: RefUnwindSafe,
C: RefUnwindSafe,
impl<C, F> Send for TextStyleBuilder<C, F>
impl<C, F> Sync for TextStyleBuilder<C, F>
impl<C, F> Unpin for TextStyleBuilder<C, F>
impl<C, F> UnwindSafe for TextStyleBuilder<C, F>where
F: UnwindSafe,
C: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.