contextmenu: resize on scale changes (#1117)
This commit is contained in:
parent
862ed9ad6a
commit
5a80d3547e
|
@ -22,6 +22,7 @@ function ContextMenu:new()
|
||||||
self.selected = -1
|
self.selected = -1
|
||||||
self.height = 0
|
self.height = 0
|
||||||
self.position = { x = 0, y = 0 }
|
self.position = { x = 0, y = 0 }
|
||||||
|
self.current_scale = SCALE
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_item_size(item)
|
local function get_item_size(item)
|
||||||
|
@ -39,11 +40,10 @@ local function get_item_size(item)
|
||||||
return lw, lh
|
return lw, lh
|
||||||
end
|
end
|
||||||
|
|
||||||
function ContextMenu:register(predicate, items)
|
local function update_items_size(items, update_binding)
|
||||||
predicate = command.generate_predicate(predicate)
|
local width, height = 0, 0
|
||||||
local width, height = 0, 0 --precalculate the size of context menu
|
for _, item in ipairs(items) do
|
||||||
for i, item in ipairs(items) do
|
if update_binding and item ~= DIVIDER then
|
||||||
if item ~= DIVIDER then
|
|
||||||
item.info = keymap.get_binding(item.command)
|
item.info = keymap.get_binding(item.command)
|
||||||
end
|
end
|
||||||
local lw, lh = get_item_size(item)
|
local lw, lh = get_item_size(item)
|
||||||
|
@ -52,6 +52,11 @@ function ContextMenu:register(predicate, items)
|
||||||
end
|
end
|
||||||
width = width + style.padding.x * 2
|
width = width + style.padding.x * 2
|
||||||
items.width, items.height = width, height
|
items.width, items.height = width, height
|
||||||
|
end
|
||||||
|
|
||||||
|
function ContextMenu:register(predicate, items)
|
||||||
|
predicate = command.generate_predicate(predicate)
|
||||||
|
update_items_size(items, true)
|
||||||
table.insert(self.itemset, { predicate = predicate, items = items })
|
table.insert(self.itemset, { predicate = predicate, items = items })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -194,6 +199,13 @@ end
|
||||||
|
|
||||||
function ContextMenu:draw()
|
function ContextMenu:draw()
|
||||||
if not self.show_context_menu then return end
|
if not self.show_context_menu then return end
|
||||||
|
if self.current_scale ~= SCALE then
|
||||||
|
update_items_size(self.items)
|
||||||
|
for _, set in ipairs(self.itemset) do
|
||||||
|
update_items_size(set.items)
|
||||||
|
end
|
||||||
|
self.current_scale = SCALE
|
||||||
|
end
|
||||||
core.root_view:defer_draw(self.draw_context_menu, self)
|
core.root_view:defer_draw(self.draw_context_menu, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue