Add more infinity scroll example

This commit is contained in:
Insality
2020-09-16 01:23:11 +03:00
parent f027d4ac96
commit 2d2790f760
4 changed files with 265 additions and 9 deletions

View File

@@ -125,8 +125,10 @@ function M.get_index(self, pos)
local col = (pos.x + self.border_offset.x) / (self.node_size.x + self.offset.x)
local row = -(pos.y + self.border_offset.y) / (self.node_size.y + self.offset.y)
local index = col + (row * self.in_row) + 1
return math.floor(index)
row = math.floor(row)
local index = col + (row * self.in_row)
return math.ceil(index)
end

View File

@@ -23,7 +23,7 @@ function M:init(data_list, scroll, grid, create_function)
self.components = {}
self.elements_view_count = vmath.vector3(
math.ceil(self.view_size.x / self.prefab_size.x),
math.min(math.ceil(self.view_size.x / self.prefab_size.x), self.grid.in_row),
math.ceil(self.view_size.y / self.prefab_size.y),
0)
@@ -89,8 +89,9 @@ end
function M:_check_elements()
local pos = gui.get_position(self.scroll.content_node)
pos.y = -pos.y
local top_index = self.grid:get_index(pos)
local last_index = top_index + (self.elements_view_count.x * self.elements_view_count.y) + 1
local last_index = top_index + (self.elements_view_count.x * self.elements_view_count.y) + self.grid.in_row - 1
-- Clear outside elements
for index, _ in pairs(self.nodes) do