-
Notifications
You must be signed in to change notification settings - Fork 19
/
Label.hx
96 lines (69 loc) · 2.53 KB
/
Label.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
package mint.render.luxe;
import mint.types.Types;
import mint.render.Rendering;
import mint.render.luxe.LuxeMintRender;
import mint.render.luxe.Convert;
import luxe.Text;
import luxe.Color;
import luxe.Log.*;
private typedef LuxeMintLabelOptions = {
var color: Color;
var color_hover: Color;
}
class Label extends mint.render.Render {
public var label : mint.Label;
public var text : Text;
public var color_hover: Color;
public var color: Color;
var render: LuxeMintRender;
public function new( _render:LuxeMintRender, _control:mint.Label ) {
label = _control;
render = _render;
super(render, _control);
var _opt: LuxeMintLabelOptions = label.options.options;
color = def(_opt.color, new Color().rgb(0xffffff));
color_hover = def(_opt.color_hover, new Color().rgb(0x9dca63));
text = new luxe.Text({
name: control.name+'.text',
batcher: render.options.batcher,
bounds: new luxe.Rectangle(control.x, control.y, control.w, control.h),
color: color,
text: label.text,
bounds_wrap: label.options.bounds_wrap,
align: Convert.text_align(label.options.align),
align_vertical: Convert.text_align(label.options.align_vertical),
point_size: label.options.text_size,
depth: render.options.depth + control.depth,
group: render.options.group,
visible: control.visible,
});
text.clip_rect = Convert.bounds(control.clip_with);
label.onchange.listen(ontext);
control.onmouseenter.listen(function(e,c){ text.color = color_hover; });
control.onmouseleave.listen(function(e,c){ text.color = color; });
}
override function onbounds() {
text.bounds = new luxe.Rectangle(control.x, control.y, control.w, control.h);
}
function ontext(_text:String) {
text.text = _text;
}
override function ondestroy() {
label.onchange.remove(ontext);
text.destroy();
text = null;
}
override function onclip(_disable:Bool, _x:Float, _y:Float, _w:Float, _h:Float) {
if(_disable) {
text.clip_rect = null;
} else {
text.clip_rect = new luxe.Rectangle(_x, _y, _w, _h);
}
} //onclip
override function onvisible( _visible:Bool ) {
text.visible = _visible;
} //onvisible
override function ondepth( _depth:Float ) {
text.depth = render.options.depth + _depth;
} //ondepth
} //Label