Skip to main content

freya_core/style/
font_size.rs

1use std::ops::Deref;
2
3/// Defaults to `16`.
4///
5/// Implements `From<i32>` and `From<f32>`.
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[derive(Hash, Debug, PartialEq, Clone, Copy)]
8pub struct FontSize(i32);
9
10impl Default for FontSize {
11    fn default() -> Self {
12        FontSize(16)
13    }
14}
15
16impl From<i32> for FontSize {
17    fn from(value: i32) -> Self {
18        FontSize(value)
19    }
20}
21
22impl From<f32> for FontSize {
23    fn from(value: f32) -> Self {
24        FontSize(value as i32)
25    }
26}
27
28impl From<FontSize> for f32 {
29    fn from(value: FontSize) -> Self {
30        value.0 as f32
31    }
32}
33
34impl Deref for FontSize {
35    type Target = i32;
36    fn deref(&self) -> &Self::Target {
37        &self.0
38    }
39}