1 module app;
2 
3 import dlangui;
4 import rx;
5 import std.conv;
6 
7 //main of this sample
8 import event;
9 import model;
10 
11 mixin APP_ENTRY_POINT;
12 
13 /// entry point for dlangui based application
14 extern (C) int UIAppMain(string[] args)
15 {
16     auto window = createAppWindow();
17     auto appModel = new MyModel;
18 
19     auto counter = window.mainWidget.childById!EditLine("counter");
20 
21     appModel.counter.doSubscribe((int n) { counter.text = to!dstring(n); });
22     counter.text = to!dstring(appModel.count);
23 
24     Disposable[] events;
25     events ~= window.mainWidget.childById!Button("btnIncrement")
26         .click.asObservable().doSubscribe((Widget _) { appModel.increment(); });
27     events ~= window.mainWidget.childById!Button("btnDecrement")
28         .click.asObservable().doSubscribe((Widget _) { appModel.decrement(); });
29 
30     window.mainWidget.childById!Button("btnDetach").click = (Widget _) {
31         foreach (e; events)
32             e.dispose();
33         return true;
34     };
35 
36     // close window on Close button click
37     window.mainWidget.childById!Button("btnClose").click = delegate(Widget _) {
38         window.close();
39         return true;
40     };
41 
42     // show window
43     window.show();
44 
45     // run message loop
46     return Platform.instance.enterMessageLoop();
47 }
48 
49 Window createAppWindow()
50 {
51     // create window
52     Log.d("Creating window");
53     if (!Platform.instance)
54     {
55         Log.e("Platform.instance is null!!!");
56     }
57 
58     auto window = Platform.instance.createWindow("DlangUI with Rx", null);
59     Log.d("Window created");
60 
61     // create some widget to show in window
62     window.mainWidget = parseML(q{
63         VerticalLayout {
64             padding: 10
65             layoutWidth: fill
66             backgroundColor: "#C0E0E070" // semitransparent yellow background
67 
68             // red bold text with size = 150% of base style size and font face Arial
69             TextWidget { text: "The example for Rx on DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "'Yu Gothic',Arial" }
70 
71             // arrange some checkboxes horizontally
72             HorizontalLayout {
73                 layoutWidth: fill
74 
75 	            TextWidget { text: "Counter" }
76 	            EditLine { id: counter; text: "some text"; layoutWidth: fill }
77 
78 				Button { id: btnIncrement; text: "+1" }
79 				Button { id: btnDecrement; text: "-1" }
80             }
81 
82 			Button { id: btnDetach; text: "Detach" }
83 
84 			Button { id: btnClose; text: "Close" }
85         }
86     });
87 
88     return window;
89 }