From 20770db3aba953585495d21bfe0a2e430485b038 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 23:03:50 +0200 Subject: First steps in cleaning-up menu. Selector, Button and Header extend Element now. --- element.lua | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'element.lua') diff --git a/element.lua b/element.lua index f9d1c3d..e6d91da 100644 --- a/element.lua +++ b/element.lua @@ -1,42 +1,50 @@ --- `Element` --- Empty element for `Menu` creation. Can be anything. +--- `Element` +-- Empty element used inside `Menu`. Element = { + parent = --[[not.Menu]]nil, x = 0, - y = 0, - parent + y = 0 } -function Element:new(parent) - local o = {} - setmetatable(o, self) - self.__index = self + +Element.__index = Element + +function Element:new (parent) + local o = setmetatable({}, self) o.parent = parent return o end -function Element:delete() end -- deletes Element -function Element:getPosition() return self.x, self.y end -- gives x,y of Element -function Element:setPosition(x,y) - self.x, self.y = x, y + +function Element:delete () end -- deletes Element + +function Element:getPosition () + return self.x, self.y +end +function Element:setPosition (x, y) + self.x = x or 0 + self.y = y or 0 return self end -function Element:set(name, func) + +function Element:set (name, func) if type(name) == "string" and func ~= nil then self[name] = func end return self end --- Menu callbacks -function Element:focus() -- Called when Element gains focus +-- Called when menu tries to focus on this element. +-- If it will return false then menu will skip element and go to next in list. +function Element:focus () return false end -function Element:blur() end -- Called when Element loses focus +function Element:blur () end -- Called when Element loses focus. -- LÖVE2D callbacks -function Element:draw(scale) end -function Element:update(dt) end +function Element:draw (scale) end +function Element:update (dt) end -- Controller callbacks -function Element:controlpressed(set, action, key) end -function Element:controlreleased(set, action, key) end +function Element:controlpressed (set, action, key) end +function Element:controlreleased (set, action, key) end -return Element \ No newline at end of file +return Element -- cgit v1.1