• R/O
  • SSH

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisãoa1799f773946097545bdc7374519e226f5236952 (tree)
Hora2022-04-05 04:52:32
AutorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...>
CommiterJaime Marquínez Ferrándiz

Mensagem de Log

Use creators defined in nativexml

Mudança Sumário

Diff

diff -r 3641ad9bc7b6 -r a1799f773946 demo.hxml
--- a/demo.hxml Wed Mar 30 23:49:22 2022 +0200
+++ b/demo.hxml Mon Apr 04 21:52:32 2022 +0200
@@ -11,6 +11,7 @@
1111 --library haxeui-core
1212 --library haxe-YUI
1313
14+--dce full
1415 --cpp bin
1516
1617 --macro haxe.macro.Compiler.include("haxe.ui", ["haxe.ui.macros"])
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/ComponentImpl.hx
--- a/src/haxe/ui/backend/ComponentImpl.hx Wed Mar 30 23:49:22 2022 +0200
+++ b/src/haxe/ui/backend/ComponentImpl.hx Mon Apr 04 21:52:32 2022 +0200
@@ -4,21 +4,11 @@
44
55 package haxe.ui.backend;
66
7-import haxe.ui.backend.yui.DialogWrapper;
7+import haxe.ui.backend.yui.creators.Creator;
88 import haxe.ui.backend.yui.WidgetWrapper;
9-import haxe.ui.components.Button;
10-import haxe.ui.components.Label;
11-import haxe.ui.containers.HBox;
12-import haxe.ui.containers.VBox;
13-import haxe.ui.core.TextInput;
149 import haxe.ui.core.Component;
15-import haxe.ui.events.UIEvent;
1610 import haxe.ui.events.MouseEvent;
17-import yui.hxHelpers.AutoRawPointer;
1811 import yui.YEvent;
19-import yui.YUI;
20-import yui.YWidget;
21-import yui.YWidgetFactory;
2212
2313 using cpp.Pointer;
2414 using yui.hxHelpers.YWidgetHelper;
@@ -49,34 +39,38 @@
4939 parent = Toolkit.screen.mainWindow;
5040 }
5141
52- var factory = YUI.widgetFactory().fromRaw().ref;
53- var rPointer : AutoRawPointer<YWidget> = null;
54- // TODO: use creators defined at native.xml
55- if (this is VBox) {
56- rPointer = factory.createVBox(parent.widget);
57- }
58- else if (this is HBox) {
59- rPointer = factory.createHBox(parent.widget);
42+ var creatorClass:String = this.getCreator();
43+ if (creatorClass != null) {
44+ var creator : Creator = Type.createInstance(Type.resolveClass(creatorClass), [this]);
45+ this.wrapper = creator.createWrapper(parent);
6046 }
61- else if (this is Button) {
62- var b = cast(this, Button);
63- rPointer = factory.createPushButton(parent.widget, b.text);
64- }
65- else if (this is Label) {
66- var l = cast(this, Label);
67- rPointer = factory.createLabel(parent.widget, l.text);
68- }
69-
70- if (rPointer != null) {
71- var pointer : cpp.RawPointer<YWidget> = rPointer;
72- this.wrapper = new WidgetWrapper(pointer.fromRaw());
73- } else {
74- trace('pointer not created');
47+ else {
48+ trace('There is not a creator for ${className}');
7549 }
7650
7751 parent.children.push(cast(this, Component));
7852 }
7953
54+ private function getCreator() {
55+ var valueType = Type.typeof(this);
56+ switch (valueType) {
57+ case TClass(cls):
58+ return this.getCreatorClassname(cls);
59+ default:
60+ return null;
61+ }
62+ }
63+
64+ private function getCreatorClassname(cls : Class<Dynamic>) {
65+ var clsName = Type.getClassName(cls);
66+ var creatorClass = Toolkit.nativeConfig.query('component[id=${clsName}].@creator', null, this);
67+ if (creatorClass != null) {
68+ return creatorClass;
69+ } else {
70+ return this.getCreatorClassname(Type.getSuperClass(cls));
71+ }
72+ }
73+
8074 public function handleYEvent(eventPointer : Pointer<YEvent>) : Bool {
8175 var event = eventPointer.ref;
8276 var widgetPointer = event.widget();
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/native.xml
--- a/src/haxe/ui/backend/native.xml Wed Mar 30 23:49:22 2022 +0200
+++ b/src/haxe/ui/backend/native.xml Mon Apr 04 21:52:32 2022 +0200
@@ -5,8 +5,12 @@
55 -->
66 <?xml version="1.0" encoding="utf-8" ?>
77 <native>
8- <component id="haxe.ui.components.Button" allowChildren="false">
8+ <component id="haxe.ui.components.Button" allowChildren="false" creator="haxe.ui.backend.yui.creators.ButtonCreator">
99 <behaviour id="text" class="haxe.ui.backend.yui.behaviours.WidgetLabel" />
1010 <behaviour id="value" class="haxe.ui.backend.yui.behaviours.WidgetLabel" />
1111 </component>
12+ <component id="haxe.ui.components.Label" allowChildren="false" creator="haxe.ui.backend.yui.creators.LabelCreator" />
13+
14+ <component id="haxe.ui.containers.HBox" allowChildren="true" creator="haxe.ui.backend.yui.creators.HBoxCreator" />
15+ <component id="haxe.ui.containers.VBox" allowChildren="true" creator="haxe.ui.backend.yui.creators.VBoxCreator" />
1216 </native>
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/WidgetWrapper.hx
--- a/src/haxe/ui/backend/yui/WidgetWrapper.hx Wed Mar 30 23:49:22 2022 +0200
+++ b/src/haxe/ui/backend/yui/WidgetWrapper.hx Mon Apr 04 21:52:32 2022 +0200
@@ -10,7 +10,6 @@
1010 import yui.YWidget;
1111
1212 using cpp.Pointer;
13-using cpp.RawPointer;
1413
1514 /**
1615 * Wrapper for `YWidget`.
@@ -21,6 +20,12 @@
2120 this.widget = w;
2221 this.children = [];
2322 }
23+
24+ public static inline function fromPointer<TWidget:YWidget>(widgetPointer : cpp.Pointer<TWidget>) {
25+ var ref : cpp.Reference<YWidget> = widgetPointer.ref;
26+ return new WidgetWrapper(ref.addressOf());
27+ }
28+
2429 public var widget : cpp.Pointer<YWidget>;
2530
2631 public var children : Array<Component>;
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/behaviours/WidgetLabel.hx
--- a/src/haxe/ui/backend/yui/behaviours/WidgetLabel.hx Wed Mar 30 23:49:22 2022 +0200
+++ b/src/haxe/ui/backend/yui/behaviours/WidgetLabel.hx Mon Apr 04 21:52:32 2022 +0200
@@ -9,6 +9,7 @@
99 import yui.YProperty;
1010 import yui.YPropertyValue;
1111
12+@:keep
1213 class WidgetLabel extends DataBehaviour {
1314 static final LABEL_PROPERTY = "Label";
1415
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/creators/ButtonCreator.hx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/haxe/ui/backend/yui/creators/ButtonCreator.hx Mon Apr 04 21:52:32 2022 +0200
@@ -0,0 +1,21 @@
1+// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net>
2+//
3+// SPDX-License-Identifier: Unlicense
4+
5+package haxe.ui.backend.yui.creators;
6+
7+import yui.YWidget;
8+
9+@:keep
10+class ButtonCreator extends Creator {
11+ private var _button : haxe.ui.components.Button;
12+ function new(button : haxe.ui.components.Button) {
13+ super(button);
14+ this._button = button;
15+ }
16+
17+ function createWidget(parentWidget : cpp.Pointer<YWidget>) : cpp.Pointer<YWidget> {
18+ var p = this.factory.ref.createPushButton(parentWidget, this._button.text);
19+ return this.convertPointer(p);
20+ }
21+}
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/creators/Creator.hx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/haxe/ui/backend/yui/creators/Creator.hx Mon Apr 04 21:52:32 2022 +0200
@@ -0,0 +1,41 @@
1+// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net>
2+//
3+// SPDX-License-Identifier: Unlicense
4+
5+package haxe.ui.backend.yui.creators;
6+
7+import haxe.ui.core.Component;
8+import yui.YUI;
9+import yui.YWidget;
10+import yui.YWidgetFactory;
11+
12+using cpp.Pointer;
13+
14+abstract class Creator {
15+ private var component : Component;
16+
17+ public function new(comp : Component) {
18+ this.component = comp;
19+ }
20+
21+ private var factory (get, never) : cpp.Pointer<YWidgetFactory>;
22+ function get_factory() {
23+ return YUI.widgetFactory().fromRaw();
24+ }
25+
26+ /**
27+ * Create the widget associated to the component
28+ * @return The widget
29+ */
30+ private abstract function createWidget(parentWidget : cpp.Pointer<YWidget>) : cpp.Pointer<YWidget>;
31+
32+ private inline function convertPointer<T:YWidget>(p : cpp.RawPointer<T>) {
33+ var r : cpp.RawPointer<YWidget> = cast p;
34+ return r.fromRaw();
35+ }
36+
37+ public function createWrapper(parent : WidgetWrapper) : WidgetWrapper {
38+ var widget = this.createWidget(parent.widget);
39+ return WidgetWrapper.fromPointer(widget);
40+ }
41+}
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/creators/HBoxCreator.hx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/haxe/ui/backend/yui/creators/HBoxCreator.hx Mon Apr 04 21:52:32 2022 +0200
@@ -0,0 +1,21 @@
1+// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net>
2+//
3+// SPDX-License-Identifier: Unlicense
4+
5+package haxe.ui.backend.yui.creators;
6+
7+import yui.YWidget;
8+
9+@:keep
10+class HBoxCreator extends Creator {
11+ private var _hbox : haxe.ui.containers.HBox;
12+ function new(hbox : haxe.ui.containers.HBox) {
13+ super(hbox);
14+ this._hbox = hbox;
15+ }
16+
17+ function createWidget(parentWidget : cpp.Pointer<YWidget>) : cpp.Pointer<YWidget> {
18+ var p = factory.ref.createHBox(parentWidget);
19+ return this.convertPointer(p);
20+ }
21+}
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/creators/LabelCreator.hx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/haxe/ui/backend/yui/creators/LabelCreator.hx Mon Apr 04 21:52:32 2022 +0200
@@ -0,0 +1,21 @@
1+// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net>
2+//
3+// SPDX-License-Identifier: Unlicense
4+
5+package haxe.ui.backend.yui.creators;
6+
7+import yui.YWidget;
8+
9+@:keep
10+class LabelCreator extends Creator {
11+ private var _label : haxe.ui.components.Label;
12+ function new(label : haxe.ui.components.Label) {
13+ super(label);
14+ this._label = label;
15+ }
16+
17+ function createWidget(parentWidget : cpp.Pointer<YWidget>) : cpp.Pointer<YWidget> {
18+ var p = this.factory.ref.createLabel(parentWidget, this._label.text);
19+ return this.convertPointer(p);
20+ }
21+}
\ No newline at end of file
diff -r 3641ad9bc7b6 -r a1799f773946 src/haxe/ui/backend/yui/creators/VBoxCreator.hx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/haxe/ui/backend/yui/creators/VBoxCreator.hx Mon Apr 04 21:52:32 2022 +0200
@@ -0,0 +1,21 @@
1+// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net>
2+//
3+// SPDX-License-Identifier: Unlicense
4+
5+package haxe.ui.backend.yui.creators;
6+
7+import yui.YWidget;
8+
9+@:keep
10+class VBoxCreator extends Creator {
11+ private var _vbox : haxe.ui.containers.VBox;
12+ function new(vbox : haxe.ui.containers.VBox) {
13+ super(vbox);
14+ this._vbox = vbox;
15+ }
16+
17+ function createWidget(parentWidget : cpp.Pointer<YWidget>) : cpp.Pointer<YWidget> {
18+ var p = factory.ref.createVBox(parentWidget);
19+ return this.convertPointer(p);
20+ }
21+}
\ No newline at end of file