-
Notifications
You must be signed in to change notification settings - Fork 337
/
Domkit.hx
125 lines (99 loc) · 2.65 KB
/
Domkit.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@:uiComp("view")
// Naming scheme of component classes can be customized with domkit.Macros.registerComponentsPath();
class ViewComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC =
<view class="mybox" min-width="200" content-halign={align}>
<text text={"Hello World"}/>
for( i in icons )
<bitmap src={i} id="icons[]"/>
</view>;
public function new(align:h2d.Flow.FlowAlign,icons:Array<h2d.Tile>,?parent) {
super(parent);
initComponent();
}
}
@:uiComp("button")
class ButtonComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <button>
<text public id="labelTxt" />
</button>
public var label(get, set): String;
function get_label() return labelTxt.text;
function set_label(s) {
labelTxt.text = s;
return s;
}
public function new( ?parent ) {
super(parent);
initComponent();
enableInteractive = true;
interactive.onClick = function(_) onClick();
interactive.onOver = function(_) {
dom.hover = true;
};
interactive.onPush = function(_) {
dom.active = true;
};
interactive.onRelease = function(_) {
dom.active = false;
};
interactive.onOut = function(_) {
dom.hover = false;
};
}
public dynamic function onClick() {
}
}
@:uiComp("container")
class ContainerComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <container>
<view(align,[]) id="view"/>
<button public id="btn"/>
<button public id="btn1"/>
<button public id="btn2"/>
</container>;
public function new(align:h2d.Flow.FlowAlign, ?parent) {
super(parent);
initComponent();
}
}
//PARAM=-lib domkit
class Domkit extends hxd.App {
var center : h2d.Flow;
var style = null;
override function init() {
center = new h2d.Flow(s2d);
center.horizontalAlign = center.verticalAlign = Middle;
onResize();
var root = new ContainerComp(Right, center);
// Override
root.btn.label = "Button";
root.btn1.label = "Highlight ON";
root.btn2.labelTxt.text = "Highlight OFF";
root.btn1.onClick = function() {
root.btn.dom.addClass("highlight");
}
root.btn2.onClick = function() {
root.btn.dom.removeClass("highlight");
}
style = new h2d.domkit.Style();
style.load(hxd.Res.style);
style.addObject(root);
}
override function onResize() {
center.minWidth = center.maxWidth = s2d.width;
center.minHeight = center.maxHeight = s2d.height;
}
override function update(dt:Float) {
style.sync();
}
static function main() {
#if hl
hxd.res.Resource.LIVE_UPDATE = true;
hxd.Res.initLocal();
#else
hxd.Res.initEmbed();
#end
new Domkit();
}
}