core/menusystem: don't draw cursor and allow selection when it overflow

This commit is contained in:
Kazhnuz 2019-02-12 18:58:26 +01:00
parent b18c95455c
commit 997a66e901
2 changed files with 18 additions and 10 deletions

View file

@ -107,7 +107,9 @@ function FlowBox:keyreleased(key, code)
end
if key == "A" then
self.widget.list[self.widget.selected]:action()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action()
end
end
end
@ -164,11 +166,13 @@ function FlowBox:draw()
end
function FlowBox:drawCursor()
local w, h = self:getWidgetSize()
local col, line = self:getCoord(self.widget.selected)
local x = (col) * h
local y = (line) * h
menuutils.drawCursor(self.x + x, self.y + y, w, h)
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local w, h = self:getWidgetSize()
local col, line = self:getCoord(self.widget.selected)
local x = (col) * h
local y = (line) * h
menuutils.drawCursor(self.x + x, self.y + y, w, h)
end
end
return FlowBox

View file

@ -42,7 +42,9 @@ function ListBox:keyreleased(key, code)
end
if key == "A" then
self.widget.list[self.widget.selected]:action()
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action()
end
end
end
@ -85,9 +87,11 @@ function ListBox:draw()
end
function ListBox:drawCursor()
local w, h = self:getWidgetSize()
local y = (self.widget.selected - 1) * h
menuutils.drawCursor(self.x,self.y + y, w, h)
if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then
local w, h = self:getWidgetSize()
local y = (self.widget.selected - 1) * h
menuutils.drawCursor(self.x,self.y + y, w, h)
end
end
return ListBox