From a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 01:55:14 +0200 Subject: Added addChild, setPosition and getSize to Group --- not/Group.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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. -- cgit v1.1