use crate::dialog::{AlertDialog, Dialog};
use crate::{App, Root, Window};
pub trait WindowExt: Sized {
fn open_dialog<F>(&mut self, cx: &mut App, build: F)
where
F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static;
fn open_alert_dialog<F>(&mut self, cx: &mut App, build: F)
where
F: Fn(AlertDialog, &mut Window, &mut App) -> AlertDialog + 'static;
fn has_active_dialog(&mut self, cx: &mut App) -> bool;
fn close_dialog(&mut self, cx: &mut App);
fn close_all_dialogs(&mut self, cx: &mut App);
}
impl WindowExt for Window {
#[inline]
fn open_dialog<F>(&mut self, cx: &mut App, build: F)
where
F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static,
{
Root::update(self, cx, move |root, window, cx| {
root.open_dialog(build, window, cx);
})
}
#[inline]
fn open_alert_dialog<F>(&mut self, cx: &mut App, build: F)
where
F: Fn(AlertDialog, &mut Window, &mut App) -> AlertDialog + 'static,
{
self.open_dialog(cx, move |_, window, cx| {
build(AlertDialog::new(cx), window, cx).into_dialog(window, cx)
})
}
#[inline]
fn has_active_dialog(&mut self, cx: &mut App) -> bool {
Root::read(self, cx).active_dialogs.len() > 0
}
#[inline]
fn close_dialog(&mut self, cx: &mut App) {
Root::update(self, cx, |root, window, cx| {
root.close_dialog(window, cx);
})
}
#[inline]
fn close_all_dialogs(&mut self, cx: &mut App) {
Root::update(self, cx, |root, window, cx| {
root.close_all_dialogs(window, cx);
})
}
}