[−][src]Struct embedded_text::prelude::TextStyleBuilder
Text style builder.
Use this builder to create TextStyles for Text.
The text_style! macro can also be used to create TextStyles, 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
impl<C, F> TextStyleBuilder<C, F> where
C: PixelColor,
F: Font + Clone, [src]
C: PixelColor,
F: Font + Clone,
pub fn new(font: F) -> TextStyleBuilder<C, F>[src]
Creates a new text style builder with a given font.
pub fn text_color(self, text_color: C) -> TextStyleBuilder<C, F>[src]
Sets the text color.
pub fn background_color(self, background_color: C) -> TextStyleBuilder<C, F>[src]
Sets the background color.
pub fn build(self) -> TextStyle<C, F>[src]
Builds the text style.
Trait Implementations
impl<C, F> Clone for TextStyleBuilder<C, F> where
C: Clone + PixelColor,
F: Clone + Font, [src]
C: Clone + PixelColor,
F: Clone + Font,
fn clone(&self) -> TextStyleBuilder<C, F>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<C, F> Copy for TextStyleBuilder<C, F> where
C: Copy + PixelColor,
F: Copy + Font + Clone, [src]
C: Copy + PixelColor,
F: Copy + Font + Clone,
impl<C, F> Debug for TextStyleBuilder<C, F> where
C: Debug + PixelColor,
F: Debug + Font + Clone, [src]
C: Debug + PixelColor,
F: Debug + Font + Clone,
impl<C, F> Default for TextStyleBuilder<C, F> where
C: Default + PixelColor,
F: Default + Font + Clone, [src]
C: Default + PixelColor,
F: Default + Font + Clone,
fn default() -> TextStyleBuilder<C, F>[src]
impl<C, F> Eq for TextStyleBuilder<C, F> where
C: Eq + PixelColor,
F: Eq + Font + Clone, [src]
C: Eq + PixelColor,
F: Eq + Font + Clone,
impl<C, F> Hash for TextStyleBuilder<C, F> where
C: Hash + PixelColor,
F: Hash + Font + Clone, [src]
C: Hash + PixelColor,
F: Hash + Font + Clone,
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher, [src]
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<C, F> Ord for TextStyleBuilder<C, F> where
C: Ord + PixelColor,
F: Ord + Font + Clone, [src]
C: Ord + PixelColor,
F: Ord + Font + Clone,
fn cmp(&self, other: &TextStyleBuilder<C, F>) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl<C, F> PartialEq<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PartialEq<C> + PixelColor,
F: PartialEq<F> + Font + Clone, [src]
C: PartialEq<C> + PixelColor,
F: PartialEq<F> + Font + Clone,
fn eq(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
fn ne(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
impl<C, F> PartialOrd<TextStyleBuilder<C, F>> for TextStyleBuilder<C, F> where
C: PartialOrd<C> + PixelColor,
F: PartialOrd<F> + Font + Clone, [src]
C: PartialOrd<C> + PixelColor,
F: PartialOrd<F> + Font + Clone,
fn partial_cmp(&self, other: &TextStyleBuilder<C, F>) -> Option<Ordering>[src]
fn lt(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
fn le(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
fn gt(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
fn ge(&self, other: &TextStyleBuilder<C, F>) -> bool[src]
Auto Trait Implementations
impl<C, F> RefUnwindSafe for TextStyleBuilder<C, F> where
C: RefUnwindSafe,
F: RefUnwindSafe,
C: RefUnwindSafe,
F: RefUnwindSafe,
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,
impl<C, F> UnwindSafe for TextStyleBuilder<C, F> where
C: UnwindSafe,
F: UnwindSafe,
C: UnwindSafe,
F: UnwindSafe,
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> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
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>,