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
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()
}
}