nuit_core/utils/font/
font.rs1use serde::{Deserialize, Serialize};
2
3use super::{FontDesign, FontLevel, FontSize, FontWeight};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
8pub enum Font {
9 System { size: FontSize, design: Option<FontDesign>, weight: Option<FontWeight> },
10 Custom { name: String, size: f64 },
11}
12
13impl Font {
14 pub const EXTRA_LARGE_TITLE2: Self = Self::with_level(FontLevel::ExtraLargeTitle2);
15 pub const EXTRA_LARGE_TITLE: Self = Self::with_level(FontLevel::ExtraLargeTitle);
16 pub const LARGE_TITLE: Self = Self::with_level(FontLevel::LargeTitle);
17 pub const TITLE: Self = Self::with_level(FontLevel::Title);
18 pub const TITLE2: Self = Self::with_level(FontLevel::Title2);
19 pub const TITLE3: Self = Self::with_level(FontLevel::Title3);
20 pub const HEADLINE: Self = Self::with_level(FontLevel::Headline);
21 pub const SUBHEADLINE: Self = Self::with_level(FontLevel::Subheadline);
22 pub const BODY: Self = Self::with_level(FontLevel::Body);
23 pub const CALLOUT: Self = Self::with_level(FontLevel::Callout);
24 pub const CAPTION: Self = Self::with_level(FontLevel::Caption);
25 pub const CAPTION2: Self = Self::with_level(FontLevel::Caption2);
26 pub const FOOTNOTE: Self = Self::with_level(FontLevel::Footnote);
27
28 pub fn system(size: impl Into<FontSize>, design: Option<FontDesign>, weight: Option<FontWeight>) -> Self {
29 Self::System { size: size.into(), design, weight }
30 }
31
32 pub fn custom(name: impl Into<String>, size: impl Into<f64>) -> Self {
33 Self::Custom { name: name.into(), size: size.into() }
34 }
35
36 pub fn with_size(size: impl Into<FontSize>) -> Self {
37 Self::System { size: size.into(), design: None, weight: None }
38 }
39
40 pub const fn with_level(level: FontLevel) -> Self {
41 Self::System { size: FontSize::level(level), design: None, weight: None }
42 }
43}