local Event = require("event") local Element = require("element") local Padding = Element:new{ left = 0, right = 0, top = 0, bottom = 0, element = nil } 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: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 if Event.containsClick(self.element, evt, -self:getPaddingLeft(), -self:getPaddingTop()) then self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())}) end else return self.element:handleEvent(evt) end return false end return Padding