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(LayerIndex::TOP_MOST, Container! {
17//!         id = "error-dlg";
18//!         widget::modal = true;
19//!         child_align = layout::Align::CENTER;
20//!         child = Container! {
21//!             padding = 10;
22//!             widget::background_color = colors::RED.desaturate(80.pct());
23//!             child_top = text::Strong!("Error"), 5;
24//!             child = SelectableText!(msg.into());
25//!             child_bottom = Button! {
26//!                 child = Text!("Ok");
27//!                 layout::align = layout::Align::END;
28//!                 on_click = hn!(|_| {
29//!                     LAYERS.remove("error-dlg");
30//!                 });
31//!             }, 10;
32//!         }
33//!     });
34//! }
35//! ```
36//!
37//! # Full API
38//!
39//! See [`zng_wgt_text_input::selectable`] for the full widget API.
40
41pub use zng_wgt_text_input::selectable::{DefaultStyle, SelectableText, style_fn};