| Add generics; transpile the part of cosmic-theme that is reachable ff34e1b nandithebull 14h ago | 1 | |
| 2 | /// Corner radii variables for the Cosmic theme |
| 3 | #[derive(Debug, Copy, Clone, PartialEq)] |
| 4 | pub struct CornerRadii { |
| 5 | /// corner radii of 0 |
| 6 | pub radius_0: [f32; 4], |
| 7 | /// smallest size of corner radii that can be non-zero |
| 8 | pub radius_xs: [f32; 4], |
| 9 | /// small corner radii |
| 10 | pub radius_s: [f32; 4], |
| 11 | /// medium corner radii |
| 12 | pub radius_m: [f32; 4], |
| 13 | /// large corner radii |
| 14 | pub radius_l: [f32; 4], |
| 15 | /// extra large corner radii |
| 16 | pub radius_xl: [f32; 4], |
| 17 | } |
| 18 | |
| 19 | impl Default for CornerRadii { |
| 20 | fn default() -> Self { |
| 21 | Self { |
| 22 | radius_0: [0.0; 4], |
| 23 | radius_xs: [4.0; 4], |
| 24 | radius_s: [8.0; 4], |
| 25 | radius_m: [16.0; 4], |
| 26 | radius_l: [32.0; 4], |
| 27 | radius_xl: [160.0; 4], |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /// Roundness options for the Cosmic theme |
| 33 | #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] |
| 34 | pub enum Roundness { |
| 35 | /// Round style |
| 36 | #[default] |
| 37 | Round, |
| 38 | /// Slightly round style |
| 39 | SlightlyRound, |
| 40 | /// Square style |
| 41 | Square, |
| 42 | } |
| 43 | |
| 44 | impl From<Roundness> for CornerRadii { |
| 45 | fn from(value: Roundness) -> Self { |
| 46 | match value { |
| 47 | Roundness::Round => CornerRadii::default(), |
| 48 | Roundness::SlightlyRound => CornerRadii { |
| 49 | radius_0: [0.0; 4], |
| 50 | radius_xs: [2.0; 4], |
| 51 | radius_s: [8.0; 4], |
| 52 | radius_m: [8.0; 4], |
| 53 | radius_l: [8.0; 4], |
| 54 | radius_xl: [8.0; 4], |
| 55 | }, |
| 56 | Roundness::Square => CornerRadii { |
| 57 | radius_0: [0.0; 4], |
| 58 | radius_xs: [2.0; 4], |
| 59 | radius_s: [2.0; 4], |
| 60 | radius_m: [2.0; 4], |
| 61 | radius_l: [2.0; 4], |
| 62 | radius_xl: [2.0; 4], |
| 63 | }, |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | impl From<CornerRadii> for Roundness { |
| 69 | fn from(value: CornerRadii) -> Self { |
| 70 | if (value.radius_m[0] - 16.0).abs() < 0.01 { |
| 71 | Self::Round |
| 72 | } else if (value.radius_m[0] - 8.0).abs() < 0.01 { |
| 73 | Self::SlightlyRound |
| 74 | } else { |
| 75 | Self::Square |
| 76 | } |
| 77 | } |
| 78 | } |