1 // Copyright (c) 2017 Matthew Brennan Jones <matthew.brennan.jones@gmail.com>
2 // Boost Software License - Version 1.0
3 // A simple message box for the D programming language
4 // https://github.com/workhorsy/d-message-box
5 
6 
7 module message_box_dlangui;
8 
9 import message_box : MessageBoxBase, IconType, is_sdl2_loadable;
10 
11 
12 class MessageBoxDlangUI : MessageBoxBase {
13 	import dlangui;
14 
15 	this(string title, string message, IconType icon_type) {
16 		super(title, message, icon_type);
17 	}
18 
19 	override void show() {
20 		import std.conv : to;
21 		import core.thread : Thread;
22 
23 		// create window
24 		auto flags = WindowFlag.Modal;
25 		auto window = Platform.instance.createWindow(_title.to!dstring, null, flags, 300, 150);
26 
27 		// Create the layout
28 		auto vlayout = new VerticalLayout();
29 		vlayout.margins = 20;
30 		vlayout.padding = 10;
31 
32 		// FIXME: Figure out how to add information, error, and warning icons
33 		// Add an icon
34 		const Action action = ACTION_ABORT;
35 		string drawableId = action.iconId;
36 		auto icon = new ImageWidget("icon", drawableId);
37 
38 		// Add the text
39 		auto text = new MultilineTextWidget(null, _message.to!dstring);
40 
41 		// Add the button
42 		auto button = new Button();
43 		button.text = "Okay";
44 		button.click = delegate(Widget w) {
45 			window.close();
46 			return true;
47 		};
48 
49 		// Add the controls to the window
50 		vlayout.addChild(icon);
51 		vlayout.addChild(text);
52 		vlayout.addChild(button);
53 		window.mainWidget = vlayout;
54 
55 		// show window
56 		window.show();
57 
58 		Platform.instance.enterMessageLoop();
59 	}
60 
61 	static bool isSupported() {
62 		version (Windows) {
63 			return true;
64 		} else version (Have_derelict_sdl2) {
65 			return is_sdl2_loadable;
66 		} else {
67 			return false;
68 		}
69 	}
70 }
71