Haxe wrapper for the libYUI library
修訂 | 47986f81997fea2a2dba2f9805a3bab5dcbb5a29 (tree) |
---|---|
時間 | 2022-03-16 06:24:01 |
作者 | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Reorganize the demo code
@@ -3,30 +3,51 @@ | ||
3 | 3 | // SPDX-License-Identifier: Unlicense |
4 | 4 | |
5 | 5 | import yui.YUI; |
6 | -import yui.YWidget; | |
6 | +import yui.YDialog; | |
7 | +import yui.YPushButton; | |
7 | 8 | |
8 | 9 | using cpp.Pointer; |
10 | +using yui.hxHelpers.YWidgetHelper; | |
9 | 11 | |
10 | 12 | class Demo { |
11 | 13 | public static function main() { |
14 | + var mainWindow = new MainWindow(); | |
15 | + mainWindow.show(); | |
16 | + } | |
17 | +} | |
18 | + | |
19 | +class MainWindow { | |
20 | + var dialog : Pointer<YDialog>; | |
21 | + var okButton : Pointer<YPushButton>; | |
22 | + var closeButton : Pointer<YPushButton>; | |
23 | + | |
24 | + public function new() { | |
25 | + | |
26 | + } | |
27 | + | |
28 | + public function show() { | |
12 | 29 | var factory = YUI.widgetFactory().fromRaw().ref; |
13 | - var dialog = factory.createPopupDialog().fromRaw().ref; | |
30 | + this.dialog = factory.createPopupDialog().fromRaw(); | |
14 | 31 | var vbox = factory.createVBox(dialog); |
15 | 32 | factory.createLabel(vbox, "Hello, world"); |
16 | 33 | |
17 | - var okButton : cpp.Pointer<YWidget> = cast factory.createPushButton(vbox, "&OK"); | |
18 | - var closeButton : cpp.Pointer<YWidget> = cast factory.createPushButton(vbox, "&Close"); | |
34 | + this.okButton = factory.createPushButton(vbox, "&OK").fromRaw(); | |
35 | + this.closeButton = factory.createPushButton(vbox, "&Close").fromRaw(); | |
19 | 36 | |
37 | + this.eventLoop(); | |
38 | + } | |
39 | + | |
40 | + function eventLoop() { | |
20 | 41 | while (true) { |
21 | - var eventPointer = dialog.waitForEvent(); | |
42 | + var eventPointer = dialog.ref.waitForEvent(); | |
22 | 43 | if (eventPointer == null) { |
23 | 44 | continue; |
24 | 45 | } |
25 | 46 | var event = eventPointer.fromRaw().ref; |
26 | 47 | var eventType = event.eventType(); |
27 | 48 | trace('Event received ${eventType}'); |
28 | - var wid : cpp.Pointer<YWidget> = cpp.Pointer.fromRaw(event.widget()); | |
29 | - if (wid == closeButton) { | |
49 | + var wid = cpp.Pointer.fromRaw(event.widget()); | |
50 | + if (wid.ref.equals(closeButton.ref)) { | |
30 | 51 | trace("Close button pressed, exiting"); |
31 | 52 | break; |
32 | 53 | } |
@@ -38,6 +59,7 @@ | ||
38 | 59 | trace('Other event'); |
39 | 60 | } |
40 | 61 | } |
41 | - dialog.destroy(); | |
62 | + | |
63 | + this.dialog.ref.destroy(); | |
42 | 64 | } |
43 | 65 | } |
\ No newline at end of file |