[−][src]Struct embedded_graphics::style::TextStyleBuilder
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);
Methods
impl<C, F> TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
pub fn new(font: F) -> Self
[src]
Creates a new text style builder with a given font.
pub fn text_color(&mut self, text_color: C) -> &mut Self
[src]
Sets the text color.
pub fn background_color(&mut self, background_color: C) -> &mut Self
[src]
Sets the background color.
pub fn build(&self) -> TextStyle<C, F>
[src]
Builds the text style.
Trait Implementations
impl<C: Debug, F: Debug> Debug for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
impl<C: Eq, F: Eq> Eq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
impl<C: PartialEq, F: PartialEq> PartialEq<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
fn eq(&self, other: &TextStyleBuilder<C, F>) -> bool
[src]
fn ne(&self, other: &TextStyleBuilder<C, F>) -> bool
[src]
impl<C, F> StructuralEq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
impl<C, F> StructuralPartialEq for TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone,
[src]
C: PixelColor,
F: Font + Clone,
Auto Trait Implementations
impl<C, F> Send for TextStyleBuilder<C, F> where
C: Send,
F: Send,
C: Send,
F: Send,
impl<C, F> Sync for TextStyleBuilder<C, F> where
C: Sync,
F: Sync,
C: Sync,
F: Sync,
impl<C, F> Unpin for TextStyleBuilder<C, F> where
C: Unpin,
F: Unpin,
C: Unpin,
F: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,