ailloli_ui_widgets/primitives/spacer.rs
1//! Layout-only flexible spacer value.
2
3use ailloli_ui_core::Size;
4
5#[derive(Debug, Clone, Copy, PartialEq)]
6/// Zero-size spacer whose parent interprets a relative flex weight.
7///
8/// The default weight is one. Zero is valid and requests no share of remaining
9/// main-axis space; overflow in aggregate parent weights follows that parent's
10/// flex algorithm.
11///
12/// # Examples
13///
14/// ```
15/// use ailloli_ui_widgets::primitives::spacer::Spacer;
16/// assert_eq!(Spacer::default().flex, 1);
17/// ```
18pub struct Spacer {
19 /// Dimensionless relative flex weight consumed by a parent layout.
20 pub flex: u32,
21}
22
23/// Creates a spacer with unit flex weight.
24impl Default for Spacer {
25 fn default() -> Self {
26 Self { flex: 1 }
27 }
28}
29
30impl Spacer {
31 /// Creates a spacer with the exact dimensionless `flex` weight.
32 ///
33 /// # Examples
34 ///
35 /// ```
36 /// use ailloli_ui_widgets::primitives::spacer::Spacer;
37 /// assert_eq!(Spacer::with_flex(3).flex, 3);
38 /// ```
39 pub fn with_flex(flex: u32) -> Self {
40 Self { flex }
41 }
42
43 /// Returns the intrinsic zero size; the parent supplies allocated space.
44 ///
45 /// # Examples
46 ///
47 /// ```
48 /// use ailloli_ui_core::Size;
49 /// use ailloli_ui_widgets::primitives::spacer::Spacer;
50 /// assert_eq!(Spacer::default().layout(), Size::default());
51 /// ```
52 pub fn layout(self) -> Size {
53 // Layout-only: size comes from the parent (Row/Column/Flex).
54 Size::default()
55 }
56}