1use tauri_dialog_sys::show_dialog;
4pub use tauri_dialog_sys::{DialogButtons, DialogSelection, DialogStyle};
5
6#[derive(Default)]
7pub struct DialogBuilder<'a> {
8 message: Option<&'a str>,
9 title: Option<&'a str>,
10 style: Option<DialogStyle>,
11 buttons: Option<DialogButtons>,
12}
13
14impl<'a> DialogBuilder<'a> {
15 pub fn new() -> Self {
16 Default::default()
17 }
18
19 pub fn message(mut self, message: &'a str) -> Self {
20 self.message = Some(message);
21 self
22 }
23
24 pub fn title(mut self, title: &'a str) -> Self {
25 self.title = Some(title);
26 self
27 }
28
29 pub fn style(mut self, style: DialogStyle) -> Self {
30 self.style = Some(style);
31 self
32 }
33
34 pub fn buttons(mut self, buttons: DialogButtons) -> Self {
35 self.buttons = Some(buttons);
36 self
37 }
38
39 pub fn build(self) -> Dialog<'a> {
40 Dialog {
41 message: self.message.unwrap_or(""),
42 title: self.title.unwrap_or(""),
43 style: self.style.unwrap_or(DialogStyle::Info),
44 buttons: self.buttons.unwrap_or(DialogButtons::Ok),
45 }
46 }
47}
48
49pub struct Dialog<'a> {
50 message: &'a str,
51 title: &'a str,
52 style: DialogStyle,
53 buttons: DialogButtons,
54}
55
56impl<'a> Dialog<'a> {
57 pub fn show(self) -> DialogSelection {
58 show_dialog(self.message, self.title, self.style, self.buttons)
59 }
60}