Skip to main content

TextStyle

Struct TextStyle 

Source
pub struct TextStyle {
Show 19 fields pub family: String, pub size: f64, pub weight: String, pub style: String, pub align: TextAlign, pub vertical_align: TextVerticalAlign, pub line_height: f64, pub wrap: bool, pub overflow: TextOverflow, pub color: Color, pub background: Option<Color>, pub padding: (f64, f64, f64, f64), pub border_width: f64, pub border_color: Option<Color>, pub border_radius: f64, pub rotate: f64, pub stroke_width: f64, pub stroke_color: Option<Color>, pub rich: Vec<(String, RichTextStyle)>,
}
Expand description

A text style, covering the font, the alignment, and the wrapping behaviour of a label.

Fields§

§family: String

The font family list, as a CSS font-family value.

§size: f64

The font size, in pixels.

§weight: String

The font weight, as a CSS font-weight value.

§style: String

The font style, as a CSS font-style value.

§align: TextAlign

The horizontal alignment of the text relative to its anchor point.

§vertical_align: TextVerticalAlign

The vertical alignment of the text relative to its anchor point.

§line_height: f64

The line height, as a multiple of the font size.

§wrap: bool

Whether the text wraps when it exceeds its box.

§overflow: TextOverflow

What happens to text that does not fit.

§color: Color

The colour of the text.

§background: Option<Color>

The colour painted behind the text, if any.

§padding: (f64, f64, f64, f64)

The padding between the text and its background, in pixels.

§border_width: f64

The border width drawn around the text, in pixels.

§border_color: Option<Color>

The colour of the border drawn around the text.

§border_radius: f64

The radius of the background’s rounded corners, in pixels.

§rotate: f64

The rotation of the text, in degrees, around its anchor point.

§stroke_width: f64

The stroke width of the text outline.

§stroke_color: Option<Color>

The colour of the text outline.

§rich: Vec<(String, RichTextStyle)>

The per-run style overrides, keyed by the name used in the text’s {name|…} markup.

Implementations§

Source§

impl TextStyle

Inherent implementation of TextStyle.

Source

pub fn new() -> Self

Returns the default text style.

Source

pub fn font(&self) -> String

Returns the CSS font shorthand for this style.

§Returns
  • String - A String value.
Source

pub fn line_height_px(&self) -> f64

Returns the line height in pixels.

§Returns
  • f64 - A 64-bit float.
Source

pub fn with_rich(self, name: &str, style: RichTextStyle) -> Self

Adds a rich-text run and returns the style.

§Arguments
  • &str - Shared reference to a str.
  • RichTextStyle - A RichTextStyle parameter.
Source§

impl TextStyle

Source

pub fn get_family(&self) -> &String

Source

pub fn get_mut_family(&mut self) -> &mut String

Source

pub fn set_family(&mut self, val: String) -> &mut Self

Source

pub fn get_size(&self) -> f64

Source

pub fn get_mut_size(&mut self) -> &mut f64

Source

pub fn set_size(&mut self, val: f64) -> &mut Self

Source

pub fn get_weight(&self) -> &String

Source

pub fn get_mut_weight(&mut self) -> &mut String

Source

pub fn set_weight(&mut self, val: String) -> &mut Self

Source

pub fn get_style(&self) -> &String

Source

pub fn get_mut_style(&mut self) -> &mut String

Source

pub fn set_style(&mut self, val: String) -> &mut Self

Source

pub fn get_align(&self) -> &TextAlign

Source

pub fn get_mut_align(&mut self) -> &mut TextAlign

Source

pub fn set_align(&mut self, val: TextAlign) -> &mut Self

Source

pub fn get_vertical_align(&self) -> &TextVerticalAlign

Source

pub fn get_mut_vertical_align(&mut self) -> &mut TextVerticalAlign

Source

pub fn set_vertical_align(&mut self, val: TextVerticalAlign) -> &mut Self

Source

pub fn get_line_height(&self) -> f64

Source

pub fn get_mut_line_height(&mut self) -> &mut f64

Source

pub fn set_line_height(&mut self, val: f64) -> &mut Self

Source

pub fn get_wrap(&self) -> bool

Source

pub fn get_mut_wrap(&mut self) -> &mut bool

Source

pub fn set_wrap(&mut self, val: bool) -> &mut Self

Source

pub fn get_overflow(&self) -> &TextOverflow

Source

pub fn get_mut_overflow(&mut self) -> &mut TextOverflow

Source

pub fn set_overflow(&mut self, val: TextOverflow) -> &mut Self

Source

pub fn get_color(&self) -> &Color

Source

pub fn get_mut_color(&mut self) -> &mut Color

Source

pub fn set_color(&mut self, val: Color) -> &mut Self

Source

pub fn get_padding(&self) -> &(f64, f64, f64, f64)

Source

pub fn get_mut_padding(&mut self) -> &mut (f64, f64, f64, f64)

Source

pub fn set_padding(&mut self, val: (f64, f64, f64, f64)) -> &mut Self

Source

pub fn get_border_width(&self) -> f64

Source

pub fn get_mut_border_width(&mut self) -> &mut f64

Source

pub fn set_border_width(&mut self, val: f64) -> &mut Self

Source

pub fn get_border_radius(&self) -> f64

Source

pub fn get_mut_border_radius(&mut self) -> &mut f64

Source

pub fn set_border_radius(&mut self, val: f64) -> &mut Self

Source

pub fn get_rotate(&self) -> f64

Source

pub fn get_mut_rotate(&mut self) -> &mut f64

Source

pub fn set_rotate(&mut self, val: f64) -> &mut Self

Source

pub fn get_stroke_width(&self) -> f64

Source

pub fn get_mut_stroke_width(&mut self) -> &mut f64

Source

pub fn set_stroke_width(&mut self, val: f64) -> &mut Self

Source

pub fn get_rich(&self) -> &Vec<(String, RichTextStyle)>

Source

pub fn get_mut_rich(&mut self) -> &mut Vec<(String, RichTextStyle)>

Source

pub fn set_rich(&mut self, val: Vec<(String, RichTextStyle)>) -> &mut Self

Trait Implementations§

Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> Self

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 Debug for TextStyle

Source§

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

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

impl Default for TextStyle

Default construction for TextStyle.

Source§

fn default() -> Self

Constructs a default TextStyle value.

Source§

impl PartialEq for TextStyle

Source§

fn eq(&self, other: &Self) -> 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 TextStyle

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> 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<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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more