freya_core/style/
text_height.rs

1use freya_engine::prelude::*;
2
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
5pub enum TextHeightBehavior {
6    All = 0,
7    DisableFirstAscent = 1,
8    DisableLastDescent = 2,
9    #[default]
10    DisableAll = 3,
11}
12
13impl TextHeightBehavior {
14    pub fn needs_custom_height(&self) -> bool {
15        matches!(
16            self,
17            Self::All | Self::DisableFirstAscent | Self::DisableLastDescent
18        )
19    }
20
21    pub fn pretty(&self) -> String {
22        match self {
23            Self::All => "All".to_string(),
24            Self::DisableFirstAscent => "DisableFirstAscent".to_string(),
25            Self::DisableLastDescent => "DisableLastDescent".to_string(),
26            Self::DisableAll => "DisableAll".to_string(),
27        }
28    }
29}
30
31impl From<TextHeightBehavior> for SkTextHeightBehavior {
32    fn from(value: TextHeightBehavior) -> Self {
33        match value {
34            TextHeightBehavior::All => SkTextHeightBehavior::All,
35            TextHeightBehavior::DisableAll => SkTextHeightBehavior::DisableAll,
36            TextHeightBehavior::DisableFirstAscent => SkTextHeightBehavior::DisableFirstAscent,
37            TextHeightBehavior::DisableLastDescent => SkTextHeightBehavior::DisableLastDescent,
38        }
39    }
40}