104 lines
2.3 KiB
Lua
104 lines
2.3 KiB
Lua
local Event = require("gfx.event")
|
|
local Element = require("gfx.element")
|
|
local Padding = Element:new{
|
|
left = 0,
|
|
right = 0,
|
|
top = 0,
|
|
bottom = 0,
|
|
element = nil
|
|
}
|
|
|
|
function Padding:new(opts)
|
|
local obj = Element.new(self, opts)
|
|
obj.element:setPos(obj:getPaddingLeft() + 1, obj:getPaddingTop() + 1)
|
|
obj:resize{
|
|
width = obj:getWidth(),
|
|
height = obj:getHeight()
|
|
}
|
|
obj.element:setParent(obj:_getWindow())
|
|
return obj
|
|
end
|
|
|
|
function Padding:resize(opts)
|
|
-- Un-pad dimensions and pass to child element
|
|
return self.element:resize{
|
|
width = (opts.width and opts.width - self:getPaddingLeft() - self:getPaddingRight()) or self:getWidth(),
|
|
height = (opts.height and opts.height - self:getPaddingTop() - self:getPaddingBottom()) or self:getHeight()
|
|
}
|
|
end
|
|
|
|
function Padding:draw()
|
|
if Element.draw(self) then
|
|
local win = self:_getWindow()
|
|
win.clear()
|
|
self.element:draw()
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function Padding:setDirty(fullInvalidate)
|
|
Element.setDirty(self, fullInvalidate)
|
|
if fullInvalidate then
|
|
self.element:setDirty(fullInvalidate)
|
|
end
|
|
end
|
|
|
|
function Padding:getPaddingLeft()
|
|
return self.left
|
|
end
|
|
|
|
function Padding:getPaddingRight()
|
|
return self.right
|
|
end
|
|
|
|
function Padding:getPaddingTop()
|
|
return self.top
|
|
end
|
|
|
|
function Padding:getPaddingBottom()
|
|
return self.bottom
|
|
end
|
|
|
|
function Padding:getInnerWidth()
|
|
return self.element:getWidth()
|
|
end
|
|
|
|
function Padding:getInnerHeight()
|
|
return self.element:getHeight()
|
|
end
|
|
|
|
function Padding:getWidth()
|
|
return self:getInnerWidth() + self:getPaddingLeft() + self:getPaddingRight()
|
|
end
|
|
|
|
function Padding:getHeight()
|
|
return self:getInnerHeight() + self:getPaddingTop() + self:getPaddingBottom()
|
|
end
|
|
|
|
function Padding:findById(id)
|
|
return Element.findById(self, id) or self.element:findById(id)
|
|
end
|
|
|
|
function Padding:handleEvent(evt)
|
|
if Element.handleEvent(self, evt) then
|
|
return true
|
|
end
|
|
|
|
if Event.isClickEvent(evt) then
|
|
return Event.containsClick(self, evt) and self.element:handleEvent(Event.toElementLocalPosition(evt, self.element))
|
|
else
|
|
return self.element:handleEvent(evt)
|
|
end
|
|
end
|
|
|
|
function Padding:_reload()
|
|
Element._reload(self)
|
|
self.element:setParent(self:_getWindow())
|
|
end
|
|
|
|
function Padding:_isDirty()
|
|
return Element._isDirty(self) or self.element:_isDirty()
|
|
end
|
|
|
|
return Padding |