Skip to main content

TextStyle

Struct TextStyle 

Source
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: FontSize

The font size in points.

§line_height: LineHeight

The line height is a multiplier of the font size.

§font_color: FontColor

The color of the text.

§horizontal_alignment: HorizontalTextAlignment

Horizontal text alignment within the container.

§vertical_alignment: VerticalTextAlignment

Vertical text alignment within the container.

§wrap: Option<TextWrap>

Text wrapping behavior.

§font_family: FontFamily

The 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: Weight

The 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

Source

pub const DEFAULT: Self

Source

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 points
  • font_color - The text color
§Examples
use protextinator::style::TextStyle;
use cosmic_text::Color;

let style = TextStyle::new(14.0, Color::rgb(0, 0, 0));
Source

pub const fn with_font_size(self, font_size: f32) -> Self

Sets the font size and returns the modified style.

§Arguments
  • font_size - The font size in points
§Examples
use protextinator::style::TextStyle;

let style = TextStyle::default().with_font_size(18.0);
Source

pub const fn with_line_height(self, line_height: f32) -> Self

Sets the line height and returns the modified style.

§Arguments
  • line_height - The line height as a multiplier of font size
§Examples
use protextinator::style::TextStyle;

let style = TextStyle::default().with_line_height(1.2);
Source

pub const fn with_font_color(self, font_color: FontColor) -> Self

Sets the font color and returns the modified style.

§Arguments
  • font_color - The text color
§Examples
use protextinator::style::{TextStyle, FontColor};

let style = TextStyle::default().with_font_color(FontColor::rgb(255, 0, 0));
Source

pub const fn with_horizontal_alignment( self, alignment: HorizontalTextAlignment, ) -> Self

Sets the horizontal alignment and returns the modified style.

§Arguments
  • alignment - The horizontal alignment
§Examples
use protextinator::style::{TextStyle, HorizontalTextAlignment};

let style = TextStyle::default().with_horizontal_alignment(HorizontalTextAlignment::Center);
Source

pub const fn with_vertical_alignment( self, alignment: VerticalTextAlignment, ) -> Self

Sets the vertical alignment and returns the modified style.

§Arguments
  • alignment - The vertical alignment
§Examples
use protextinator::style::{TextStyle, VerticalTextAlignment};

let style = TextStyle::default().with_vertical_alignment(VerticalTextAlignment::Center);
Source

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 alignment
  • vertical - The vertical alignment
§Examples
use protextinator::style::{TextStyle, HorizontalTextAlignment, VerticalTextAlignment};

let style = TextStyle::default().with_alignment(
    HorizontalTextAlignment::Center,
    VerticalTextAlignment::Center
);
Source

pub const fn with_wrap(self, wrap: TextWrap) -> Self

Sets the text wrapping behavior and returns the modified style.

§Arguments
  • wrap - The text wrapping behavior
§Examples
use protextinator::style::{TextStyle, TextWrap};

let style = TextStyle::default().with_wrap(TextWrap::Wrap);
Source

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

Trait Implementations§

Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> TextStyle

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

Creates a default text style with standard settings.

Default values:

  • Font size: 16.0 points
  • Line height: 1.5x font size
  • Font color: White (255, 255, 255)
  • No overflow handling
  • Start horizontal alignment
  • Start vertical alignment
  • No text wrapping
  • Sans-serif font family
Source§

impl Eq for TextStyle

Source§

impl Hash for TextStyle

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. 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 (const: unstable) · 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 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.