use crate::dialog::{DialogImpl, MessageAlert, MessageConfirm};
use crate::Result;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
#[derive(Copy, Clone)]
pub enum MessageType {
Info,
Warning,
Error,
}
pub struct MessageDialog<'a> {
pub(crate) title: &'a str,
pub(crate) text: &'a str,
pub(crate) typ: MessageType,
pub(crate) owner: Option<RawWindowHandle>,
}
impl<'a> MessageDialog<'a> {
pub fn new() -> Self {
MessageDialog {
title: "",
text: "",
typ: MessageType::Info,
owner: None,
}
}
pub fn set_title(mut self, title: &'a str) -> Self {
self.title = title;
self
}
pub fn set_text(mut self, text: &'a str) -> Self {
self.text = text;
self
}
pub fn set_type(mut self, typ: MessageType) -> Self {
self.typ = typ;
self
}
pub fn set_owner<W: HasRawWindowHandle>(mut self, window: &W) -> Self {
self.owner = Some(window.raw_window_handle());
self
}
pub unsafe fn set_owner_handle(mut self, handle: RawWindowHandle) -> Self {
self.owner = Some(handle);
self
}
pub fn reset_owner(mut self) -> Self {
self.owner = None;
self
}
pub fn show_alert(self) -> Result<()> {
let mut dialog = MessageAlert {
title: self.title,
text: self.text,
typ: self.typ,
owner: self.owner,
};
dialog.show()
}
pub fn show_confirm(self) -> Result<bool> {
let mut dialog = MessageConfirm {
title: self.title,
text: self.text,
typ: self.typ,
owner: self.owner,
};
dialog.show()
}
}
impl Default for MessageDialog<'_> {
fn default() -> Self {
Self::new()
}
}