zng/
popup.rs

1//! Popup widget and properties.
2//!
3//! A popup is a temporary *flyover* inserted as a top-most layer using [`POPUP`] service. The service works
4//! as an extension of the [`LAYERS`](crate::layer::LAYERS) service that implements the concept of *open* and *close* and
5//! close requests. The [`Popup!`](struct@Popup) widget is a styleable container that is a good popup root widget.
6//!
7//! ```
8//! use zng::prelude::*;
9//! # fn example() {
10//!
11//! let mut popup = None;
12//! let is_closed = var(true);
13//! # let _ =
14//! Button! {
15//!     layout::align = layout::Align::CENTER;
16//!     child = Text!(is_closed.map(|&b| if b { "Open Popup" } else { "Close Popup" }.into()));
17//!     on_click = hn!(|_| {
18//!         if is_closed.get() {
19//!             let p = POPUP.open(zng::popup::Popup! {
20//!                 child = Text!("Popup content!");
21//!             });
22//!             p.bind_map(&is_closed, |s| matches!(s, zng::popup::PopupState::Closed)).perm();
23//!             popup = Some(p);
24//!         } else if let Some(p) = popup.take() {
25//!             POPUP.close(&p);
26//!         }
27//!     });
28//! }
29//! # ; }
30//! ```
31//!
32//! The example above declares a button that opens and closes a popup
33//!
34//! Note that the toggle widget provides a [combo](crate::toggle#Combo) style and the [`checked_popup`](struct@crate::toggle::Toggle#checked_popup)
35//! property that implements a similar behavior.
36//!
37//! # Full API
38//!
39//! See [`zng_wgt_layer::popup`] for the full widget API.
40
41pub use zng_wgt_layer::popup::{
42    ContextCapture, DefaultStyle, POPUP, POPUP_CLOSE_CMD, POPUP_CLOSE_REQUESTED_EVENT, Popup, PopupCloseMode, PopupCloseRequestedArgs,
43    PopupState, anchor_mode, close_delay, close_on_focus_leave, context_capture, is_close_delaying, on_popup_close_requested,
44    on_pre_popup_close_requested, style_fn,
45};