Add scroll:bind_grid function

This commit is contained in:
Insality
2020-09-28 01:56:43 +03:00
parent c0bd3e599b
commit 0b1051b5b2
5 changed files with 67 additions and 28 deletions

View File

@@ -245,17 +245,21 @@ end
-- update poses on grid elements. Default: gui.set_position
-- @function dynamic_grid:set_position_function
-- @tparam function callback Function on node set position
-- @treturn druid.dynamic_grid Current grid instance
function DynamicGrid:set_position_function(callback)
self._set_position_function = callback or gui.set_position
return self
end
--- Clear grid nodes array. GUI nodes will be not deleted!
-- If you want to delete GUI nodes, use dynamic_grid.nodes array before grid:clear
-- @function dynamic_grid:clear
-- @treturn druid.dynamic_grid Current grid instance
function DynamicGrid:clear()
self.nodes = {}
self:_update()
return self
end

View File

@@ -118,8 +118,11 @@ function Scroll:init(view_node, content_node)
self.selected = nil
self.is_animate = false
self._is_horizontal_scroll = true
self._is_vertical_scroll = true
self._grid_on_change = nil
self._grid_on_change_callback = nil
self:_update_size()
end
@@ -139,6 +142,11 @@ function Scroll:update(dt)
end
function Scroll:on_remove()
self:bind_grid(nil)
end
--- Start scroll to target point.
-- @function scroll:scroll_to
-- @tparam point vector3 Target point
@@ -318,6 +326,28 @@ function Scroll:set_vertical_scroll(state)
end
function Scroll:bind_grid(grid)
if self._grid_on_change then
self._grid_on_change:unsubscribe(self._grid_on_change_callback)
self._grid_on_change = nil
self._grid_on_change_callback = nil
end
if not grid then
return
end
self._grid_on_change = grid.on_change_items
self._grid_on_change_callback = self._grid_on_change:subscribe(function()
self:set_size(grid:get_size())
end)
return self
end
function Scroll:_on_scroll_drag(dx, dy)
local t = self.target_position
local b = self.available_pos

View File

@@ -218,14 +218,18 @@ end
-- update poses on grid elements. Default: gui.set_position
-- @function static_grid:set_position_function
-- @tparam function callback Function on node set position
-- @treturn druid.static_grid Current grid instance
function StaticGrid:set_position_function(callback)
self._set_position_function = callback or gui.set_position
return self
end
--- Clear grid nodes array. GUI nodes will be not deleted!
-- If you want to delete GUI nodes, use static_grid.nodes array before grid:clear
-- @function static_grid:clear
-- @treturn druid.static_grid Current grid instance
function StaticGrid:clear()
self.border.x = 0
self.border.y = 0
@@ -234,6 +238,8 @@ function StaticGrid:clear()
self.nodes = {}
self:_update()
return self
end