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

View File

@ -10511,7 +10511,7 @@ nodes {
nodes {
position {
x: 0.0
y: 200.0
y: 280.0
z: 0.0
w: 1.0
}
@ -10529,7 +10529,7 @@ nodes {
}
size {
x: 300.0
y: 400.0
y: 250.0
z: 0.0
w: 1.0
}
@ -10584,7 +10584,7 @@ nodes {
}
size {
x: 400.0
y: 400.0
y: 250.0
z: 0.0
w: 1.0
}
@ -10621,7 +10621,7 @@ nodes {
nodes {
position {
x: 0.0
y: 160.0
y: 240.0
z: 0.0
w: 1.0
}
@ -10739,7 +10739,7 @@ nodes {
nodes {
position {
x: 0.0
y: 240.0
y: 320.0
z: 0.0
w: 1.0
}
@ -10799,6 +10799,234 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 0.0
y: -44.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 270.0
y: 250.0
z: 0.0
w: 1.0
}
color {
x: 0.8
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: ""
id: "infinity_scroll_3_stencil"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_N
adjust_mode: ADJUST_MODE_FIT
parent: "infinity_page"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_STENCIL
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 270.0
y: 250.0
z: 0.0
w: 1.0
}
color {
x: 0.8
y: 1.0
z: 0.8
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty"
id: "infinity_scroll_3_content"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_N
adjust_mode: ADJUST_MODE_FIT
parent: "infinity_scroll_3_stencil"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: -106.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 90.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "infinity_prefab_small"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "infinity_page"
layer: ""
inherit_alpha: true
slice9 {
x: 20.0
y: 0.0
z: 20.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 4.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.75
y: 0.75
z: 1.0
w: 1.0
}
size {
x: 380.0
y: 50.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "001"
font: "game"
id: "infinity_text_3"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 0.3019608
y: 0.4
z: 0.8
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "infinity_prefab_small"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 0.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 0.0

View File

@ -14,6 +14,19 @@ local function create_infinity_instance(self, record, index)
end
local function create_infinity_instance_small(self, record, index)
local instance = gui.clone_tree(self.infinity_prefab_small)
gui.set_enabled(instance["infinity_prefab_small"], true)
gui.set_text(instance["infinity_text_3"], index)
local button = self.druid:new_button(instance["infinity_prefab_small"], function()
print("Infinity click on", index)
end)
return instance["infinity_prefab_small"], button
end
local function setup_infinity_list(self)
local data = {}
@ -29,6 +42,12 @@ local function setup_infinity_list(self)
-- scroll to some index
local pos = self.infinity_grid:get_pos(100)
self.infinity_scroll:scroll_to(pos, true)
self.infinity_list_small = self.druid:new_infinity_list(data, self.infinity_scroll_3, self.infinity_grid_3, function(record, index)
-- function should return gui_node, [druid_component]
return create_infinity_instance_small(self, record, index)
end)
end
@ -40,6 +59,12 @@ function M.setup_page(self)
self.infinity_prefab = gui.get_node("infinity_prefab")
gui.set_enabled(self.infinity_prefab, false)
self.infinity_scroll_3 = self.druid:new_scroll("infinity_scroll_3_stencil", "infinity_scroll_3_content")
self.infinity_grid_3 = self.druid:new_grid("infinity_scroll_3_content", "infinity_prefab_small", 3)
self.infinity_prefab_small = gui.get_node("infinity_prefab_small")
gui.set_enabled(self.infinity_prefab_small, false)
setup_infinity_list(self)
end