| Add generics; transpile the part of cosmic-theme that is reachable ff34e1b nandithebull 4h ago | 1 | |
| 2 | /// Spacing variables for the Cosmic theme |
| 3 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 4 | pub struct Spacing { |
| 5 | /// No spacing |
| 6 | pub space_none: u16, |
| 7 | /// smallest spacing that can be non-zero |
| 8 | pub space_xxxs: u16, |
| 9 | /// extra extra small spacing |
| 10 | pub space_xxs: u16, |
| 11 | /// extra small spacing |
| 12 | pub space_xs: u16, |
| 13 | /// small spacing |
| 14 | pub space_s: u16, |
| 15 | /// medium spacing |
| 16 | pub space_m: u16, |
| 17 | /// large spacing |
| 18 | pub space_l: u16, |
| 19 | /// extra large spacing |
| 20 | pub space_xl: u16, |
| 21 | /// extra extra large spacing |
| 22 | pub space_xxl: u16, |
| 23 | /// largest possible spacing |
| 24 | pub space_xxxl: u16, |
| 25 | } |
| 26 | |
| 27 | impl Default for Spacing { |
| 28 | fn default() -> Self { |
| 29 | Self { |
| 30 | space_none: 0, |
| 31 | space_xxxs: 4, |
| 32 | space_xxs: 8, |
| 33 | space_xs: 12, |
| 34 | space_s: 16, |
| 35 | space_m: 24, |
| 36 | space_l: 32, |
| 37 | space_xl: 48, |
| 38 | space_xxl: 64, |
| 39 | space_xxxl: 128, |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /// Density options for the Cosmic theme |
| 45 | #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] |
| 46 | pub enum Density { |
| 47 | /// Lower padding/spacing of elements |
| 48 | Compact, |
| 49 | /// Standard padding/spacing of elements |
| 50 | #[default] |
| 51 | Standard, |
| 52 | /// Higher padding/spacing of elements |
| 53 | Spacious, |
| 54 | } |
| 55 | |
| 56 | impl From<Density> for Spacing { |
| 57 | fn from(value: Density) -> Self { |
| 58 | match value { |
| 59 | Density::Compact => Spacing { |
| 60 | space_none: 0, |
| 61 | space_xxxs: 4, |
| 62 | space_xxs: 4, |
| 63 | space_xs: 8, |
| 64 | space_s: 8, |
| 65 | space_m: 16, |
| 66 | space_l: 24, |
| 67 | space_xl: 32, |
| 68 | space_xxl: 48, |
| 69 | space_xxxl: 64, |
| 70 | }, |
| 71 | Density::Standard => Spacing::default(), |
| 72 | Density::Spacious => Spacing { |
| 73 | space_none: 4, |
| 74 | space_xxxs: 8, |
| 75 | space_xxs: 12, |
| 76 | space_xs: 16, |
| 77 | space_s: 24, |
| 78 | space_m: 32, |
| 79 | space_l: 48, |
| 80 | space_xl: 64, |
| 81 | space_xxl: 128, |
| 82 | space_xxxl: 160, |
| 83 | }, |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl From<Spacing> for Density { |
| 89 | fn from(value: Spacing) -> Self { |
| 90 | if value.space_m.saturating_sub(16) == 0 { |
| 91 | Self::Compact |
| 92 | } else if value.space_m.saturating_sub(24) == 0 { |
| 93 | Self::Standard |
| 94 | } else { |
| 95 | Self::Spacious |
| 96 | } |
| 97 | } |
| 98 | } |