Skip to main content

freya_core/style/
text_decoration.rs

1use freya_engine::prelude::SkTextDecoration;
2
3/// A line drawn through, under or over text.
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
6pub enum TextDecoration {
7    /// No decoration. This is the default.
8    #[default]
9    None,
10    /// A line below the text.
11    Underline,
12    /// A line above the text.
13    Overline,
14    /// A line through the middle of the text.
15    LineThrough,
16}
17
18impl TextDecoration {
19    pub fn pretty(&self) -> String {
20        match self {
21            Self::None => "none".to_string(),
22            Self::Underline => "underline".to_string(),
23            Self::Overline => "overline".to_string(),
24            Self::LineThrough => "line-through".to_string(),
25        }
26    }
27}
28
29impl From<TextDecoration> for SkTextDecoration {
30    fn from(value: TextDecoration) -> Self {
31        match value {
32            TextDecoration::None => SkTextDecoration::NO_DECORATION,
33            TextDecoration::Underline => SkTextDecoration::UNDERLINE,
34            TextDecoration::Overline => SkTextDecoration::OVERLINE,
35            TextDecoration::LineThrough => SkTextDecoration::LINE_THROUGH,
36        }
37    }
38}