ailloli_ui_core/style/
radius.rs

1//! Independent logical-pixel radii for four box corners.
2
3/// Per-corner border radius in logical pixels.
4///
5/// # Examples
6///
7/// ```
8/// use ailloli_ui_core::Radius;
9/// assert_eq!(Radius::uniform(4.0), Radius { tl: 4.0, tr: 4.0, br: 4.0, bl: 4.0 });
10/// ```
11#[derive(Debug, Clone, Copy, Default, PartialEq)]
12pub struct Radius {
13    /// Top-left radius in logical pixels.
14    pub tl: f32,
15    /// Top-right radius in logical pixels.
16    pub tr: f32,
17    /// Bottom-right radius in logical pixels.
18    pub br: f32,
19    /// Bottom-left radius in logical pixels.
20    pub bl: f32,
21}
22
23impl Radius {
24    /// Zero radius on all corners.
25    ///
26    /// # Examples
27    ///
28    /// ```
29    /// use ailloli_ui_core::Radius;
30    /// assert_eq!(Radius::zero(), Radius::uniform(0.0));
31    /// ```
32    pub const fn zero() -> Self {
33        Self::uniform(0.0)
34    }
35
36    /// Stores the same radius on all corners without clamping it.
37    ///
38    /// # Examples
39    ///
40    /// ```
41    /// use ailloli_ui_core::Radius;
42    /// assert_eq!(Radius::uniform(3.0).br, 3.0);
43    /// ```
44    pub const fn uniform(v: f32) -> Self {
45        Self {
46            tl: v,
47            tr: v,
48            br: v,
49            bl: v,
50        }
51    }
52
53    /// Stores independent radii in clockwise order from top-left.
54    ///
55    /// Negative and non-finite values are preserved for later geometry/render
56    /// normalization.
57    ///
58    /// # Examples
59    ///
60    /// ```
61    /// use ailloli_ui_core::Radius;
62    /// assert_eq!(Radius::per_corner(1.0, 2.0, 3.0, 4.0).bl, 4.0);
63    /// ```
64    pub const fn per_corner(tl: f32, tr: f32, br: f32, bl: f32) -> Self {
65        Self { tl, tr, br, bl }
66    }
67}