pub struct TextStyle {
pub font_size: FontSize,
pub line_height: LineHeight,
pub font_color: FontColor,
pub horizontal_alignment: HorizontalTextAlignment,
pub vertical_alignment: VerticalTextAlignment,
pub wrap: Option<TextWrap>,
pub font_family: FontFamily,
pub weight: Weight,
pub letter_spacing: Option<LetterSpacing>,
}Expand description
Comprehensive text styling configuration.
TextStyle combines all visual aspects of text rendering, including font properties,
colors, alignment, and wrapping behavior
Fields§
§font_size: FontSizeThe font size in points.
line_height: LineHeightThe line height is a multiplier of the font size.
font_color: FontColorThe color of the text.
horizontal_alignment: HorizontalTextAlignmentHorizontal text alignment within the container.
vertical_alignment: VerticalTextAlignmentVertical text alignment within the container.
wrap: Option<TextWrap>Text wrapping behavior.
font_family: FontFamilyThe font family to use for rendering. Can be a generic family created with an enum, or
you can use a CSS-like font family query string to specify custom fonts:
"Helvetica, 'Segoe UI', sans-serif".into().
weight: WeightThe font weight to use for rendering.
letter_spacing: Option<LetterSpacing>The spacing between characters as a multiplier of the font size.
Implementations§
Source§impl TextStyle
impl TextStyle
pub const DEFAULT: Self
Sourcepub const fn new(font_size: f32, font_color: Color) -> Self
pub const fn new(font_size: f32, font_color: Color) -> Self
Creates a new TextStyle with the specified font size and color.
Other properties are set to their default values.
§Arguments
font_size- The font size in pointsfont_color- The text color
§Examples
use protextinator::style::TextStyle;
use cosmic_text::Color;
let style = TextStyle::new(14.0, Color::rgb(0, 0, 0));Sourcepub const fn with_font_size(self, font_size: f32) -> Self
pub const fn with_font_size(self, font_size: f32) -> Self
Sourcepub const fn with_line_height(self, line_height: f32) -> Self
pub const fn with_line_height(self, line_height: f32) -> Self
Sourcepub const fn with_font_color(self, font_color: FontColor) -> Self
pub const fn with_font_color(self, font_color: FontColor) -> Self
Sourcepub const fn with_horizontal_alignment(
self,
alignment: HorizontalTextAlignment,
) -> Self
pub const fn with_horizontal_alignment( self, alignment: HorizontalTextAlignment, ) -> Self
Sourcepub const fn with_vertical_alignment(
self,
alignment: VerticalTextAlignment,
) -> Self
pub const fn with_vertical_alignment( self, alignment: VerticalTextAlignment, ) -> Self
Sourcepub const fn with_alignment(
self,
horizontal: HorizontalTextAlignment,
vertical: VerticalTextAlignment,
) -> Self
pub const fn with_alignment( self, horizontal: HorizontalTextAlignment, vertical: VerticalTextAlignment, ) -> Self
Sets both horizontal and vertical alignment and returns the modified style.
§Arguments
horizontal- The horizontal alignmentvertical- The vertical alignment
§Examples
use protextinator::style::{TextStyle, HorizontalTextAlignment, VerticalTextAlignment};
let style = TextStyle::default().with_alignment(
HorizontalTextAlignment::Center,
VerticalTextAlignment::Center
);Sourcepub const fn line_height_pt(&self) -> f32
pub const fn line_height_pt(&self) -> f32
Calculates the line height in points based on the font size and line height multiplier.
§Returns
The line height in points (font_size * line_height_multiplier)
§Examples
use protextinator::style::TextStyle;
let style = TextStyle::default().with_font_size(16.0).with_line_height(1.5);
assert_eq!(style.line_height_pt(), 24.0); // 16.0 * 1.5