Skip to main content

TextStyle

Struct TextStyle 

Source
pub struct TextStyle {
Show 14 fields pub font_family: Option<String>, pub font_size: f32, pub fill: Paint, pub line_height: f32, pub letter_spacing: f32, pub font_weight: u16, pub align: TextAlign, pub max_width: f32, pub position: Vec2, pub anchor: Vec2, pub strokes: Vec<TextStroke>, pub shadows: Vec<TextShadow>, pub background: Option<TextBackground>, pub animators: Vec<TextAnimator>,
}
Expand description

How text looks and where it lies, for caption cues or a text crate::Generator.

The font size is a fraction of the canvas’s shorter side, the wrapping width a fraction of the canvas width, and strokes, shadows and padding fractions of the font size. The engine draws with its host’s registered fonts, font_family first, then the rest in fallback order.

Painting is bottom to top as in CSS: background boxes, shadows (last listed lowest), strokes (outermost lowest), fill, then color glyphs.

Fields§

§font_family: Option<String>

The family, as the font’s name table gives it (typographic family, else family), matched ASCII case-insensitively. Missing glyphs and unknown families fall back to the other fonts in order; None uses the fallback order alone. Non-empty, at most MAX_FONT_FAMILY_BYTES bytes.

§font_size: f32

Font size as a fraction of the canvas’s shorter side: positive, at most crate::MAX_CAPTION_FONT_SIZE on a caption track and MAX_TEXT_GENERATOR_FONT_SIZE in a text generator.

§fill: Paint

What paints the glyphs; a color reads as a solid paint. Gradient positions are in the text’s layout box, (0, 0) top-left to (1, 1) bottom-right, and a radial radius is a fraction of the box’s shorter side. Default solid white.

§line_height: f32

Baseline-to-baseline distance in font sizes, in [0.5, 3]. Each line’s em box (0.8 font sizes above the baseline, 0.2 below) is centred in a taller line.

§letter_spacing: f32

Space after each character, as a fraction of the font size, in [-0.5, 1], added as CSS letter-spacing does: none after a line’s last character or within cursive scripts such as Arabic. A non-zero value turns optional ligatures off.

§font_weight: u16

The weight in [1, 1000] used to match a family’s faces, as CSS Fonts 4 matches font-weight. Variable faces draw at it, clamped to their wght axis; no face is synthetically emboldened.

§align: TextAlign

How lines align within the text.

§max_width: f32

Width text wraps at, as a fraction of the canvas width, in (0, 1].

§position: Vec2

Where on the canvas the text’s anchor lies, (0, 0) top-left to (1, 1) bottom-right.

§anchor: Vec2

The point of the text, background included, placed at position; (0.5, 1) is its bottom centre.

§strokes: Vec<TextStroke>

Bands around the glyphs, innermost first, each outside the one before. At most MAX_TEXT_STROKES, widths summing to at most MAX_TEXT_STROKE_EXTENT.

§shadows: Vec<TextShadow>

Shadows of the glyphs and strokes, the first on top, as CSS text-shadow lists them. At most MAX_TEXT_SHADOWS.

§background: Option<TextBackground>

A box behind each line.

§animators: Vec<TextAnimator>

Per-character motion and color, applied in order, at most crate::MAX_TEXT_ANIMATORS. Keyframes are in the holder’s time (since a caption cue’s start, or a text generator’s picture time). They never change line layout.

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TextStyle

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
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 Serialize for TextStyle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.