From e9d01d1e65489e70782fb917eec73e2e3a9c4efc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 10 Feb 2019 21:05:31 +0100 Subject: [PATCH] core/menusystem: add a function to update widget size --- sonic-boost.love/core/modules/menusystem/flowbox.lua | 5 +++++ sonic-boost.love/core/modules/menusystem/grid.lua | 7 +++++-- sonic-boost.love/core/modules/menusystem/listbox.lua | 7 +++++-- sonic-boost.love/core/modules/menusystem/parent.lua | 10 ++++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/flowbox.lua b/sonic-boost.love/core/modules/menusystem/flowbox.lua index df176bb..ad75cce 100644 --- a/sonic-boost.love/core/modules/menusystem/flowbox.lua +++ b/sonic-boost.love/core/modules/menusystem/flowbox.lua @@ -16,6 +16,11 @@ function FlowBox:new(x,y,w,h,slots_hor,slots_vert) -- soit un multiple du nombre de slot et de leur dimensions end +function Menu:updateWidgetSize() + self.widget.h = math.floor( self.h / slots_vert ) + self.widget.w = math.floor( self.w / slots_hor ) +end + function FlowBox:update(dt) local col, line = self:getCoord(self.widget.selected) local begincol, beginline = self:getCoord(self.begin) diff --git a/sonic-boost.love/core/modules/menusystem/grid.lua b/sonic-boost.love/core/modules/menusystem/grid.lua index e9cf653..77b465e 100644 --- a/sonic-boost.love/core/modules/menusystem/grid.lua +++ b/sonic-boost.love/core/modules/menusystem/grid.lua @@ -10,8 +10,6 @@ function GridBox:new(x,y,w,h,slots_hor,slots_vert) self.slots_hor = slots_hor self.slots_vert = slots_vert self.begin = 1 - self.widget.h = math.floor( self.h / slots_vert ) - self.widget.w = math.floor( self.w / slots_hor ) self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur self.w = slots_hor * self.widget.w -- et la largeur -- soit un multiple du nombre de slot et de leur dimensions @@ -31,6 +29,11 @@ function GridBox:new(x,y,w,h,slots_hor,slots_vert) end end +function Menu:updateWidgetSize() + self.widget.h = math.floor( self.h / slots_vert ) + self.widget.w = math.floor( self.w / slots_hor ) +end + function GridBox:update(dt) self.begin = 1 local slotID = self:getSlotbyCoord(self.cursor.x, self.cursor.y) diff --git a/sonic-boost.love/core/modules/menusystem/listbox.lua b/sonic-boost.love/core/modules/menusystem/listbox.lua index ae593db..fa1d5eb 100644 --- a/sonic-boost.love/core/modules/menusystem/listbox.lua +++ b/sonic-boost.love/core/modules/menusystem/listbox.lua @@ -7,12 +7,15 @@ function ListBox:new(x,y,w,h,slots) ListBox.super.new(self, x, y, w, h) self.slots = slots self.begin = 1 - self.widget.w = self.w - self.widget.h = math.floor( self.h / slots ) self.h = slots * self.widget.h -- On fait en sorte que la hauteur -- soit un multiple du nombre de slot et de leur hauteur end +function Menu:updateWidgetSize() + self.widget.h = math.floor( self.h / slots ) + self.widget.w = self.w +end + function ListBox:update(dt) if self.widget.selected < self.begin then self.begin = self.widget.selected diff --git a/sonic-boost.love/core/modules/menusystem/parent.lua b/sonic-boost.love/core/modules/menusystem/parent.lua index ad91c32..1c4c09b 100644 --- a/sonic-boost.love/core/modules/menusystem/parent.lua +++ b/sonic-boost.love/core/modules/menusystem/parent.lua @@ -11,8 +11,7 @@ function Menu:new(x,y,w,h) self.widget.selected = 0 self.widget.selectedPrevious = 0 self.widget.cancel = 0 - self.widget.h = 0 - self.widget.w = 0 + self:setWidgetSize() self.isDestroyed = false self.haveFocus = false @@ -32,6 +31,11 @@ function Menu:setCancelWidget(id) self.widget.cancel = #self.widget.list end +function Menu:updateWidgetSize() + self.widget.h = 0 + self.widget.w = 0 +end + function Menu:getWidgetSize(id) return self.widget.h, self.widget.w end @@ -56,6 +60,8 @@ function Menu:resize(x,y,w,h) self.y = y self.w = w self.h = h + + self:updateWidgetSize() end function Menu:destroy()