close menus when resizing windows
This commit is contained in:
parent
30ce5e2ba9
commit
24c1f05d66
|
@ -19,7 +19,7 @@ function table.copy(t)
|
|||
return res
|
||||
end
|
||||
|
||||
function table.selective_copy(t, keys)
|
||||
function table.selectivecopy(t, keys)
|
||||
local res = { }
|
||||
for i,v in ipairs(keys) do
|
||||
res[v] = t[v]
|
||||
|
@ -32,3 +32,21 @@ function table.merge(t, src)
|
|||
t[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
function table.find(t, value)
|
||||
for k,v in pairs(t) do
|
||||
if v == value then return k end
|
||||
end
|
||||
end
|
||||
|
||||
function table.removevalue(t, value)
|
||||
local queue = {}
|
||||
for k,v in pairs(t) do
|
||||
if v == value then
|
||||
table.insert(queue, k)
|
||||
end
|
||||
end
|
||||
for i,v in pairs(queue) do
|
||||
table.remove(t, i)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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} )
|
||||
|
|
|
@ -120,7 +120,8 @@
|
|||
<item> string.trim </item> <item> string.starts </item>
|
||||
<item> string.split </item>
|
||||
<item> table.dump </item> <item> table.copy </item>
|
||||
<item> table.selective_copy </item> <item> table.merge </item>
|
||||
<item> table.selectivecopy </item> <item> table.merge </item>
|
||||
<item> table.find </item> <item> table.removevalue </item>
|
||||
<item> toboolean </item>
|
||||
</list>
|
||||
<list name="otclient-core-functions">
|
||||
|
|
Loading…
Reference in New Issue