Skip to main content

mitsuami_widgets/
separator.rs

1//! Separator lines.
2
3use mitsuami_core::{Element, ElementBuilder, NodeId, Orientation, Prop, Tweak, Ui, View, WidgetKind};
4use mitsuami_reactive::{IntoValue, Value};
5
6/// A line between groups of content, as the platform draws one: a
7/// separator `NSBox`, `gtk::Separator`, `Kirigami.Separator`, and on
8/// WinUI, which has no separator control, a `Border` in the divider brush,
9/// as Fluent apps draw one. Horizontal unless told otherwise, as thick as
10/// the platform makes it; its length is the layout's, so it spans a
11/// column (or a row, vertical) that stretches its children, as they do
12/// by default.
13///
14/// ```ignore
15/// Column::new().children((general(), Separator::new(), advanced()))
16/// Row::new().children((back(), Separator::vertical(), forward()))
17/// ```
18pub struct Separator(Element);
19
20widget!(Separator);
21
22impl Separator {
23    pub fn new() -> Separator {
24        let mut element = Element::new(WidgetKind::Separator);
25        element.prop(Value::Static(Orientation::Horizontal), Prop::Orientation);
26        Separator(element)
27    }
28
29    /// A vertical one, between things side by side.
30    pub fn vertical() -> Separator {
31        Separator::new().orientation(Orientation::Vertical)
32    }
33
34    /// Which way it runs.
35    pub fn orientation(mut self, orientation: impl IntoValue<Orientation>) -> Separator {
36        self.0.prop(orientation.into_value(), Prop::Orientation);
37        self
38    }
39
40    /// Raw platform settings: see [`Tweak`].
41    pub fn native(mut self, tweak: Tweak<Separator>) -> Separator {
42        tweak.apply(&mut self.0);
43        self
44    }
45}
46
47impl Default for Separator {
48    fn default() -> Separator {
49        Separator::new()
50    }
51}
52
53impl Separator {
54    /// `<Separator/>`, `<Separator orientation=Orientation::Vertical/>`
55    #[doc(hidden)]
56    pub fn __tag() -> Separator {
57        Separator::new()
58    }
59}