mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
close menus when resizing windows
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
UIPopupMenu = extends(UIWidget)
|
||||
|
||||
local displayedMenuList = {}
|
||||
|
||||
function UIPopupMenu.create()
|
||||
local menu = UIPopupMenu.internalCreate()
|
||||
local layout = UIVerticalLayout.create(menu)
|
||||
@@ -8,6 +10,11 @@ function UIPopupMenu.create()
|
||||
return menu
|
||||
end
|
||||
|
||||
function UIPopupMenu:destroy()
|
||||
table.removevalue(displayedMenuList, self)
|
||||
UIWidget.destroy(self)
|
||||
end
|
||||
|
||||
function UIPopupMenu:display(pos)
|
||||
-- don't display if not options was added
|
||||
if self:getChildCount() == 0 then
|
||||
@@ -19,6 +26,7 @@ function UIPopupMenu:display(pos)
|
||||
self:bindRectToParent()
|
||||
self:grabMouse()
|
||||
self:grabKeyboard()
|
||||
table.insert(displayedMenuList, self)
|
||||
end
|
||||
|
||||
function UIPopupMenu:addOption(optionName, optionCallback)
|
||||
@@ -53,3 +61,12 @@ function UIPopupMenu:onKeyPress(keyCode, keyText, keyboardModifiers)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function onRootGeometryUpdate()
|
||||
-- close all menus when the window is resized
|
||||
for i,menu in ipairs(displayedMenuList) do
|
||||
menu:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
connect(rootWidget, { onGeometryUpdate = onRootGeometryUpdate} )
|
||||
|
Reference in New Issue
Block a user