-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.js
88 lines (79 loc) · 2.16 KB
/
Button.js
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
import Component from "./Component.js"
import BackGround from "./Background.js"
import Label from "./Label.js"
export default class Button extends Component {
constructor() {
super()
}
setText(text, fontSize, color = "black", x, y) {
if (!this.textLabel) {
this.textLabel = new Label().setSizeEqualToParent()
this.textLabel.options.informational.is_button_text_label = true
this.textLabel.addEventListener(Component.events.build, (_, target) => {
target.getContainer().style.pointerEvents = "none"
})
this.addComponent(this.textLabel)
}
this.textLabel.centerText()
this.textLabel.setText(text).setColor(color)
if (fontSize) this.textLabel.setFontSize(fontSize)
if (x || y) this.textLabel.setPosition(x, y)
return this
}
copy(toCopy) {
let copy = super.copy(toCopy)
let found = false
if (this.queue)
for (let component of copy.queue) {
if (component.component.options.informational.is_button_text_label) {
copy.textLabel = component.component
found = true
break
}
}
if (!found)
for (const component in copy.componentOrder) {
if (component.options.informational.is_button_text_label) {
copy.textLabel = component
found = true
break
}
}
return copy
}
createHTMLElement() {
this.container = document.createElement("button")
}
/**
asymethric - defines if icon W == H, false for ==
@deprecated
*/
setIcon(
icon,
x = 0.15,
y = 0.15,
width = -1,
height = -1,
asymethric = false
) {
{
if (width == -1) {
width = this.size.x - 2 * x
}
if (height == -1) {
height = this.size.y - 2 * y
}
if (asymethric == false)
if (height < width) {
width = height
} else height = width
}
let icon_component = new BackGround()
.setSize(width, height)
.setPosition(x, y)
.setName("icon")
.setImg(icon)
this.addComponent(icon_component)
return this
}
}