-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathui_widget.lua
38 lines (30 loc) · 850 Bytes
/
ui_widget.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
-- widget
local Widget = {
-- parent
-- x, y relative to parent
-- width, height
-- align
}
Widget.__index = Widget
function Widget.new(o)
return setmetatable(o, Widget)
end
function Widget:screenRect()
-- assert(self.x and self.y)
-- assert(self.parent)
-- assert(self.parent.x and self.parent.y)
-- assert(self.parent.dragOffset)
-- assert(self.parent.dragOffset.x and self.parent.dragOffset.y)
-- assert(self.width and self.height)
local x = self.parent.x + self.parent.dragOffset.x + self.x
local y = self.parent.y + self.parent.dragOffset.y + self.y
return x, y, self.width, self.height
end
function Widget:hitRect()
-- by default, return rect of widget content (text or icon)
return self:screenRect()
end
-- Widget:layout() done by parent
-- no need for Widget:update()
-- Widget.draw() done by subclasses
return Widget