Struct TextStyle

Source
pub struct TextStyle {
    pub face: FontFace,
    pub size: f32,
    pub color: Color,
    pub shadow: Option<Color>,
    pub outline: Option<Color>,
    pub letter_spacing: f32,
    pub line_spacing: f32,
    pub align: TextAlign,
    pub pixel_snap: bool,
}
Expand description

Appearance of styled text. Construct with TextStyle::modern or TextStyle::classic and refine with the with_* methods.

use ferravex_render::{Color, text::{FontFace, TextAlign, TextStyle}};
let style = TextStyle::modern(16., Color::new(1., 1., 1., 1.))
    .with_outline(Color::new(0., 0., 0., 1.))
    .with_letter_spacing(1.)
    .with_align(TextAlign::Right);
assert_eq!(style.face, FontFace::Modern);
assert_eq!(style.pixel(), 2.);

Fields§

§face: FontFace§size: f32

One font pixel is size / 8 logical units.

§color: Color§shadow: Option<Color>

One-font-pixel drop shadow (down and right), drawn under the outline.

§outline: Option<Color>

One-font-pixel outline around every glyph. Outlines of adjacent glyphs merge, so translucent outlines do not double-blend.

§letter_spacing: f32

Extra space between glyphs in font pixels (may be fractional or negative).

§line_spacing: f32

Extra space between lines in font pixels.

§align: TextAlign§pixel_snap: bool

Rounds each line’s origin to the device pixel grid (default true) so integer-scaled glyphs stay crisp at fractional positions.

Implementations§

Source§

impl TextStyle

Source

pub const fn modern(size: f32, color: Color) -> TextStyle

Modern face at size (one font pixel = size / 8).

Source

pub const fn classic(size: f32, color: Color) -> TextStyle

Classic 5×7 face at size.

Source

pub const fn with_face(self, face: FontFace) -> TextStyle

Source

pub const fn with_size(self, size: f32) -> TextStyle

Source

pub const fn with_color(self, color: Color) -> TextStyle

Source

pub const fn with_shadow(self, color: Color) -> TextStyle

Source

pub const fn with_outline(self, color: Color) -> TextStyle

Source

pub const fn with_letter_spacing(self, pixels: f32) -> TextStyle

Source

pub const fn with_line_spacing(self, pixels: f32) -> TextStyle

Source

pub const fn with_align(self, align: TextAlign) -> TextStyle

Source

pub const fn with_pixel_snap(self, snap: bool) -> TextStyle

Source

pub fn pixel(&self) -> f32

Size of one font pixel in logical units.

Source

pub fn line_height(&self) -> f32

Baseline-to-baseline distance in logical units.

Source

pub fn centered_baseline(&self, center_y: f32) -> f32

Baseline that optically centers capitals and digits on center_y.

use ferravex_render::{Color, text::TextStyle};
let style = TextStyle::modern(16., Color::new(1., 1., 1., 1.));
assert_eq!(style.centered_baseline(100.), 108.); // 8 px caps of 2 units

Trait Implementations§

Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> TextStyle

Returns a duplicate of the value. Read more
1.0.0 · 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<(), Error>

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

impl Default for TextStyle

Source§

fn default() -> TextStyle

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

impl PartialEq for TextStyle

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TextStyle

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 = 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.