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//! # let _scope = APP.defaults();
10//!
11//!
12//! let mut popup = None;
13//! let is_closed = var(true);
14//! # let _ =
15//! Button! {
16//!     layout::align = layout::Align::CENTER;
17//!     child = Text!(is_closed.map(|&b| if b { "Open Popup" } else { "Close Popup" }.into()));
18//!     on_click = hn!(|_| {
19//!         if is_closed.get() {
20//!             let p = POPUP.open(zng::popup::Popup! {
21//!                 child = Text!("Popup content!");
22//!             });
23//!             p.bind_map(&is_closed, |s| matches!(s, zng::popup::PopupState::Closed)).perm();
24//!             popup = Some(p);
25//!         } else if let Some(p) = popup.take() {
26//!             POPUP.close(&p);
27//!         }
28//!     })
29//! }
30//! # ;
31//! ```
32//!
33//! The example above declares a button that opens and closes a popup
34//!
35//! Note that the toggle widget provides a [combo](crate::toggle#Combo) style and the [`checked_popup`](struct@crate::toggle::Toggle#checked_popup)
36//! property that implements a similar behavior.
37//!
38//! # Full API
39//!
40//! See [`zng_wgt_layer::popup`] for the full widget API.
41
42pub use zng_wgt_layer::popup::{
43    ContextCapture, DefaultStyle, POPUP, POPUP_CLOSE_CMD, POPUP_CLOSE_REQUESTED_EVENT, Popup, PopupCloseMode, PopupCloseRequestedArgs,
44    PopupState, anchor_mode, close_delay, close_on_focus_leave, context_capture, is_close_delaying, on_popup_close_requested,
45    on_pre_popup_close_requested, style_fn,
46};