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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
//! Modal dialog overlay widget and service.
//!
//! The [`DIALOG`] service provides custom and modal native dialogs.
//!
//! ```
//! use zng::prelude::*;
//!
//! # let _scope = APP.defaults();
//! # let _ =
//! Button! {
//! child = Text!("Info, Warn, Error");
//! on_click = async_hn!(|_| {
//! DIALOG.info("Info", "Information message.").wait_rsp().await;
//! DIALOG.warn("Warn", "Warning message.").wait_rsp().await;
//! DIALOG.error("Error", "Error message.").wait_rsp().await;
//! });
//! // dialog::native_dialogs = true;
//! }
//! # ;
//! ```
//!
//! The example above shows 3 custom dialogs in sequence, info, warn and error. If `dialog::native_dialogs = true` is uncommented
//! the example shows 3 native dialogs.
//!
//! Custom dialogs modal widgets, rendered in the window content, instantiated using the [`Dialog!`] widget.
//!
//! ```
//! use zng::prelude::*;
//!
//! # async fn _demo() {
//! let r = DIALOG
//! .custom(dialog::Dialog! {
//! style_fn = dialog::WarnStyle!();
//! title = Text!(l10n!("save-dlg.title", "Save File?"));
//! content = SelectableText!(l10n!("save-dlg.msg", "Save file? All unsaved changes will be lost."));
//! responses = vec![
//! dialog::Response::cancel(),
//! dialog::Response::new("discard", l10n!("save-dlg.discard", "Discard")),
//! dialog::Response::new("save", l10n!("save-dlg.save", "Save")),
//! ]
//! })
//! .wait_rsp()
//! .await;
//! if r.name == "save" {
//! // save
//! }
//! # }
//! ```
//!
//! The example above creates a custom dialog based on the warning dialog (`WarnStyle!`), it uses custom responses that are
//! identified by name.
//!
//! Some of the dialogs provided are native by default (and only native on this release), the example below shows a native save file dialog:
//!
//! ```
//! use zng::prelude::*;
//!
//! # async fn _demo() {
//! let mut f = dialog::FileDialogFilters::default();
//! f.push_filter("Text Files", &["txt", "md"]);
//! f.push_filter("Text File", &["txt"]);
//! f.push_filter("Markdown File", &["md"]);
//! f.push_filter("All Files", &["*"]);
//! let filters = f;
//!
//! let r = DIALOG
//! .save_file("Save Text", "last/save/dir", "last-name.txt", filters)
//! .wait_rsp()
//! .await
//! .into_path();
//!
//! if let Ok(Some(path)) = r {
//! std::fs::write(path, "contents".as_bytes()).unwrap();
//! }
//! # }
//! ```
//!
//! [`Dialog!`]: struct@Dialog
//!
//! # Full API
//!
//! See [`zng_wgt_dialog`] for the full view API.
pub use zng_wgt_dialog::{
native_dialogs, AskStyle, ConfirmStyle, DefaultStyle, Dialog, DialogButtonArgs, DialogKind, ErrorStyle, FileDialogFilters,
FileDialogResponse, InfoStyle, Response, Responses, WarnStyle, DIALOG,
};
/// Modal dialog parent widget that fills the window.
///
/// Note that the actual [`DialogBackdrop!`] widget is not included in this module because it is instantiated by the [`DIALOG`] service.
/// The backdrop can be customized by setting the [`backdrop::style_fn`].
///
/// ```
/// use zng::prelude::*;
///
/// # let _scope = APP.defaults();
/// # let _ =
/// Window! {
/// dialog::backdrop::style_fn = Style! {
/// replace = true;
/// color::filter::backdrop_blur = 2;
/// };
/// }
/// # ;
/// ```
///
/// The example above configures the backdrop to blur the window content when any dialog is open.
///
/// [`DialogBackdrop!`]: struct@zng_wgt_dialog::backdrop::DialogBackdrop
/// [`backdrop::style_fn`]: fn@crate::dialog::backdrop::style_fn
/// [`DIALOG`]: crate::dialog::DIALOG
///
/// # Full API
///
/// See [`zng_wgt_dialog::backdrop`] for the fill view API.
pub mod backdrop {
pub use zng_wgt_dialog::backdrop::{style_fn, DefaultStyle};
}