From 3e17d0af7db5d080c4b2b7341e6451a5b60de0ee Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Tue, 1 Oct 2024 15:58:52 +0000 Subject: [PATCH] Move element graphics reload to dedicated method --- gfx/element.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gfx/element.lua b/gfx/element.lua index 13fef78..af8eb8f 100644 --- a/gfx/element.lua +++ b/gfx/element.lua @@ -30,6 +30,10 @@ function Element:new(o) setmetatable(obj, self) obj.__index = self + if obj.render and obj.render.parent then + self:_reload() + end + return obj end @@ -51,7 +55,7 @@ function Element:setPos(x, y) self.x = x or self.x self.y = y or self.y - self.render.window = createWindow(self) + self:_reload() end end @@ -59,7 +63,7 @@ function Element:setX(x) if self.x ~= x then self:setDirty() self.x = x - self.render.window = createWindow(self) + self:_reload() end end @@ -67,7 +71,7 @@ function Element:setY(y) if self.y ~= y then self:setDirty() self.y = y - self.render.window = createWindow(self) + self:_reload() end end @@ -103,7 +107,7 @@ function Element:resize(opts) self:setDirty() self.width = opts.width or self.width self.height = opts.height or self.height - self.render.window = createWindow(self) + self:_reload() end end @@ -111,7 +115,7 @@ function Element:setWidth(width) if width ~= self.width then self:setDirty() self.width = width - self.render.window = createWindow(self) + self:_reload() end end @@ -119,7 +123,7 @@ function Element:setHeight(height) if height ~= self.height then self:setDirty() self.height = height - self.render.window = createWindow(self) + self:_reload() end end @@ -171,4 +175,8 @@ function Element:setOnClick(onClick) self.onClick = onClick end +function Element:_reload() + self.render.window = createWindow(self) +end + return Element \ No newline at end of file