-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentry.lua
More file actions
97 lines (80 loc) · 1.98 KB
/
entry.lua
File metadata and controls
97 lines (80 loc) · 1.98 KB
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
require("yalg")
local function mEnter(self, x, y)
self.style.borderColor = rgb(0,0,0)
end
local function mLeave(self, x, y)
self.style.borderColor = rgb(255,255,255)
end
local function cIncrement(self, x, y, button)
self.linkedL:setVal(self.linkedL.entry.value + self.linkedL.entry.step)
end
local function cDecrement(self, x, y, button)
self.linkedL:setVal(self.linkedL.entry.value - self.linkedL.entry.step)
end
local function setVal(self, val)
local ent = self.entry
val = math.min(val, ent.max)
val = math.max(val, ent.min)
ent.value = val
if type(ent.format)=="string" then
self.text = ent.format:format(val)
else if type(ent.format)=="table" then
self.text = ent.format[val]
end
end
if ent.callback then
ent.callback(self, val, self.text)
end
end
local HDivStyle = {
gap = 5,
}
local plusButtonStyle = {
font = Font(20),
width = 20,
borderColor = rgb(255, 255, 255),
backgroundColor = rgb(0,255,0),
mouseEnter = mEnter,
mouseLeave = mLeave,
click = cIncrement,
}
local labelStyle = {
}
local minusButtonStyle = {
font = Font(20),
width = 20,
borderColor = rgb(255, 255, 255),
backgroundColor = rgb(255,0,0),
mouseEnter = mEnter,
mouseLeave = mLeave,
click = cDecrement,
}
function Entry(name, format, default, min, max, step, callback)
local l = Label(name, labelStyle, name)
local plusB = Button("+", plusButtonStyle)
local minusB = Button("-", minusButtonStyle)
if type(format)=="table" then
min = 1
max = #format
step = 1
end
l.entry = {
format = format,
value = default,
min = min,
max = max,
step = step,
}
l.setVal = setVal
l:setVal(default)
-- do not call callback on initialization
l.entry.callback = callback
plusB.linkedL = l
minusB.linkedL = l
return HDiv(
minusB,
l,
plusB,
HDivStyle
)
end