vizia_core/views/
divider.rs

1use crate::prelude::*;
2
3/// The Divider view provides a thin, unobtrusive line for visually separating views.
4pub struct Divider {}
5
6impl Divider {
7    /// Creates a dividing line. Orientation is determined by context.
8    pub fn new(cx: &mut Context) -> Handle<Self> {
9        Self {}.build(cx, |cx| {
10            Element::new(cx).class("divider-line");
11        })
12    }
13
14    /// Creates a horizontal dividing line.
15    pub fn horizontal(cx: &mut Context) -> Handle<Self> {
16        Self::new(cx).class("horizontal")
17    }
18
19    /// Creates a vertical dividing line.
20    pub fn vertical(cx: &mut Context) -> Handle<Self> {
21        Self::new(cx).class("vertical")
22    }
23}
24
25impl View for Divider {
26    fn element(&self) -> Option<&'static str> {
27        Some("divider")
28    }
29}
30
31impl Handle<'_, Divider> {
32    /// Set the orientation of the divider. Accepts a value or a lens to an [Orientation].
33    pub fn orientation(self, orientation: impl Res<Orientation>) -> Self {
34        self.bind(orientation, move |handle, orientation| {
35            let orientation = orientation.get(&handle);
36            if orientation == Orientation::Horizontal {
37                handle.toggle_class("horizontal", true).toggle_class("vertical", false);
38            } else {
39                handle.toggle_class("horizontal", false).toggle_class("vertical", true);
40            }
41        })
42    }
43}