zng/
rule_line.rs

1#![cfg(feature = "rule_line")]
2
3//! Rule line widgets and properties.
4//!
5//! A rule line is a horizontal or vertical separator line, this module provides 3 widgets the [`RuleLine!`](struct@RuleLine)
6//! base that can dynamically change orientation and the [`hr::Hr!`](struct@hr::Hr) and [`vr::Vr!`](struct@vr::Vr) that represents
7//! each orientation and can be styled separately.
8//!
9//! ```
10//! use zng::prelude::*;
11//! # fn demo() {
12//!
13//! # let _ =
14//! Window! {
15//!     context_menu = ContextMenu!(ui_vec![
16//!         Button!(zng::app::NEW_CMD.scoped(WINDOW.id())),
17//!         Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
18//!         Hr!(),
19//!         Button!(zng::app::EXIT_CMD),
20//!     ]);
21//! }
22//! # ; }
23//! ```
24//!
25//! The example above uses the `Hr!` widget in a context menu to separate the commands into two groups.
26//!
27//! # Collapse Scope
28//!
29//! Sometimes two or more separator lines can end-up appearing adjacent to one another, not actually *separating* anything. A
30//! parent panel widget can set [`collapse_scope`] to automatically *trim* or *merge* separator lines in its descendants.
31//!
32//! The `ContextMenu!`, `Menu!` and `SubMenu!` widgets enable this feature by default, the standalone property can also be set in any other widget.
33//!
34//! ```
35//! # use zng::prelude::*;
36//! # fn demo() {
37//! # let _ =
38//! Wrap! {
39//!     id = "toolbar";
40//!     zng::rule_line::vr::height = 1.em();
41//!     zng::rule_line::collapse_scope = true;
42//!     children = ui_vec![
43//!         Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
44//!         Vr!(),
45//!         Button!(zng::clipboard::COPY_CMD.scoped("content")),
46//!         Button!(zng::clipboard::PASTE_CMD.scoped("content")),
47//!     ];
48//! }
49//! # ; }
50//! ```
51//!
52//! The example above defines a `"toolbar"` panel with a vertical separator, command buttons are not visible when the command has no handle,
53//! in the example the clipboard commands are scoped to a `"content"` target, if that widget does not exist the buttons will collapse so the
54//! `Vr!()` would appear dangling at the end. In this example toolbar enables all features of [`collapse_scope`] that includes [`CollapseMode::TRIM_END`],
55//! so the vertical line will collapse as well, until the `"content"` widget is loaded.
56//!
57//! Note that [`collapse_scope`] also works in nested panels, a more complex *toolbars* setup can enable it at the *toolbar tray* root widget and
58//! all *toolbar* widgets can be dynamically moved and the separator lines will collapse as needed. The algorithm only considers leaf descendants so
59//! the scope UI tree can have any number of nested children widgets too.
60//!
61//! [`collapse_scope`]: fn@collapse_scope
62//!
63//! # Full API
64//!
65//! See [`zng_wgt_rule_line`] for the full widget API.
66
67pub use zng_wgt_rule_line::{CollapseMode, RuleLine, collapse_scope, collapse_skip};
68
69/// Horizontal rule line widget and properties.
70pub mod hr {
71    pub use zng_wgt_rule_line::hr::{Hr, color, line_style, margin, stroke_thickness, width};
72}
73
74/// Vertical rule line widget and properties.
75pub mod vr {
76    pub use zng_wgt_rule_line::vr::{Vr, color, height, line_style, margin, stroke_thickness};
77}