core/menusystem: don't update cursor position when hovering no widget

This commit is contained in:
Kazhnuz 2019-02-12 18:15:17 +01:00
parent 902dfa0d95
commit c4ce0f5c5d
2 changed files with 21 additions and 32 deletions

View file

@ -112,39 +112,31 @@ end
function FlowBox:mousemoved(x, y) function FlowBox:mousemoved(x, y)
local col, line = self:getCoord(self.widget.selected) local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin) local begincol, beginline = self:getCoord(self.begin)
local newcol, newline local newcol, newline, widget_selected
newline = beginline + math.floor(y / self.widget.h) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widget.w) newcol = math.floor(x / self.widget.w)
self.widget.selected = (newline * self.slots_hor) + newcol + 1 widget_selected = (newline * self.slots_hor) + newcol + 1
if self.widget.selected < 1 then if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = 1 self.widget.selected = widget_selected
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end end
end end
function FlowBox:mousepressed(x, y, button, isTouch) function FlowBox:mousepressed(x, y, button, isTouch)
local col, line = self:getCoord(self.widget.selected) local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin) local begincol, beginline = self:getCoord(self.begin)
local newline, newcol local newline, newcol, widget_selected
newline = beginline + math.floor(y / self.widget.h) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widget.w) newcol = math.floor(x / self.widget.w)
self.widget.selected = (newline * self.slots_hor) + newcol + 1 widget_selected = (newline * self.slots_hor) + newcol + 1
if self.widget.selected < 1 then if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = 1 self.widget.selected = widget_selected
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action() self.widget.list[self.widget.selected]:action()
end end
end end
function FlowBox:draw() function FlowBox:draw()

View file

@ -46,26 +46,23 @@ function ListBox:keyreleased(key, code)
end end
function ListBox:mousemoved(x, y) function ListBox:mousemoved(x, y)
self.widget.selected = self.begin + math.floor(y / self.widget.h) local widget_selected = self.begin + math.floor(y / self.widget.h)
if self.widget.selected < 1 then
self.widget.selected = 1 if widget_selected >= 1 and widget_selected <= #self.widget.list then
end self.widget.selected = widget_selected
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end end
end end
function ListBox:mousepressed(x, y, button, isTouch) function ListBox:mousepressed(x, y, button, isTouch)
self.widget.selected = self.begin + math.floor(y / self.widget.h) local widget_selected = self.begin + math.floor(y / self.widget.h)
if self.widget.selected < 1 then
self.widget.selected = 1 if widget_selected >= 1 and widget_selected <= #self.widget.list then
end self.widget.selected = widget_selected
if self.widget.selected > #self.widget.list then if #self.widget.list > 0 then
self.widget.selected = #self.widget.list self.widget.list[self.widget.selected]:action()
end end
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action()
end end
end end
function ListBox:draw() function ListBox:draw()