Revisão | 49243744bee211cd36fd6907013714e4fe9e5cd1 (tree) |
---|---|
Hora | 2022-07-16 05:44:15 |
Autor | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Allow opening dialogs
@@ -0,0 +1,6 @@ | ||
1 | +<dialog> | |
2 | + <vbox> | |
3 | + <label text="Custom dialog" /> | |
4 | + <button text="Close" id="btnClose"/> | |
5 | + </vbox> | |
6 | +</dialog> | |
\ No newline at end of file |
@@ -19,5 +19,7 @@ | ||
19 | 19 | <button text="Y" /> |
20 | 20 | </hbox> |
21 | 21 | </vbox> |
22 | + | |
23 | + <button text="Open custom dialog" id="btnDialog" /> | |
22 | 24 | </hbox> |
23 | 25 | </vbox> |
\ No newline at end of file |
@@ -2,6 +2,9 @@ | ||
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Unlicense |
4 | 4 | |
5 | + | |
6 | +--library haxeui-core | |
7 | +--library haxe-koreader | |
5 | 8 | --class-path src |
6 | 9 | |
7 | 10 | --macro include("haxe.ui.backend.koreader") |
@@ -11,9 +14,6 @@ | ||
11 | 14 | --class-path demo |
12 | 15 | --main Main |
13 | 16 | |
14 | ---library haxeui-core | |
15 | ---library haxe-koreader | |
16 | - | |
17 | 17 | --dce full |
18 | 18 | |
19 | 19 | --lua out/haxeui_demo.lua |
@@ -0,0 +1,14 @@ | ||
1 | +import haxe.ui.events.MouseEvent; | |
2 | +import haxe.ui.containers.dialogs.Dialog; | |
3 | + | |
4 | +@:build(haxe.ui.ComponentBuilder.build("assets/custom-dialog.xml")) | |
5 | +class CustomDialog extends Dialog { | |
6 | + public function new() { | |
7 | + super(); | |
8 | + } | |
9 | + | |
10 | + @:bind(btnClose, MouseEvent.CLICK) | |
11 | + private function onOpenDialog(e:MouseEvent) { | |
12 | + this.hide(); | |
13 | + } | |
14 | +} | |
\ No newline at end of file |
@@ -21,4 +21,10 @@ | ||
21 | 21 | private function onMyButton(e:MouseEvent) { |
22 | 22 | btn2.text = "Clicked!"; |
23 | 23 | } |
24 | + | |
25 | + @:bind(btnDialog, MouseEvent.CLICK) | |
26 | + private function onOpenDialog(e:MouseEvent) { | |
27 | + var dialog = new CustomDialog(); | |
28 | + dialog.showDialog(); | |
29 | + } | |
24 | 30 | } |
\ No newline at end of file |
@@ -6,6 +6,7 @@ | ||
6 | 6 | |
7 | 7 | import haxe.ui.backend.koreader.creators.Creator; |
8 | 8 | import haxe.ui.backend.koreader.WidgetWrapper; |
9 | +import haxe.ui.backend.koreader.DialogWrapper; | |
9 | 10 | import haxe.ui.components.Button; |
10 | 11 | import haxe.ui.components.Label; |
11 | 12 | import haxe.ui.containers.HBox; |
@@ -43,7 +44,7 @@ | ||
43 | 44 | parent = Toolkit.screen.mainContainer; |
44 | 45 | } |
45 | 46 | |
46 | - var creatorClass:String = Toolkit.nativeConfig.query('component[id=${className}].@creator', null, this); | |
47 | + var creatorClass:String = this.getCreator(); | |
47 | 48 | if (creatorClass != null) { |
48 | 49 | var creator : Creator = Type.createInstance(Type.resolveClass(creatorClass), [this]); |
49 | 50 | this.wrapper = creator.createWrapper(parent); |
@@ -54,4 +55,42 @@ | ||
54 | 55 | |
55 | 56 | parent.children.push(cast(this, Component)); |
56 | 57 | } |
58 | + | |
59 | + private function getCreator() { | |
60 | + var valueType = Type.typeof(this); | |
61 | + switch (valueType) { | |
62 | + case TClass(cls): | |
63 | + return this.getCreatorClassname(cls); | |
64 | + default: | |
65 | + return null; | |
66 | + } | |
67 | + } | |
68 | + | |
69 | + private function getCreatorClassname(cls : Class<Dynamic>) { | |
70 | + if (cls == null) { | |
71 | + trace('the class for the component ${className} is null'); | |
72 | + return null; | |
73 | + } | |
74 | + var clsName = Type.getClassName(cls); | |
75 | + trace(clsName); | |
76 | + var creatorClass = Toolkit.nativeConfig.query('component[id=${clsName}].@creator', null, this); | |
77 | + if (creatorClass != null) { | |
78 | + return creatorClass; | |
79 | + } else { | |
80 | + return this.getCreatorClassname(Type.getSuperClass(cls)); | |
81 | + } | |
82 | + } | |
83 | + | |
84 | + override function handleVisibility(show:Bool) { | |
85 | + if (this.wrapper is DialogWrapper) { | |
86 | + var dlgWrapper = cast(this.wrapper, DialogWrapper); | |
87 | + if (show) { | |
88 | + UIManager.show(dlgWrapper.dialog); | |
89 | + UIManager.setDirty(dlgWrapper.dialog, Partial); | |
90 | + } else { | |
91 | + UIManager.close(dlgWrapper.dialog); | |
92 | + UIManager.setDirty(dlgWrapper.dialog, Partial); | |
93 | + } | |
94 | + } | |
95 | + } | |
57 | 96 | } |
\ No newline at end of file |
@@ -0,0 +1,40 @@ | ||
1 | +package haxe.ui.backend; | |
2 | + | |
3 | +import haxe.exceptions.NotImplementedException; | |
4 | +import haxe.ui.containers.Box; | |
5 | +import haxe.ui.containers.VBox; | |
6 | +import haxe.ui.containers.dialogs.Dialog.DialogButton; | |
7 | +import haxe.ui.core.Component; | |
8 | + | |
9 | +class DialogBase extends Component { | |
10 | + public var modal:Bool = true; | |
11 | + public var buttons:DialogButton = null; | |
12 | + public var centerDialog:Bool = true; | |
13 | + public var button:DialogButton = null; | |
14 | + | |
15 | + public var dialogContentContainer:VBox; | |
16 | + public var dialogContent:VBox; | |
17 | + public var customDialogFooterContainer:Box; | |
18 | + public var customDialogFooter:Box; | |
19 | + | |
20 | + public var title:String; | |
21 | + | |
22 | + public function new() { | |
23 | + super(); | |
24 | + this._hidden = true; | |
25 | + } | |
26 | + | |
27 | + public function showDialog(modal:Bool = true) { | |
28 | + this.modal = modal; | |
29 | + show(); | |
30 | + } | |
31 | + | |
32 | + override function show() { | |
33 | + this.ready(); | |
34 | + super.show(); | |
35 | + } | |
36 | + | |
37 | + private function createButtons() { | |
38 | + throw new NotImplementedException(); | |
39 | + } | |
40 | +} |
@@ -0,0 +1,12 @@ | ||
1 | +package haxe.ui.backend.koreader; | |
2 | + | |
3 | +import koreader.ui.widget.Widget; | |
4 | + | |
5 | +class DialogWrapper extends WidgetWrapper { | |
6 | + public var dialog : Widget; | |
7 | + | |
8 | + public function new(dialog : Widget, container : Widget) { | |
9 | + super(container); | |
10 | + this.dialog = dialog; | |
11 | + } | |
12 | +} | |
\ No newline at end of file |
@@ -0,0 +1,46 @@ | ||
1 | +package haxe.ui.backend.koreader.creators; | |
2 | + | |
3 | +import koreader.ui.widget.container.MovableContainer; | |
4 | +import koreader.Device; | |
5 | +import koreader.ui.widget.container.CenterContainer; | |
6 | +import koreader.ffi.Blitbuffer; | |
7 | +import koreader.ui.widget.VerticalGroup; | |
8 | +import koreader.ui.Size; | |
9 | +import koreader.ui.widget.container.FrameContainer; | |
10 | +import koreader.ui.widget.Widget; | |
11 | + | |
12 | +@:keep | |
13 | +class DialogCreator extends Creator { | |
14 | + private var _dialog : haxe.ui.containers.dialogs.Dialog; | |
15 | + | |
16 | + public function new(dialog : haxe.ui.containers.dialogs.Dialog) { | |
17 | + super(dialog); | |
18 | + this._dialog = dialog; | |
19 | + } | |
20 | + | |
21 | + function createWidget() : Widget { | |
22 | + throw new haxe.exceptions.NotImplementedException(); | |
23 | + } | |
24 | + | |
25 | + override function createWrapper(parent : WidgetWrapper) : WidgetWrapper { | |
26 | + var frame = FrameContainer.create({ | |
27 | + background: Blitbuffer.COLOR_GRAY, | |
28 | + bordersize: Size.border.window, | |
29 | + radius: Size.radius.window, | |
30 | + padding: Size.padding.default_, | |
31 | + }); | |
32 | + | |
33 | + var group = VerticalGroup.create({}); | |
34 | + frame.addWidget(group); | |
35 | + | |
36 | + var dialog = CenterContainer.create({ | |
37 | + dimen: Device.screen.getSize(), | |
38 | + widgets: [ | |
39 | + MovableContainer.create({ | |
40 | + widgets: [frame], | |
41 | + }), | |
42 | + ], | |
43 | + }); | |
44 | + return new DialogWrapper(dialog, group); | |
45 | + } | |
46 | +} | |
\ No newline at end of file |
@@ -12,4 +12,5 @@ | ||
12 | 12 | <component id="haxe.ui.components.Label" allowChildren="false" creator="haxe.ui.backend.koreader.creators.LabelCreator" /> |
13 | 13 | <component id="haxe.ui.containers.HBox" allowChildren="true" creator="haxe.ui.backend.koreader.creators.HBoxCreator" /> |
14 | 14 | <component id="haxe.ui.containers.VBox" allowChildren="true" creator="haxe.ui.backend.koreader.creators.VBoxCreator" /> |
15 | + <component id="haxe.ui.containers.dialogs.Dialog" allowChildren="true" creator="haxe.ui.backend.koreader.creators.DialogCreator" /> | |
15 | 16 | </native> |
\ No newline at end of file |