nuit_core/utils/font/
size.rs

1use serde::{Deserialize, Serialize};
2
3use super::FontLevel;
4
5#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
7pub enum FontSize {
8    Level { level: FontLevel },
9    Custom { size: f64 },
10}
11
12impl FontSize {
13    pub const EXTRA_LARGE_TITLE2: Self = Self::level(FontLevel::ExtraLargeTitle2);
14    pub const EXTRA_LARGE_TITLE: Self = Self::level(FontLevel::ExtraLargeTitle);
15    pub const LARGE_TITLE: Self = Self::level(FontLevel::LargeTitle);
16    pub const TITLE: Self = Self::level(FontLevel::Title);
17    pub const TITLE2: Self = Self::level(FontLevel::Title2);
18    pub const TITLE3: Self = Self::level(FontLevel::Title3);
19    pub const HEADLINE: Self = Self::level(FontLevel::Headline);
20    pub const SUBHEADLINE: Self = Self::level(FontLevel::Subheadline);
21    pub const BODY: Self = Self::level(FontLevel::Body);
22    pub const CALLOUT: Self = Self::level(FontLevel::Callout);
23    pub const CAPTION: Self = Self::level(FontLevel::Caption);
24    pub const CAPTION2: Self = Self::level(FontLevel::Caption2);
25    pub const FOOTNOTE: Self = Self::level(FontLevel::Footnote);
26
27    pub const fn level(level: FontLevel) -> Self {
28        Self::Level { level }
29    }
30
31    pub const fn custom(size: f64) -> Self {
32        Self::Custom { size }
33    }
34}
35
36impl From<usize> for FontSize {
37    fn from(size: usize) -> Self {
38        Self::Custom { size: size as f64 }
39    }
40}
41
42impl From<f64> for FontSize {
43    fn from(size: f64) -> Self {
44        Self::Custom { size }
45    }
46}
47
48impl From<FontLevel> for FontSize {
49    fn from(level: FontLevel) -> Self {
50        Self::Level { level }
51    }
52}