mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
#104 Add is_instant flag to add/remove Static and Dynamic Grid components
This commit is contained in:
parent
a4a03db813
commit
ab3f5f8e31
@ -180,7 +180,8 @@ end
|
|||||||
-- @tparam node item Gui node
|
-- @tparam node item Gui node
|
||||||
-- @tparam[opt] number index The item position. By default add as last item
|
-- @tparam[opt] number index The item position. By default add as last item
|
||||||
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
||||||
function StaticGrid.add(self, item, index, shift_policy)
|
-- @tparam[opt=false] boolean is_instance If true, update node positions instantly
|
||||||
|
function StaticGrid.add(self, item, index, shift_policy, is_instant)
|
||||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||||
index = index or ((self.last_index or 0) + 1)
|
index = index or ((self.last_index or 0) + 1)
|
||||||
|
|
||||||
@ -206,7 +207,7 @@ function StaticGrid.add(self, item, index, shift_policy)
|
|||||||
|
|
||||||
gui.set_position(item, self:get_pos(index) + self:_get_zero_offset())
|
gui.set_position(item, self:get_pos(index) + self:_get_zero_offset())
|
||||||
|
|
||||||
self:_update_pos()
|
self:_update_pos(is_instant)
|
||||||
|
|
||||||
self.on_add_item:trigger(self:get_context(), item, index)
|
self.on_add_item:trigger(self:get_context(), item, index)
|
||||||
self.on_change_items:trigger(self:get_context(), index)
|
self.on_change_items:trigger(self:get_context(), index)
|
||||||
@ -217,8 +218,9 @@ end
|
|||||||
-- @tparam StaticGrid self
|
-- @tparam StaticGrid self
|
||||||
-- @tparam number index The grid node index to remove
|
-- @tparam number index The grid node index to remove
|
||||||
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
||||||
|
-- @tparam[opt=false] boolean is_instance If true, update node positions instantly
|
||||||
-- @treturn Node The deleted gui node from grid
|
-- @treturn Node The deleted gui node from grid
|
||||||
function StaticGrid.remove(self, index, shift_policy)
|
function StaticGrid.remove(self, index, shift_policy, is_instant)
|
||||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||||
assert(self.nodes[index], "No grid item at given index " .. index)
|
assert(self.nodes[index], "No grid item at given index " .. index)
|
||||||
|
|
||||||
@ -236,7 +238,7 @@ function StaticGrid.remove(self, index, shift_policy)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:_update()
|
self:_update(is_instant)
|
||||||
|
|
||||||
self.on_remove_item:trigger(self:get_context(), index)
|
self.on_remove_item:trigger(self:get_context(), index)
|
||||||
self.on_change_items:trigger(self:get_context(), index)
|
self.on_change_items:trigger(self:get_context(), index)
|
||||||
|
@ -140,7 +140,8 @@ end
|
|||||||
-- @tparam node node Gui node
|
-- @tparam node node Gui node
|
||||||
-- @tparam[opt] number index The node position. By default add as last node
|
-- @tparam[opt] number index The node position. By default add as last node
|
||||||
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
||||||
function DynamicGrid.add(self, node, index, shift_policy)
|
-- @tparam[opt=false] boolean is_instance If true, update node positions instantly
|
||||||
|
function DynamicGrid.add(self, node, index, shift_policy, is_instant)
|
||||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||||
local delta = shift_policy -- -1 or 1 or 0
|
local delta = shift_policy -- -1 or 1 or 0
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ function DynamicGrid.add(self, node, index, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Sync grid data
|
-- Sync grid data
|
||||||
self:_update()
|
self:_update(is_instant)
|
||||||
|
|
||||||
self.on_add_item:trigger(self:get_context(), node, index)
|
self.on_add_item:trigger(self:get_context(), node, index)
|
||||||
self.on_change_items:trigger(self:get_context(), index)
|
self.on_change_items:trigger(self:get_context(), index)
|
||||||
@ -181,8 +182,9 @@ end
|
|||||||
-- @tparam DynamicGrid self
|
-- @tparam DynamicGrid self
|
||||||
-- @tparam number index The grid node index to remove
|
-- @tparam number index The grid node index to remove
|
||||||
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
||||||
|
-- @tparam[opt=false] boolean is_instance If true, update node positions instantly
|
||||||
-- @treturn Node The deleted gui node from grid
|
-- @treturn Node The deleted gui node from grid
|
||||||
function DynamicGrid.remove(self, index, shift_policy)
|
function DynamicGrid.remove(self, index, shift_policy, is_instant)
|
||||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||||
local delta = shift_policy -- -1 or 1 or 0
|
local delta = shift_policy -- -1 or 1 or 0
|
||||||
|
|
||||||
@ -204,7 +206,7 @@ function DynamicGrid.remove(self, index, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Sync grid data
|
-- Sync grid data
|
||||||
self:_update()
|
self:_update(is_instant)
|
||||||
|
|
||||||
self.on_remove_item:trigger(self:get_context(), index)
|
self.on_remove_item:trigger(self:get_context(), index)
|
||||||
self.on_change_items:trigger(self:get_context(), index)
|
self.on_change_items:trigger(self:get_context(), index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user