diff options
author | Aki <nthirtyone@gmail.com> | 2017-09-05 01:55:14 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-09-05 01:55:14 +0200 |
commit | a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80 (patch) | |
tree | 36a9baf27ef60adc713184bdbaeb1c2af0349c6c /not | |
parent | b117c29325698e56a4fbd76426739dd48fa154cb (diff) | |
download | roflnauts-a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80.zip roflnauts-a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80.tar.gz roflnauts-a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80.tar.bz2 |
Added addChild, setPosition and getSize to Group
Diffstat (limited to 'not')
-rw-r--r-- | not/Group.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/not/Group.lua b/not/Group.lua index 45dc474..898d7f3 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -4,6 +4,35 @@ Group = require "not.Element":extends() function Group:new (parent) Group.__super.new(self, parent) self.children = {} + self.marign = 0 +end + +function Group:addChild (element) + table.insert(self.children, element) + return element +end + +-- TODO: Missing semi-important docs on Group's setPosition. +function Group:setPosition (x, y) + local dx = 0 + for _,child in ipairs(self.children) do + child:setPosition(x + dx, y) + dx = dx + child:getSize() + self.marigin + end + return Group.__super.setPosition(self, x, y) +end + +function Group:getSize () + local twidth = -self.marigin + local theight = 0 + for _,child in ipairs(self.children) do + local cwidth, cheight = child:getSize() + twidth = twidth + child:getSize() + self.marigin + if theight < cheight then + theight = cheight + end + end + return twidth, theight end --- Calls function with parameters for each child. |