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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Keyboard shortcut display widget.
//!
//! The [`ShortcutText!`] is composite widget that generates localized and styled shortcut *text*, it
//! can handle all shortcut variations, multiple shortcuts and partially invalid shortcuts.
//! Extensive configuration is possible using contextual properties that can override.
//!
//! The example below demonstrates a basic *key binding editor* that uses the [`ShortcutText!`] widget in multiple places.
//!
//! ```
//! # use zng::focus::{focus_on_init, focusable};
//! # use zng::gesture::Shortcuts;
//! # use zng::keyboard::{Key, KeyInputArgs, on_pre_key_down};
//! # use zng::layout::{align, min_height};
//! # use zng::prelude::*;
//! # use zng::shortcut_text::ShortcutText;
//! #
//! pub fn shortcut_input(shortcut: Var<Shortcuts>) -> UiNode {
//! Button! {
//! // display the shortcut, or the `none_fn` content if there is no shortcut.
//! child = ShortcutText! {
//! shortcut = shortcut.clone();
//! none_fn = wgt_fn!(|_| Text!("no shortcut"));
//! };
//! on_click = hn!(|_| {
//! DIALOG.custom(shortcut_input_dialog(shortcut.clone()));
//! });
//! }
//! }
//! fn shortcut_input_dialog(output: Var<gesture::Shortcuts>) -> UiNode {
//! let pressed = var(Shortcuts::new());
//! let is_valid = var(true);
//! Container! {
//! child_top = Wrap!(ui_vec![
//! Text!("Press the new shortcut and then press "),
//! ShortcutText!(shortcut!(Enter)), // shortcut text supports inlining
//! ]);
//! child_spacing = 20;
//! // default style is derived from the `font_size` and `font_color` values.
//! child = ShortcutText! {
//! shortcut = pressed.clone();
//! font_size = 3.em();
//! align = Align::TOP;
//! when !#{is_valid.clone()} {
//! font_color = colors::RED;
//! }
//! };
//!
//! on_pre_key_down = hn!(|args| {
//! args.propagation.stop();
//! match &args.key {
//! Key::Enter => {
//! let shortcut = pressed.get();
//! if shortcut.is_empty() || shortcut[0].is_valid() {
//! is_valid.set(true);
//! output.set(shortcut);
//! DIALOG.respond(dialog::Response::ok());
//! } else {
//! is_valid.set(false);
//! }
//! }
//! Key::Escape => {
//! DIALOG.respond(dialog::Response::cancel());
//! }
//! _ => {
//! is_valid.set(true); // clear
//! pressed.set(args.editing_shortcut().unwrap());
//! }
//! }
//! });
//! align = Align::CENTER;
//! min_height = 200;
//! focusable = true;
//! focus_on_init = true;
//! }
//! }
//! ```
//!
//! [`ShortcutText!`]: struct@ShortcutText
//!
//! # Full API
//!
//! See [`zng_wgt_shortcut`] for the full widget API.
pub use ;