mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Add grid update position function
This commit is contained in:
parent
69dd2ce9e3
commit
a92e4e6ae0
@ -49,6 +49,8 @@ function M.init(self, parent, element, in_row)
|
|||||||
self.on_remove_item = Event()
|
self.on_remove_item = Event()
|
||||||
self.on_clear = Event()
|
self.on_clear = Event()
|
||||||
self.on_update_positions = Event()
|
self.on_update_positions = Event()
|
||||||
|
|
||||||
|
self._set_position_function = gui.set_position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -87,10 +89,15 @@ local function get_pos(self, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function update_pos(self)
|
local function update_pos(self, is_instant)
|
||||||
for i = 1, #self.nodes do
|
for i = 1, #self.nodes do
|
||||||
local node = self.nodes[i]
|
local node = self.nodes[i]
|
||||||
|
|
||||||
|
if is_instant then
|
||||||
gui.set_position(node, get_pos(self, i))
|
gui.set_position(node, get_pos(self, i))
|
||||||
|
else
|
||||||
|
self._set_position_function(node, get_pos(self, i))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.on_update_positions:trigger(self:get_context())
|
self.on_update_positions:trigger(self:get_context())
|
||||||
@ -157,6 +164,15 @@ function M.get_all_pos(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Chane set position function for grid nodes. It will call on
|
||||||
|
-- update poses on grid elements. Default: gui.set_position
|
||||||
|
-- @function grid:set_position_function
|
||||||
|
-- @tparam function callback Function on node set position
|
||||||
|
function M.set_position_function(self, callback)
|
||||||
|
self._set_position_function = callback or gui.set_position
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Clear grid nodes array. GUI nodes will be not deleted!
|
--- Clear grid nodes array. GUI nodes will be not deleted!
|
||||||
-- If you want to delete GUI nodes, use grid.nodes array before grid:clear
|
-- If you want to delete GUI nodes, use grid.nodes array before grid:clear
|
||||||
-- @function grid:clear
|
-- @function grid:clear
|
||||||
|
Loading…
x
Reference in New Issue
Block a user