zng/
selectable.rs

1#![cfg(feature = "text_input")]
2
3//! Selectable text widget and properties.
4//!
5//! The [`SelectableText!`](struct@SelectableText) is a read-only styleable text with text selection enabled.
6//! Any `Text!` widget can enable selection using the `txt_selectable` property, this widget complements that
7//! by adding a context menu and touch selection toolbar. The widget should be used for every text the user might wish to copy.
8//!
9//! The example below uses the widget to display an error message, it looks just like a simple `Text!` rendered, but
10//! the cursor is different, the `SELECT_ALL_CMD` and `COPY_CMD` commands are available in the context menu and
11//! the selection toolbar (if selected by touch).
12//!
13//! ```
14//! use zng::prelude::*;
15//! fn show_error(msg: impl Into<Txt>) {
16//!     LAYERS.insert(
17//!         LayerIndex::TOP_MOST,
18//!         Container! {
19//!             id = "error-dlg";
20//!             widget::modal = true;
21//!             child_align = layout::Align::CENTER;
22//!             child = Container! {
23//!                 padding = 10;
24//!                 widget::background_color = colors::RED.desaturate(80.pct());
25//!                 child_spacing = (5, 0, 10, 0);
26//!                 child_top = text::Strong!("Error");
27//!                 child = SelectableText!(msg.into());
28//!                 child_bottom = Button! {
29//!                     child = Text!("Ok");
30//!                     layout::align = layout::Align::END;
31//!                     on_click = hn!(|_| {
32//!                         LAYERS.remove("error-dlg");
33//!                     });
34//!                 };
35//!             };
36//!         },
37//!     );
38//! }
39//! ```
40//!
41//! # Full API
42//!
43//! See [`zng_wgt_text_input::selectable`] for the full widget API.
44
45pub use zng_wgt_text_input::selectable::{DefaultStyle, SelectableText, style_fn};