feat(menumodel): add a widget limit

This commit is contained in:
Kazhnuz 2020-11-29 12:50:07 +01:00
parent a3e2da3972
commit 12b4b3fbc1

View file

@ -16,6 +16,7 @@ function MenuModel:new()
self.selected = 0 self.selected = 0
self.selectedPrevious = 0 self.selectedPrevious = 0
self.cancel = 0 self.cancel = 0
self.limit = -1
-- self:updateWidgetSize() -- self:updateWidgetSize()
end end
@ -24,6 +25,10 @@ function MenuModel:clear()
self.cancel = 0 self.cancel = 0
end end
function MenuModel:setLimit(limit)
self.limit = limit
end
-- UPDATE/DRAW FUNCTIONS -- UPDATE/DRAW FUNCTIONS
-- All the update functions -- All the update functions
@ -70,6 +75,9 @@ end
-- All the functions to handle widgets -- All the functions to handle widgets
function MenuModel:addWidget(newWidget) function MenuModel:addWidget(newWidget)
if (self.limit ~= -1 and #self.list >= self.limit) then
return
end
if #self.list == 0 then if #self.list == 0 then
self.selected = 1 self.selected = 1
end end