zng_wgt_rule_line/
vr.rs

1//! Vertical rule line.
2
3use zng_wgt::prelude::*;
4
5/// Draws a vertical [`RuleLine!`](struct@crate::RuleLine).
6#[widget($crate::vr::Vr)]
7pub struct Vr(super::RuleLine);
8impl Vr {
9    fn widget_intrinsic(&mut self) {
10        widget_set! {
11            self;
12            orientation = LineOrientation::Vertical;
13            color = COLOR_VAR;
14            stroke_thickness = STROKE_THICKNESS_VAR;
15            line_style = LINE_STYLE_VAR;
16            margin = MARGIN_VAR;
17            length = HEIGHT_VAR;
18        }
19    }
20}
21
22context_var! {
23    /// Line color, inherits from [`FONT_COLOR_VAR`].
24    ///
25    /// [`FONT_COLOR_VAR`]: zng_wgt_text::FONT_COLOR_VAR
26    pub static COLOR_VAR: Rgba = zng_wgt_text::FONT_COLOR_VAR.map(|c| c.with_alpha(30.pct()));
27
28    /// Line stroke thickness, default is `1.dip()`
29    pub static STROKE_THICKNESS_VAR: Length = 1.dip();
30
31    /// Line style, default is `Solid`.
32    pub static LINE_STYLE_VAR: LineStyle = LineStyle::Solid;
33
34    /// Margin around line.
35    ///
36    /// Is `(0, 4)` by default, 0 top-bottom, 4 left-right.
37    pub static MARGIN_VAR: SideOffsets = (0, 4);
38
39    /// Vertical line length.
40    ///
41    /// Is `Default` by default, that fills height.
42    pub static HEIGHT_VAR: Length = Length::Default;
43}
44
45/// Sets the line color of all descendant `Vr!()`.
46///
47/// The default is the `FONT_COLOR_VAR` with 30% alpha.
48///
49/// This property sets the [`COLOR_VAR`].
50#[property(CONTEXT, default(COLOR_VAR))]
51pub fn color(child: impl IntoUiNode, color: impl IntoVar<Rgba>) -> UiNode {
52    with_context_var(child, COLOR_VAR, color)
53}
54
55/// Sets the line stroke thickness of all descendant `Vr!()`.
56///
57/// The default is `1.dip()`.
58///
59/// This property sets the [`STROKE_THICKNESS_VAR`].
60#[property(CONTEXT, default(STROKE_THICKNESS_VAR))]
61pub fn stroke_thickness(child: impl IntoUiNode, thickness: impl IntoVar<Length>) -> UiNode {
62    with_context_var(child, STROKE_THICKNESS_VAR, thickness)
63}
64
65/// Sets the line style of all descendant `Vr!()`.
66///
67/// The default is `Solid`.
68///
69/// This property sets the [`LINE_STYLE_VAR`].
70#[property(CONTEXT, default(LINE_STYLE_VAR))]
71pub fn line_style(child: impl IntoUiNode, style: impl IntoVar<LineStyle>) -> UiNode {
72    with_context_var(child, LINE_STYLE_VAR, style)
73}
74
75/// Sets the margin around line of all descendant `Vr!()`.
76///
77/// Is `(0, 4)` by default, 0 top-bottom, 4 left-right.
78///
79/// This property sets the [`MARGIN_VAR`].
80#[property(CONTEXT, default(MARGIN_VAR))]
81pub fn margin(child: impl IntoUiNode, margin: impl IntoVar<SideOffsets>) -> UiNode {
82    with_context_var(child, MARGIN_VAR, margin)
83}
84
85/// Sets the vertical line length of all descendant `Vr!()`.
86///
87/// Is `Default` by default, that fills the height or collapses if not aligned to fill.
88///
89/// This property sets the [`HEIGHT_VAR`].
90#[property(CONTEXT, default(HEIGHT_VAR))]
91pub fn height(child: impl IntoUiNode, height: impl IntoVar<Length>) -> UiNode {
92    with_context_var(child, HEIGHT_VAR, height)
93}