zng_wgt_rule_line/
hr.rs

1//! Horizontal rule line.
2
3use zng_wgt::prelude::*;
4
5/// Draws an horizontal [`RuleLine!`](struct@crate::RuleLine).
6#[widget($crate::hr::Hr)]
7pub struct Hr(super::RuleLine);
8impl Hr {
9    fn widget_intrinsic(&mut self) {
10        widget_set! {
11            self;
12            orientation = LineOrientation::Horizontal;
13            color = COLOR_VAR;
14            stroke_thickness = STROKE_THICKNESS_VAR;
15            line_style = LINE_STYLE_VAR;
16            margin = MARGIN_VAR;
17            length = WIDTH_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 `(4, 0)` by default, 4 top-bottom, 0 left-right.
37    pub static MARGIN_VAR: SideOffsets = (4, 0);
38
39    /// Horizontal line length.
40    ///
41    /// Is `Default` by default, that fills width.
42    pub static WIDTH_VAR: Length = Length::Default;
43}
44
45/// Sets the line color of all descendant `Hr!()`.
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 `Hr!()`.
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 `Hr!()`.
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 `Hr!()`.
76///
77/// Is `(4, 0)` by default, 4 top-bottom, 0 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 horizontal line length of all descendant `Hr!()`.
86///
87/// Is `Default` by default, that fills the width or collapses if not aligned to fill.
88///
89/// This property sets the [`WIDTH_VAR`].
90#[property(CONTEXT, default(WIDTH_VAR))]
91pub fn width(child: impl IntoUiNode, width: impl IntoVar<Length>) -> UiNode {
92    with_context_var(child, WIDTH_VAR, width)
93}