Skip to main content

freya_core/style/
text_align.rs

1use freya_engine::prelude::SkTextAlign;
2
3/// Horizontal alignment of text within its element.
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
6pub enum TextAlign {
7    /// Align text to the left edge. This is the default.
8    #[default]
9    Left = 0,
10    /// Align text to the right edge.
11    Right = 1,
12    /// Center the text horizontally.
13    Center = 2,
14    /// Stretch each line to fill the width, except the last line.
15    Justify = 3,
16    /// Align text to the start edge, following the text direction.
17    Start = 4,
18    /// Align text to the end edge, following the text direction.
19    End = 5,
20}
21
22impl From<TextAlign> for SkTextAlign {
23    fn from(value: TextAlign) -> Self {
24        match value {
25            TextAlign::Left => SkTextAlign::Left,
26            TextAlign::Right => SkTextAlign::Right,
27            TextAlign::Center => SkTextAlign::Center,
28            TextAlign::Justify => SkTextAlign::Justify,
29            TextAlign::Start => SkTextAlign::Start,
30            TextAlign::End => SkTextAlign::End,
31        }
32    }
33}
34
35impl TextAlign {
36    pub fn pretty(&self) -> String {
37        match self {
38            Self::Left => "left".to_string(),
39            Self::Right => "right".to_string(),
40            Self::Center => "center".to_string(),
41            Self::Justify => "justify".to_string(),
42            Self::Start => "start".to_string(),
43            Self::End => "end".to_string(),
44        }
45    }
46}