-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.lua
More file actions
137 lines (115 loc) · 4.05 KB
/
Copy pathlist.lua
File metadata and controls
137 lines (115 loc) · 4.05 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
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
126
127
128
129
130
131
132
133
134
135
136
137
local pretty = require("pl.pretty")
local button = require("button")
local widget = require("widget")
local scrollBar = require("scrollbar")
local listBox = {}
listBox.__index = listBox
setmetatable(listBox, widget)
function listBox.new(app, x, y, width, height, content)
local self = {}
setmetatable(self, listBox)
listBox.init(self, app, x, y, width, height, content)
return self
end
function listBox.init(self, app, x, y, width, height, content)
widget.init(self, app)
self.width = width
self.height = height
self.x = x
self.y = y
self.radius = {x=2, y=2}
self.content = content
self.buttons ={}
self.buttonHeight = 30
self.colors = {
released = {text={0,0,0,1}, fill= {1,1,1,1}, stroke = {0.5,0.5,0.5,1}},
pressed = {text={0,0,0,1}, fill= {1,1,1,1}, stroke={0.5,0.5,0.5,1}},
hovered = {text={0,0,0,1}, fill= {1,1,1,1}, stroke={0.5,0.5,0.5,1}},
focused = {text={0,0,0,1}, fill= {1,1,1,1}, stroke = {0.5,0.5,1,1}},
}
for k,v in ipairs(content) do
local bt = button.new(self, self.x, self.y + (self.buttonHeight * (k - 1)), v)
bt.colors = {
released = {text={0,0,0,1}, fill= {1,1,1,1}, stroke = {1,1,1,1}},
pressed = {text={1,0,0,1}, fill= {0.5,0.5,0.5,1}, stroke={0.5,0.5,0.5,1}},
hovered = {text={0,0,0,1}, fill= {1,1,1,1}, stroke = {1,1,1,1}},
focused = {text={1,1,1,1}, fill= {0,0,1,1}, stroke = {0,0,1,1}},
}
bt.color = bt.colors.released
bt.radius = {x = 0, y = 0}
bt.width = self.width
bt.height = self.buttonHeight
bt.textPos = "left"
table.insert(self.buttons, bt)
end
self.contentRect = {x=self.x, y=self.y, width = self.width, height = #self.buttons * self.buttonHeight}
self.scrollBar = scrollBar.new(self)
end
function listBox.draw(self)
local currentColor = self:getColor()
love.graphics.setColor(currentColor.fill)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height, self.radius.x, self.radius.y)
love.graphics.setScissor(self.x, self.y, self.width, self.height)
for k,v in ipairs(self.buttons) do
v:draw()
end
love.graphics.setScissor()
self.scrollBar:draw()
love.graphics.setColor(currentColor.stroke)
love.graphics.rectangle("line", self.x, self.y, self.width, self.height, self.radius.x, self.radius.y)
end
function listBox.keyPressed(self, handled, key)
if self.focused then
end
end
function listBox.mousePressed(self, handled, x, y, button, isTouch)
if self:hit(x,y) then
handled = handled or self.scrollBar:mousePressed(handled, x, y, button, isTouch)
self.pressed = true
if not handled then
for k,v in ipairs(self.buttons) do
handled = handled or v:mousePressed(handled, x,y,button,isTouch)
end
end
else
self.pressed = false
self.focused = false
end
return handled
end
function listBox.mouseReleased(self, handled, x, y, button, isTouch)
handled = handled or self.scrollBar:mouseReleased(handled, x, y, button, isTouch)
if self:hit(x,y) and self.pressed then
self.focused = true
else
self.focused = false
end
if self:hit(x,y) then
if not handled then
for k,v in ipairs(self.buttons) do
handled = handled or v:mouseReleased(handled, x,y,button,isTouch)
end
end
end
self.pressed = false
return handled
end
function listBox.getContentRect(self)
return {
x = self.contentRect.x,
y = self.contentRect.y,
width = self.contentRect.width,
height = self.contentRect.height
}
end
function listBox.setContentPosition(self, position)
self.contentPosition = {x=position.x, y=position.y}
for pos,button in pairs(self.buttons) do
button.x = self.contentPosition.x
button.y = self.contentPosition.y + self.buttonHeight * (pos - 1)
end
end
function listBox.update(self, dt)
self.scrollBar:update(dt)
end
return listBox