Skip to main content

whisker_css/prop/
linear.rs

1//! Lynx-only `linear-*` layout extensions. Used when
2//! `display: linear` (Lynx's default for `<view>`).
3
4use crate::css::Css;
5use crate::keyword::{LinearCrossGravity, LinearGravity, LinearLayoutGravity, LinearOrientation};
6
7impl Css {
8    /// Sets `linear-orientation` — Lynx's analogue of `flex-direction`.
9    /// <https://lynxjs.org/api/css/properties/linear-orientation>
10    pub fn linear_orientation(self, v: LinearOrientation) -> Self {
11        self.push("linear-orientation", v)
12    }
13
14    /// Sets `linear-direction` — direction the linear container flows.
15    /// <https://lynxjs.org/api/css/properties/linear-direction>
16    pub fn linear_direction(self, v: LinearOrientation) -> Self {
17        self.push("linear-direction", v)
18    }
19
20    /// Sets `linear-gravity` — main-axis alignment. **Deprecated**;
21    /// switch to `display: flex` + `justify-content` when possible.
22    /// <https://lynxjs.org/api/css/properties/linear-gravity>
23    pub fn linear_gravity(self, v: LinearGravity) -> Self {
24        self.push("linear-gravity", v)
25    }
26
27    /// Sets `linear-cross-gravity` — cross-axis alignment for all items.
28    /// <https://lynxjs.org/api/css/properties/linear-cross-gravity>
29    pub fn linear_cross_gravity(self, v: LinearCrossGravity) -> Self {
30        self.push("linear-cross-gravity", v)
31    }
32
33    /// Sets `linear-layout-gravity` — per-item cross-axis override.
34    /// <https://lynxjs.org/api/css/properties/linear-layout-gravity>
35    pub fn linear_layout_gravity(self, v: LinearLayoutGravity) -> Self {
36        self.push("linear-layout-gravity", v)
37    }
38
39    /// Sets `linear-weight` — relative size weight along the main axis.
40    /// <https://lynxjs.org/api/css/properties/linear-weight>
41    pub fn linear_weight(self, v: f32) -> Self {
42        self.push_raw("linear-weight", crate::to_css::number_to_string(v))
43    }
44
45    /// Sets `linear-weight-sum` — denominator for weight calculations.
46    /// <https://lynxjs.org/api/css/properties/linear-weight-sum>
47    pub fn linear_weight_sum(self, v: f32) -> Self {
48        self.push_raw("linear-weight-sum", crate::to_css::number_to_string(v))
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use crate::keyword::*;
55    use crate::Css;
56
57    #[test]
58    fn linear_orientation_and_direction() {
59        let s = Css::new()
60            .linear_orientation(LinearOrientation::Vertical)
61            .linear_direction(LinearOrientation::Horizontal);
62        assert_eq!(
63            s.to_string(),
64            "linear-orientation: vertical; linear-direction: horizontal;"
65        );
66    }
67
68    #[test]
69    fn linear_gravity_all_three() {
70        let s = Css::new()
71            .linear_gravity(LinearGravity::CenterVertical)
72            .linear_cross_gravity(LinearCrossGravity::Center)
73            .linear_layout_gravity(LinearLayoutGravity::Stretch);
74        assert_eq!(
75            s.to_string(),
76            "linear-gravity: center-vertical; linear-cross-gravity: center; linear-layout-gravity: stretch;"
77        );
78    }
79
80    #[test]
81    fn linear_weights() {
82        let s = Css::new().linear_weight(1.0).linear_weight_sum(3.0);
83        assert_eq!(s.to_string(), "linear-weight: 1; linear-weight-sum: 3;");
84    }
85}