1 module w95.dialog_window;
2 
3 import fluid;
4 
5 import w95.window;
6 import w95.titlebar;
7 import w95.dialog_button;
8 
9 @safe:
10 
11 alias dialogWindow = simpleConstructor!DialogWindow;
12 
13 /// Create an info dialog.
14 ///
15 /// ---
16 /// dialogWindow.info("Text")
17 /// ---
18 DialogWindow info(Ts...)(typeof(dialogWindow), Ts params, string message) {
19 
20     DialogWindow window;
21 
22     return window = dialogWindow(
23         params,
24         titlebar("Info"),
25         imageView("resources/dialog-icons/info.private.png"),
26         label(message),
27         dialogButton("OK", delegate {
28             window.close();
29         }),
30     );
31     
32 }
33 
34 /// Create an error dialog.
35 ///
36 /// ---
37 /// dialogWindow.error("Text")
38 /// ---
39 DialogWindow error(Ts...)(typeof(dialogWindow), Ts params, string message) {
40 
41     DialogWindow window;
42 
43     return window = dialogWindow(
44         params,
45         titlebar("Error"),
46         imageView("resources/dialog-icons/cross2.private.png"),
47         label(message),
48         dialogButton("OK", delegate {
49             window.close();
50         }),
51     );
52     
53 }
54 
55 class DialogWindow : Window95 {
56 
57     this(Titlebar titlebar, ImageView icon, Node content, DialogButton[] buttons...) {
58 
59         if (buttons != []) {
60 
61             super(
62                 titlebar, 
63                 hspace(
64                     icon,
65                     vspace(
66                         content,
67                         hspace(
68                             .layout!"end",
69                             buttons,
70                         ),
71                     ),
72                 )
73             );
74 
75         }
76 
77         else {
78 
79             super(
80                 titlebar,
81                 hspace(
82                     icon,
83                     content,
84                 ),
85             );
86 
87         }
88 
89     }
90 
91 }