Haxe wrapper for the libYUI library
Revision | f2c90333307628861f4deafb3075e48755c51c09 (tree) |
---|---|
Zeit | 2022-03-23 06:41:06 |
Autor | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Implement properties
@@ -53,6 +53,7 @@ | ||
53 | 53 | var eventType = event.eventType(); |
54 | 54 | trace('Event received ${eventType}'); |
55 | 55 | var wid = cpp.Pointer.fromRaw(event.widget()); |
56 | + wid.ref.printDebugWidget(); | |
56 | 57 | if (wid.ref.equals(closeButton.ref)) { |
57 | 58 | trace("Close button pressed, exiting"); |
58 | 59 | break; |
@@ -0,0 +1,29 @@ | ||
1 | +// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net> | |
2 | +// | |
3 | +// SPDX-License-Identifier: Unlicense | |
4 | + | |
5 | +package yui; | |
6 | + | |
7 | +import yui.hxHelpers.AutoStdString; | |
8 | + | |
9 | +@:include("yui/YProperty.h") | |
10 | +@:native("YProperty") | |
11 | +@:structAccess | |
12 | +extern class YProperty { | |
13 | + function new(name : AutoStdString, type : YPropertyType, isReadOnly : Bool = false ); | |
14 | + function isReadOnly() : Bool; | |
15 | + function name() : AutoStdString; | |
16 | + function type() : YPropertyType; | |
17 | + static function typeAsStr(type : YProperty) : AutoStdString; | |
18 | + function typeAsStr() : AutoStdString; | |
19 | +} | |
20 | + | |
21 | +@:include("yui/YProperty.h") | |
22 | +@:native("YPropertyType") | |
23 | +extern enum abstract YPropertyType(Int) { | |
24 | + var YUnknownPropertyType; | |
25 | + var YOtherProperty; | |
26 | + var YStringProperty; | |
27 | + var YBoolProperty; | |
28 | + var YIntegerProperty; | |
29 | +} | |
\ No newline at end of file |
@@ -0,0 +1,67 @@ | ||
1 | +// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net> | |
2 | +// | |
3 | +// SPDX-License-Identifier: Unlicense | |
4 | + | |
5 | +package yui; | |
6 | + | |
7 | +import yui.hxHelpers.AutoStdString; | |
8 | +import cpp.Native; | |
9 | + | |
10 | +using cpp.Pointer; | |
11 | + | |
12 | +@:include("yui/YProperty.h") | |
13 | +@:native("YPropertySet") | |
14 | +@:structAccess | |
15 | +extern class YPropertySet { | |
16 | + function size() : Int; | |
17 | + function isEmpty() : Bool; | |
18 | + overload function contains(propertyName : AutoStdString) : Bool; | |
19 | + overload function contains(propertyName : AutoStdString, type : YProperty) : Bool; | |
20 | + overload function contains(propertyName : cpp.Reference<YProperty>) : Bool; | |
21 | + | |
22 | + overload function add(prop : cpp.Reference<YProperty>) : Void; | |
23 | + overload function add(otherSet : cpp.Reference<YPropertySet>) : Void; | |
24 | + | |
25 | + function propertiesBegin() : YPropertySetConstIterator; | |
26 | + function propertiesEnd() : YPropertySetConstIterator; | |
27 | + | |
28 | + inline public function iterator() : YPropertySetIterator { | |
29 | + return new YPropertySetIterator(this.addressOf()); | |
30 | + } | |
31 | +} | |
32 | + | |
33 | +@:native("std::vector<YProperty>::const_iterator") | |
34 | +extern class YPropertySetConstIterator { | |
35 | + inline function item() : YProperty { | |
36 | + return untyped Native.star(this); | |
37 | + } | |
38 | + | |
39 | + inline function ref() : cpp.Pointer<YProperty> { | |
40 | + var p : YProperty = this.item(); | |
41 | + return Pointer.addressOf(cast p); | |
42 | + } | |
43 | +} | |
44 | + | |
45 | +@:unreflective | |
46 | +class YPropertySetIterator { | |
47 | + var propertySet : cpp.Pointer<YPropertySet>; | |
48 | + var iter : YPropertySetConstIterator; | |
49 | + var i : Int; | |
50 | + | |
51 | + public function new(set : cpp.Pointer<YPropertySet>) { | |
52 | + this.propertySet = set; | |
53 | + this.iter = untyped set.ref.propertiesBegin(); | |
54 | + this.i = 0; | |
55 | + } | |
56 | + | |
57 | + public function hasNext() { | |
58 | + return i < this.propertySet.ref.size(); | |
59 | + } | |
60 | + | |
61 | + public function next() { | |
62 | + var item = this.iter.item(); | |
63 | + untyped this.iter++; | |
64 | + this.i++; | |
65 | + return item; | |
66 | + } | |
67 | +} | |
\ No newline at end of file |
@@ -0,0 +1,27 @@ | ||
1 | +// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net> | |
2 | +// | |
3 | +// SPDX-License-Identifier: Unlicense | |
4 | + | |
5 | +package yui; | |
6 | + | |
7 | +import yui.YProperty.YPropertyType; | |
8 | +import yui.hxHelpers.AutoStdString; | |
9 | + | |
10 | +@:include("yui/YProperty.h") | |
11 | +@:native("YPropertyValue") | |
12 | +@:structAccess | |
13 | +extern class YPropertyValue { | |
14 | + @:native("YPropertyValue") | |
15 | + overload static function create(str : AutoStdString) : YPropertyValue; | |
16 | + @:native("YPropertyValue") | |
17 | + overload static function create(b : Bool) : YPropertyValue; | |
18 | + @:native("YPropertyValue") | |
19 | + overload static function create(num : Int) : YPropertyValue; | |
20 | + @:native("YPropertyValue") | |
21 | + overload static function create(type : YPropertyType) : YPropertyValue; | |
22 | + | |
23 | + function stringVal() : AutoStdString; | |
24 | + function type() : YPropertyType; | |
25 | + function boolVal() : Bool; | |
26 | + function integerVal() : Int; | |
27 | +} | |
\ No newline at end of file |
@@ -10,6 +10,14 @@ | ||
10 | 10 | @:native("YWidget") |
11 | 11 | @:structAccess |
12 | 12 | @:unreflective |
13 | +@:using(yui.hxHelpers.YWidgetExtensions) | |
13 | 14 | extern class YWidget { |
14 | 15 | function debugLabel() : AutoStdString; |
16 | + function widgetClass() : AutoStdString; | |
17 | + inline public function widgetClassTyped() : yui.hxHelpers.WidgetClassName { | |
18 | + return cast this.widgetClass(); | |
19 | + } | |
20 | + function propertySet() : YPropertySet; | |
21 | + function getProperty(propertyName : AutoStdString) : YPropertyValue; | |
22 | + function setProperty(propertyName : AutoStdString, val : cpp.Reference<YPropertyValue>) : Bool; | |
15 | 23 | } |
\ No newline at end of file |
@@ -0,0 +1,9 @@ | ||
1 | +// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net> | |
2 | +// | |
3 | +// SPDX-License-Identifier: Unlicense | |
4 | + | |
5 | +package yui.hxHelpers; | |
6 | + | |
7 | +enum abstract WidgetClassName(String) { | |
8 | + var YPushButton = "YPushButton"; | |
9 | +} | |
\ No newline at end of file |
@@ -0,0 +1,37 @@ | ||
1 | +// SPDX-FileCopyrightText: 2022 Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fastmail.net> | |
2 | +// | |
3 | +// SPDX-License-Identifier: Unlicense | |
4 | + | |
5 | +package yui.hxHelpers; | |
6 | + | |
7 | +@:unreflective | |
8 | +class YWidgetExtensions { | |
9 | + public static function printDebugWidget(wid : cpp.Reference<YWidget>) { | |
10 | + var className = wid.widgetClass(); | |
11 | + var label = wid.debugLabel(); | |
12 | + trace('Widget of type ${className} with label ${label}'); | |
13 | + var properties = wid.propertySet(); | |
14 | + for (prop in properties) { | |
15 | + trace('Property ${prop.name()} of type ${prop.typeAsStr()}'); | |
16 | + var value = wid.getProperty(prop.name()); | |
17 | + printDebugPropertyValue(value); | |
18 | + wid.setProperty(prop.name(), value); | |
19 | + } | |
20 | + } | |
21 | + | |
22 | + private static function printDebugPropertyValue(value : YPropertyValue) { | |
23 | + trace('Value of type ${value.type()}'); | |
24 | + switch (value.type()) { | |
25 | + case YBoolProperty: | |
26 | + trace('Booleano ${value.boolVal()}'); | |
27 | + case YIntegerProperty: | |
28 | + var v = value.integerVal(); | |
29 | + trace('Integer ${v}'); | |
30 | + case YStringProperty: | |
31 | + trace('String ${value.stringVal()}'); | |
32 | + case YOtherProperty: | |
33 | + case YUnknownPropertyType: | |
34 | + trace('Other type'); | |
35 | + } | |
36 | + } | |
37 | +} | |
\ No newline at end of file |