fix popupmenu, fix mouserelease events, fix connect
This commit is contained in:
parent
8545d15304
commit
c707f990bf
|
@ -22,7 +22,7 @@ function connect(object, signalsAndSlots, pushFront)
|
||||||
for signal,slot in pairs(signalsAndSlots) do
|
for signal,slot in pairs(signalsAndSlots) do
|
||||||
if not object[signal] then
|
if not object[signal] then
|
||||||
local mt = getmetatable(object)
|
local mt = getmetatable(object)
|
||||||
if mt then
|
if mt and type(object) == 'userdata' then
|
||||||
object[signal] = function(...)
|
object[signal] = function(...)
|
||||||
return signalcall(mt[signal], ...)
|
return signalcall(mt[signal], ...)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
UIPopupMenu = extends(UIWidget)
|
UIPopupMenu = extends(UIWidget)
|
||||||
|
|
||||||
local displayedMenuList = {}
|
local currentMenu
|
||||||
|
|
||||||
function UIPopupMenu.create()
|
function UIPopupMenu.create()
|
||||||
local menu = UIPopupMenu.internalCreate()
|
local menu = UIPopupMenu.internalCreate()
|
||||||
|
@ -17,10 +17,14 @@ function UIPopupMenu:display(pos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if currentMenu then
|
||||||
|
currentMenu:destroy()
|
||||||
|
end
|
||||||
|
|
||||||
displayUI(self, {x = pos.x, y = pos.y})
|
displayUI(self, {x = pos.x, y = pos.y})
|
||||||
self:grabMouse()
|
self:grabMouse()
|
||||||
self:grabKeyboard()
|
self:grabKeyboard()
|
||||||
table.insert(displayedMenuList, self)
|
currentMenu = self
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIPopupMenu:onGeometryChange()
|
function UIPopupMenu:onGeometryChange()
|
||||||
|
@ -44,7 +48,9 @@ function UIPopupMenu:addSeparator()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIPopupMenu:onDestroy()
|
function UIPopupMenu:onDestroy()
|
||||||
table.removevalue(displayedMenuList, self)
|
if currentMenu == self then
|
||||||
|
currentMenu = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIPopupMenu:onMousePress(mousePos, mouseButton)
|
function UIPopupMenu:onMousePress(mousePos, mouseButton)
|
||||||
|
@ -65,8 +71,8 @@ end
|
||||||
|
|
||||||
-- close all menus when the window is resized
|
-- close all menus when the window is resized
|
||||||
local function onRootGeometryUpdate()
|
local function onRootGeometryUpdate()
|
||||||
for i,menu in ipairs(displayedMenuList) do
|
if currentMenu then
|
||||||
menu:destroy()
|
currentMenu:destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
connect(rootWidget, { onGeometryChange = onRootGeometryUpdate} )
|
connect(rootWidget, { onGeometryChange = onRootGeometryUpdate} )
|
||||||
|
|
|
@ -79,7 +79,7 @@ void UIManager::inputEvent(const InputEvent& event)
|
||||||
case Fw::MousePressInputEvent:
|
case Fw::MousePressInputEvent:
|
||||||
m_mouseReceiver->propagateOnMousePress(event.mousePos, event.mouseButton);
|
m_mouseReceiver->propagateOnMousePress(event.mousePos, event.mouseButton);
|
||||||
if(event.mouseButton == Fw::MouseLeftButton)
|
if(event.mouseButton == Fw::MouseLeftButton)
|
||||||
updatePressedWidget(m_rootWidget->recursiveGetChildByPos(event.mousePos), event.mousePos);
|
updatePressedWidget(m_mouseReceiver->recursiveGetChildByPos(event.mousePos), event.mousePos);
|
||||||
break;
|
break;
|
||||||
case Fw::MouseReleaseInputEvent:
|
case Fw::MouseReleaseInputEvent:
|
||||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||||
|
|
Loading…
Reference in New Issue