-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathui_container.lua
60 lines (49 loc) · 1.31 KB
/
ui_container.lua
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
-- ui_container
local Util = require('util')
local Container = {}
Container.__index = Container
function Container.new(o)
o = o or {}
o.dragOffset = {x=0, y=0}
o.dragStart = {x=0, y=0}
o.widgets = {}
return setmetatable(o, Container)
end
function Container:baizePos()
return self.x + self.dragOffset.x, self.y + self.dragOffset.y
end
function Container:screenRect()
return self.x, self.y, self.width, self.height -- bar is not scrollable, so baize == screen pos
end
function Container:startDrag(x, y)
self.dragStart.x = self.dragOffset.x
self.dragStart.y = self.dragOffset.y
end
function Container:dragBy(dx, dy)
if self.hscroll then
self.dragOffset.x = self.dragStart.x + dx
if self.dragOffset.x > 0 then
self.dragOffset.x = 0 -- DragOffset should only ever be 0 or -ve
end
end
if self.vscroll then
self.dragOffset.y = self.dragStart.y + dy
if self.dragOffset.y > 0 then
self.dragOffset.y = 0 -- DragOffset should only ever be 0 or -ve
end
end
end
function Container:stopDrag(x, y)
end
-- update handled by subclasses
-- layout handled by subclasses
function Container:draw()
if not self:hidden() then
Util.setColorFromName('UiBackground')
love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
for _, w in ipairs(self.widgets) do
w:draw()
end
end
end
return Container