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: f32One 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: f32Extra space between glyphs in font pixels (may be fractional or negative).
line_spacing: f32Extra space between lines in font pixels.
align: TextAlign§pixel_snap: boolRounds each line’s origin to the device pixel grid (default true) so
integer-scaled glyphs stay crisp at fractional positions.
Implementations§
Source§impl TextStyle
impl TextStyle
Sourcepub const fn modern(size: f32, color: Color) -> TextStyle
pub const fn modern(size: f32, color: Color) -> TextStyle
Modern face at size (one font pixel = size / 8).
pub const fn with_face(self, face: FontFace) -> TextStyle
pub const fn with_size(self, size: f32) -> TextStyle
pub const fn with_color(self, color: Color) -> TextStyle
pub const fn with_shadow(self, color: Color) -> TextStyle
pub const fn with_outline(self, color: Color) -> TextStyle
pub const fn with_letter_spacing(self, pixels: f32) -> TextStyle
pub const fn with_line_spacing(self, pixels: f32) -> TextStyle
pub const fn with_align(self, align: TextAlign) -> TextStyle
pub const fn with_pixel_snap(self, snap: bool) -> TextStyle
Sourcepub fn line_height(&self) -> f32
pub fn line_height(&self) -> f32
Baseline-to-baseline distance in logical units.
Sourcepub fn centered_baseline(&self, center_y: f32) -> f32
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 unitsTrait Implementations§
impl Copy for TextStyle
impl StructuralPartialEq for TextStyle
Auto Trait Implementations§
impl Freeze for TextStyle
impl RefUnwindSafe for TextStyle
impl Send for TextStyle
impl Sync for TextStyle
impl Unpin for TextStyle
impl UnwindSafe for TextStyle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more