waterui_layout/containers/divider.rs
1//! Divider layout primitive shared across `WaterUI` surfaces.
2
3use waterui_core::View;
4use waterui_core::layout::StretchAxis;
5use waterui_graphics::color::{BorderColor, Color};
6
7use crate::{frame::Frame, stack};
8
9/// A thin line that separates content.
10///
11/// Divider adapts to its parent container: in `VStack` it spans horizontally,
12/// in `HStack` it spans vertically. The line is drawn in the theme's separator
13/// colour — the [`BorderColor`] slot — so it follows the active theme and
14/// colour scheme on every backend.
15#[derive(Debug, Clone, Copy)]
16#[must_use]
17pub struct Divider;
18
19impl View for Divider {
20 fn body(self, env: &waterui_core::Environment) -> impl View {
21 let vertical_divider = matches!(env.get::<stack::Axis>(), Some(stack::Axis::Horizontal));
22
23 if vertical_divider {
24 Frame::new(Color::new(BorderColor)).width(1.0)
25 } else {
26 Frame::new(Color::new(BorderColor)).height(1.0)
27 }
28 }
29
30 /// A divider always spans its parent stack's cross axis and stays one
31 /// point thick on the main axis — which orientation that is resolves in
32 /// `body` from `stack::Axis`, but the cross-axis answer is the same either
33 /// way.
34 fn stretch_axis(&self) -> StretchAxis {
35 StretchAxis::CrossAxis
36 }
37}