Skip to main content

cranpose_ui/text/
unit.rs

1#[derive(Clone, Copy, Debug, PartialEq, Default)]
2pub enum TextUnit {
3    #[default]
4    Unspecified,
5    Sp(f32),
6    Em(f32),
7}
8
9impl TextUnit {
10    pub fn is_unspecified(&self) -> bool {
11        matches!(self, TextUnit::Unspecified)
12    }
13
14    pub fn is_specified(&self) -> bool {
15        !self.is_unspecified()
16    }
17
18    pub fn value(&self) -> f32 {
19        match self {
20            TextUnit::Unspecified => f32::NAN, // Or panic? Kotlin returns value from packed bits.
21            TextUnit::Sp(v) => *v,
22            TextUnit::Em(v) => *v,
23        }
24    }
25}
26
27// Implement basic arithmetic ops that panic on unspecified (matching Kotlin checks) or return invalid?
28// Kotlin checks pre-conditions.