1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use freya_engine::prelude::*;

use crate::{
    Parse,
    ParseError,
};

impl Parse for TextHeightBehavior {
    fn parse(value: &str) -> Result<Self, ParseError> {
        match value {
            "all" => Ok(TextHeightBehavior::All),
            "disable-first-ascent" => Ok(TextHeightBehavior::DisableFirstAscent),
            "disable-least-ascent" => Ok(TextHeightBehavior::DisableLastDescent),
            "disable-all" => Ok(TextHeightBehavior::DisableAll),
            _ => Err(ParseError),
        }
    }
}

pub trait TextHeight {
    fn needs_custom_height(&self) -> bool;
}

impl TextHeight for TextHeightBehavior {
    fn needs_custom_height(&self) -> bool {
        matches!(
            self,
            Self::All | Self::DisableFirstAscent | Self::DisableLastDescent
        )
    }
}