diff --git a/gfx/element.lua b/gfx/element.lua index e56c547..b5af444 100644 --- a/gfx/element.lua +++ b/gfx/element.lua @@ -17,7 +17,7 @@ local Element = { Element.__index = Element local function createWindow(element) - return window.create(element.render.parent, element:getX(), element:getY(), element:getWidth(), element:getHeight(), element:isVisible()) + return window.create(element.parent, element:getX(), element:getY(), element:getWidth(), element:getHeight(), element:isVisible()) end @@ -83,7 +83,7 @@ function Element:setFgColor(color) if color ~= self.fgColor then self:setDirty() self.fgColor = color - self.render.window.setTextColor(color) + self:_getWindow().setTextColor(color) end end @@ -91,12 +91,28 @@ function Element:setBgColor(color) if color ~= self.bgColor then self:setDirty() self.bgColor = color - self.render.window.setBackgroundColor(color) + self:_getWindow().setBackgroundColor(color) end end +function Element:getFgColor() + return self.fgColor +end + +function Element:getBgColor() + return self.bgColor +end + +function Element:_getWindow() + return self.window +end + +function Element:_setWindow(window) + self.window = window +end + function Element:setVisible(visible) - self.render.window.setVisible(visible) + self:_getWindow().setVisible(visible) end function Element:resize(opts) @@ -157,7 +173,7 @@ function Element:getId() end function Element:redraw() - self.render.window.redraw() + self:_getWindow().redraw() end function Element:handleEvent(evt) @@ -173,7 +189,7 @@ function Element:setOnClick(onClick) end function Element:_reload() - self.render.window = createWindow(self) + self:_setWindow(createWindow(self)) end return Element \ No newline at end of file diff --git a/gfx/list.lua b/gfx/list.lua index 1bf0634..0ebc618 100644 --- a/gfx/list.lua +++ b/gfx/list.lua @@ -68,7 +68,7 @@ end function List:draw() Element.draw(self) - self.render.window.clear() + self:_getWindow().clear() for _,v in ipairs(self.children) do v:draw() end diff --git a/gfx/text.lua b/gfx/text.lua index c99e200..56bb1b1 100644 --- a/gfx/text.lua +++ b/gfx/text.lua @@ -9,10 +9,11 @@ function Text:new(o) end function Text:setText(text) - if self.text ~= text then + local current = self:getText() + if current ~= text then self:setDirty() - local needReload = #self.text ~= #text + local needReload = #current ~= #text self.text = text if needReload then self:_reload() @@ -20,9 +21,13 @@ function Text:setText(text) end end +function Text:getText() + return self.text +end + function Text:draw() Element.draw(self) - self.render.window.write(self.text) + self:_getWindow().write(self:getText()) end function Text:getHeight() @@ -30,7 +35,7 @@ function Text:getHeight() end function Text:getWidth() - return #self.text + return #self:getText() end function Text:setWidth()