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)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newcol, newline
local newcol, newline, widget_selected
newline = beginline + math.floor(y / self.widget.h)
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
self.widget.selected = 1
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
end
end
function FlowBox:mousepressed(x, y, button, isTouch)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newline, newcol
local newline, newcol, widget_selected
newline = beginline + math.floor(y / self.widget.h)
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
self.widget.selected = 1
end
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if #self.widget.list > 0 then
if widget_selected >= 1 and widget_selected <= #self.widget.list then
self.widget.selected = widget_selected
self.widget.list[self.widget.selected]:action()
end
end
function FlowBox:draw()

View file

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