Add return node on grid's remove function

This commit is contained in:
Insality 2020-11-03 19:46:20 +03:00
parent 7bbfbab45e
commit 5d9951e03f
2 changed files with 8 additions and 0 deletions

View File

@ -176,9 +176,11 @@ end
-- @tparam StaticGrid self
-- @tparam number index The grid node index to remove
-- @tparam bool is_shift_nodes If true, will shift nodes left after index
-- @treturn Node The deleted gui node from grid
function StaticGrid.remove(self, index, is_shift_nodes)
assert(self.nodes[index], "No grid item at given index " .. index)
local remove_node = self.nodes[index]
self.nodes[index] = nil
if is_shift_nodes then
@ -191,6 +193,8 @@ function StaticGrid.remove(self, index, is_shift_nodes)
self.on_remove_item:trigger(self:get_context(), index)
self.on_change_items:trigger(self:get_context(), index)
return remove_node
end

View File

@ -178,12 +178,14 @@ end
-- @tparam DynamicGrid self
-- @tparam number index The grid node index to remove
-- @tparam[opt=false] bool is_shift_left If true, shift all nodes to the left, otherwise shift nodes to the right
-- @treturn Node The deleted gui node from grid
function DynamicGrid.remove(self, index, is_shift_left)
local delta = is_shift_left and -1 or 1
assert(self.nodes[index], "No grid item at given index " .. index)
-- Just set nil for delete node data
local removed_node = self.nodes[index].node
self.nodes[index] = nil
-- After delete node, we should shift nodes and recalc their poses, depends from is_shift_left
@ -200,6 +202,8 @@ function DynamicGrid.remove(self, index, is_shift_left)
self.on_remove_item:trigger(self:get_context(), index)
self.on_change_items:trigger(self:get_context(), index)
return removed_node
end