1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::prelude::*;

pub struct Divider {}

impl Divider {
    /// Creates a dividing line. Orientation is determined by context (default horizontal).
    pub fn new(cx: &mut Context) -> Handle<Self> {
        Self {}.build(cx, |_| {})
    }

    /// Creates a horizontal dividing line.
    pub fn horizontal(cx: &mut Context) -> Handle<Self> {
        Self {}.build(cx, |_| {}).class("horizontal")
    }

    /// Creates a vertical dividing line.
    pub fn vertical(cx: &mut Context) -> Handle<Self> {
        Self {}.build(cx, |_| {}).class("vertical")
    }
}

impl View for Divider {
    fn element(&self) -> Option<&'static str> {
        Some("divider")
    }
}

impl<'a> Handle<'a, Divider> {
    pub fn orientation(self, orientation: impl Res<Orientation>) -> Self {
        self.bind(orientation, move |handle, orientation| {
            let orientation = orientation.get(&handle);
            if orientation == Orientation::Horizontal {
                handle.class("horizontal");
            } else {
                handle.class("vertical");
            }
        })
    }
}