Skip to main content

TextBoxStyle

Struct TextBoxStyle 

Source
#[non_exhaustive]
pub struct TextBoxStyle { pub alignment: HorizontalAlignment, pub vertical_alignment: VerticalAlignment, pub height_mode: HeightMode, pub line_height: LineHeight, pub paragraph_spacing: u32, pub tab_size: TabSize, pub leading_spaces: bool, pub trailing_spaces: bool, }
Expand description

Styling options of a TextBox.

TextBoxStyle contains the font, foreground and background PixelColor, line spacing, HeightMode, HorizontalAlignment and VerticalAlignment information necessary to draw a TextBox.

To construct a new TextBoxStyle object, use the TextBoxStyle::default method or the TextBoxStyleBuilder object.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§alignment: HorizontalAlignment

Horizontal text alignment.

§vertical_alignment: VerticalAlignment

Vertical text alignment.

§height_mode: HeightMode

The height behaviour.

§line_height: LineHeight

Line height.

§paragraph_spacing: u32

Paragraph spacing.

§tab_size: TabSize

Desired column width for tabs

§leading_spaces: bool

True to render leading spaces

§trailing_spaces: bool

True to render trailing spaces

Implementations§

Source§

impl TextBoxStyle

Source

pub const fn default() -> Self

Creates a new text box style object with default settings.

Source

pub const fn with_alignment(alignment: HorizontalAlignment) -> TextBoxStyle

Creates a new text box style with the given alignment.

Source

pub const fn with_vertical_alignment( alignment: VerticalAlignment, ) -> TextBoxStyle

Creates a new text box style with the given vertical alignment.

Source

pub const fn with_height_mode(mode: HeightMode) -> TextBoxStyle

Creates a new text box style with the given height mode.

Source

pub const fn with_line_height(line_height: LineHeight) -> TextBoxStyle

Creates a new text box style with the given line height.

Source

pub const fn with_paragraph_spacing(spacing: u32) -> TextBoxStyle

Creates a new text box style with the given paragraph spacing.

Source

pub const fn with_tab_size(tab_size: TabSize) -> TextBoxStyle

Creates a new text box style with the given tab size.

Source§

impl TextBoxStyle

Source

pub fn measure_text_height<S>( &self, character_style: &S, text: &str, max_width: u32, ) -> u32
where S: TextRenderer,

Measures text height when rendered using a given width.

§Example: measure height of text when rendered using a 6x9 MonoFont and 72px width.
let character_style = MonoTextStyleBuilder::new()
    .font(&FONT_6X9)
    .text_color(BinaryColor::On)
    .build();
let style = TextBoxStyleBuilder::new().build();

let height = style.measure_text_height(
    &character_style,
    "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    72,
);

// Expect 7 lines of text, wrapped in something like the following:

// |Lorem Ipsum |
// |is simply   |
// |dummy text  |
// |of the      |
// |printing and|
// |typesetting |
// |industry.   |

assert_eq!(7 * 9, height);

Trait Implementations§

Source§

impl Clone for TextBoxStyle

Source§

fn clone(&self) -> TextBoxStyle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TextBoxStyle

Source§

impl Debug for TextBoxStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TextBoxStyle

Source§

impl From<&TextBoxStyle> for TextBoxStyleBuilder

Source§

fn from(style: &TextBoxStyle) -> Self

Converts to this type from the input type.
Source§

impl Hash for TextBoxStyle

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TextBoxStyle

Source§

fn eq(&self, other: &TextBoxStyle) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextBoxStyle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.