mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update data list examples
This commit is contained in:
parent
8a8a5e22a0
commit
29f4d6f47a
@ -29,7 +29,7 @@ local DataList = component.create("data_list")
|
|||||||
-- @tparam DataList self
|
-- @tparam DataList self
|
||||||
-- @tparam druid.scroll The Scroll instance for Data List component
|
-- @tparam druid.scroll The Scroll instance for Data List component
|
||||||
-- @tparam druid.grid The Grid instance for Data List component
|
-- @tparam druid.grid The Grid instance for Data List component
|
||||||
-- @tparam function create_function The create function callback(self, data, index). Function should return (node, [component])
|
-- @tparam function create_function The create function callback(self, data, index, data_list). Function should return (node, [component])
|
||||||
function DataList.init(self, scroll, grid, create_function)
|
function DataList.init(self, scroll, grid, create_function)
|
||||||
self.druid = self:get_druid()
|
self.druid = self:get_druid()
|
||||||
self.scroll = scroll
|
self.scroll = scroll
|
||||||
@ -186,7 +186,7 @@ function DataList._add_at(self, index)
|
|||||||
self:_remove_at(index)
|
self:_remove_at(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
local node, instance = self._create_function(self:get_context(), self._data[index], index)
|
local node, instance = self._create_function(self:get_context(), self._data[index], index, self)
|
||||||
self.grid:add(node, index, const.SHIFT.NO_SHIFT)
|
self.grid:add(node, index, const.SHIFT.NO_SHIFT)
|
||||||
self._data_visual[index] = {
|
self._data_visual[index] = {
|
||||||
node = node,
|
node = node,
|
||||||
|
@ -9,7 +9,7 @@ shadow_alpha: 1.0
|
|||||||
shadow_blur: 0
|
shadow_blur: 0
|
||||||
shadow_x: 3.0
|
shadow_x: 3.0
|
||||||
shadow_y: -4.0
|
shadow_y: -4.0
|
||||||
extra_characters: ""
|
extra_characters: "\342\204\226%;"
|
||||||
output_format: TYPE_DISTANCE_FIELD
|
output_format: TYPE_DISTANCE_FIELD
|
||||||
all_chars: true
|
all_chars: true
|
||||||
cache_width: 0
|
cache_width: 0
|
||||||
|
@ -116,7 +116,7 @@ local function init_lobby(self)
|
|||||||
self.lobby_grid:add(get_button(self, "With static grid", "data_list_static_grid"))
|
self.lobby_grid:add(get_button(self, "With static grid", "data_list_static_grid"))
|
||||||
self.lobby_grid:add(get_button(self, "With dynamic grid", "data_list_dynamic_grid"))
|
self.lobby_grid:add(get_button(self, "With dynamic grid", "data_list_dynamic_grid"))
|
||||||
self.lobby_grid:add(get_button_disabled(self, "Add/remove elements", "scroll_scene"))
|
self.lobby_grid:add(get_button_disabled(self, "Add/remove elements", "scroll_scene"))
|
||||||
self.lobby_grid:add(get_button(self, "Navigate over elements", "data_list_navigate"))
|
self.lobby_grid:add(get_button_disabled(self, "Navigate over elements", "data_list_navigate"))
|
||||||
|
|
||||||
self.lobby_grid:add(get_title(self, "System"))
|
self.lobby_grid:add(get_title(self, "System"))
|
||||||
self.lobby_grid:add(get_button_disabled(self, "Styles"))
|
self.lobby_grid:add(get_button_disabled(self, "Styles"))
|
||||||
|
@ -70,7 +70,7 @@ nodes {
|
|||||||
nodes {
|
nodes {
|
||||||
position {
|
position {
|
||||||
x: 0.0
|
x: 0.0
|
||||||
y: 0.0
|
y: 380.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
@ -81,14 +81,14 @@ nodes {
|
|||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
scale {
|
scale {
|
||||||
x: 1.0
|
x: 0.75
|
||||||
y: 1.0
|
y: 0.75
|
||||||
z: 1.0
|
z: 1.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
size {
|
size {
|
||||||
x: 200.0
|
x: 700.0
|
||||||
y: 100.0
|
y: 60.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
@ -100,9 +100,9 @@ nodes {
|
|||||||
}
|
}
|
||||||
type: TYPE_TEXT
|
type: TYPE_TEXT
|
||||||
blend_mode: BLEND_MODE_ALPHA
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
text: "Hello!"
|
text: "Data List with vertical Dynamic Grid:"
|
||||||
font: "game"
|
font: "game"
|
||||||
id: "text_hint"
|
id: "text_hint_vertical"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_CENTER
|
||||||
@ -130,6 +130,407 @@ nodes {
|
|||||||
text_leading: 1.0
|
text_leading: 1.0
|
||||||
text_tracking: 0.0
|
text_tracking: 0.0
|
||||||
}
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 0.0
|
||||||
|
y: 350.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: 250.0
|
||||||
|
y: 450.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: "data_list_vertical"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_N
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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: 250.0
|
||||||
|
y: 450.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: "data_list_vertical_content"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_N
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "data_list_vertical"
|
||||||
|
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: -162.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: 700.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_TEXT
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
text: "Data List with horizontal Dynamic Grid:"
|
||||||
|
font: "game"
|
||||||
|
id: "text_hint_horizontal"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
outline {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
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: "root"
|
||||||
|
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
|
||||||
|
y: -200.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: 600.0
|
||||||
|
y: 120.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: "data_list_horizontal"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_N
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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: -300.0
|
||||||
|
y: -60.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: 600.0
|
||||||
|
y: 120.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: "data_list_horizontal_content"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_W
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "data_list_horizontal"
|
||||||
|
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: 636.0
|
||||||
|
y: -78.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: 200.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: "prefab"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
layer: "image"
|
||||||
|
inherit_alpha: true
|
||||||
|
slice9 {
|
||||||
|
x: 20.0
|
||||||
|
y: 10.0
|
||||||
|
z: 20.0
|
||||||
|
w: 20.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: 200.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: "Record 1"
|
||||||
|
font: "game"
|
||||||
|
id: "text"
|
||||||
|
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: "prefab"
|
||||||
|
layer: "text"
|
||||||
|
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
|
||||||
|
}
|
||||||
layers {
|
layers {
|
||||||
name: "image"
|
name: "image"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,77 @@
|
|||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
|
||||||
|
|
||||||
|
local buttons = {
|
||||||
|
"button_blue",
|
||||||
|
"button_red",
|
||||||
|
"button_green",
|
||||||
|
"button_yellow",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local function create_vertical(self, data, index, data_list)
|
||||||
|
local instance = gui.clone_tree(self.prefab)
|
||||||
|
gui.set_enabled(instance["prefab"], true)
|
||||||
|
gui.set_text(instance["text"], "Record " .. data)
|
||||||
|
|
||||||
|
gui.set_size(instance["prefab"], vmath.vector3(200, 50 + math.random(100), 0))
|
||||||
|
gui.play_flipbook(instance["prefab"], buttons[math.random(#buttons)])
|
||||||
|
|
||||||
|
-- Since we have only 1 component, we can return this one
|
||||||
|
-- If we have several components, we should create custom component to
|
||||||
|
-- union them all
|
||||||
|
local button = self.druid:new_button(instance["prefab"], function()
|
||||||
|
print("Data list element click on", data)
|
||||||
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
|
return instance["prefab"], button
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function create_horizontal(self, data, index, data_list)
|
||||||
|
local instance = gui.clone_tree(self.prefab)
|
||||||
|
gui.set_enabled(instance["prefab"], true)
|
||||||
|
gui.set_text(instance["text"], "N. " .. data)
|
||||||
|
|
||||||
|
gui.set_size(instance["prefab"], vmath.vector3(120 + math.random(100), 80, 0))
|
||||||
|
gui.play_flipbook(instance["prefab"], buttons[math.random(#buttons)])
|
||||||
|
|
||||||
|
local button = self.druid:new_button(instance["prefab"], function()
|
||||||
|
print("Data list element click on", data)
|
||||||
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
|
return instance["prefab"], button
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
|
|
||||||
|
self.data_set = {}
|
||||||
|
for i = 1, 9999 do
|
||||||
|
table.insert(self.data_set, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.prefab = gui.get_node("prefab")
|
||||||
|
gui.set_enabled(self.prefab, false)
|
||||||
|
|
||||||
|
|
||||||
|
local scroll_vertical = self.druid:new_scroll("data_list_vertical", "data_list_vertical_content")
|
||||||
|
:set_horizontal_scroll(false)
|
||||||
|
local grid_vertical = self.druid:new_dynamic_grid("data_list_vertical_content")
|
||||||
|
|
||||||
|
self.data_list_vertical = self.druid:new_data_list(scroll_vertical, grid_vertical, create_vertical)
|
||||||
|
self.data_list_vertical:set_data(self.data_set)
|
||||||
|
|
||||||
|
|
||||||
|
local scroll_horizontal = self.druid:new_scroll("data_list_horizontal", "data_list_horizontal_content")
|
||||||
|
:set_vertical_scroll(false)
|
||||||
|
local grid_horizontal = self.druid:new_dynamic_grid("data_list_horizontal_content")
|
||||||
|
|
||||||
|
self.data_list_horizontal = self.druid:new_data_list(scroll_horizontal, grid_horizontal, create_horizontal)
|
||||||
|
self.data_list_horizontal:set_data(self.data_set)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
|
||||||
|
|
||||||
local function create_vertical_element(self, data, index)
|
local function create_vertical_element(self, data, index, data_list)
|
||||||
local instance = gui.clone_tree(self.prefab)
|
local instance = gui.clone_tree(self.prefab)
|
||||||
gui.set_enabled(instance["prefab"], true)
|
gui.set_enabled(instance["prefab"], true)
|
||||||
gui.set_text(instance["text"], "Record " .. data)
|
gui.set_text(instance["text"], "Record " .. data)
|
||||||
@ -12,12 +12,13 @@ local function create_vertical_element(self, data, index)
|
|||||||
local button = self.druid:new_button(instance["prefab"], function()
|
local button = self.druid:new_button(instance["prefab"], function()
|
||||||
print("Data list element click on", data)
|
print("Data list element click on", data)
|
||||||
end)
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
return instance["prefab"], button
|
return instance["prefab"], button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function create_horizontal_element(self, data, index)
|
local function create_horizontal_element(self, data, index, data_list)
|
||||||
local instance = gui.clone_tree(self.prefab_square)
|
local instance = gui.clone_tree(self.prefab_square)
|
||||||
gui.set_enabled(instance["prefab_square"], true)
|
gui.set_enabled(instance["prefab_square"], true)
|
||||||
gui.set_text(instance["text_square"], data)
|
gui.set_text(instance["text_square"], data)
|
||||||
@ -25,12 +26,13 @@ local function create_horizontal_element(self, data, index)
|
|||||||
local button = self.druid:new_button(instance["prefab_square"], function()
|
local button = self.druid:new_button(instance["prefab_square"], function()
|
||||||
print("Data list element click on", data)
|
print("Data list element click on", data)
|
||||||
end)
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
return instance["prefab_square"], button
|
return instance["prefab_square"], button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function create_matrix_element(self, data, index)
|
local function create_matrix_element(self, data, index, data_list)
|
||||||
local instance = gui.clone_tree(self.prefab_square)
|
local instance = gui.clone_tree(self.prefab_square)
|
||||||
gui.set_enabled(instance["prefab_square"], true)
|
gui.set_enabled(instance["prefab_square"], true)
|
||||||
gui.set_text(instance["text_square"], data)
|
gui.set_text(instance["text_square"], data)
|
||||||
@ -38,6 +40,7 @@ local function create_matrix_element(self, data, index)
|
|||||||
local button = self.druid:new_button(instance["prefab_square"], function()
|
local button = self.druid:new_button(instance["prefab_square"], function()
|
||||||
print("Data list element click on", data)
|
print("Data list element click on", data)
|
||||||
end)
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
return instance["prefab_square"], button
|
return instance["prefab_square"], button
|
||||||
end
|
end
|
||||||
@ -65,7 +68,7 @@ function init(self)
|
|||||||
|
|
||||||
-- We pass already created scroll and grid components with create function
|
-- We pass already created scroll and grid components with create function
|
||||||
self.data_list_vertical = self.druid:new_data_list(scroll_vertical, grid_vertical, create_vertical_element)
|
self.data_list_vertical = self.druid:new_data_list(scroll_vertical, grid_vertical, create_vertical_element)
|
||||||
:set_data(self.data_set)
|
self.data_list_vertical:set_data(self.data_set)
|
||||||
|
|
||||||
|
|
||||||
local scroll_horizontal = self.druid:new_scroll("data_list_horizontal", "data_list_horizontal_content")
|
local scroll_horizontal = self.druid:new_scroll("data_list_horizontal", "data_list_horizontal_content")
|
||||||
@ -73,7 +76,7 @@ function init(self)
|
|||||||
local grid_horizontal = self.druid:new_static_grid("data_list_horizontal_content", "prefab_square", 999)
|
local grid_horizontal = self.druid:new_static_grid("data_list_horizontal_content", "prefab_square", 999)
|
||||||
|
|
||||||
self.data_list_horizontal = self.druid:new_data_list(scroll_horizontal, grid_horizontal, create_horizontal_element)
|
self.data_list_horizontal = self.druid:new_data_list(scroll_horizontal, grid_horizontal, create_horizontal_element)
|
||||||
:set_data(self.data_set)
|
self.data_list_horizontal:set_data(self.data_set)
|
||||||
|
|
||||||
|
|
||||||
local scroll_matrix = self.druid:new_scroll("data_list_matrix_vertical", "data_list_matrix_vertical_content")
|
local scroll_matrix = self.druid:new_scroll("data_list_matrix_vertical", "data_list_matrix_vertical_content")
|
||||||
@ -81,7 +84,7 @@ function init(self)
|
|||||||
local grid_matrix = self.druid:new_static_grid("data_list_matrix_vertical_content", "prefab_square", 3)
|
local grid_matrix = self.druid:new_static_grid("data_list_matrix_vertical_content", "prefab_square", 3)
|
||||||
|
|
||||||
self.data_list_matrix = self.druid:new_data_list(scroll_matrix, grid_matrix, create_matrix_element)
|
self.data_list_matrix = self.druid:new_data_list(scroll_matrix, grid_matrix, create_matrix_element)
|
||||||
:set_data(self.data_set)
|
self.data_list_matrix:set_data(self.data_set)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,180 +1,48 @@
|
|||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
|
||||||
|
|
||||||
local function create_infinity_instance(self, record, index)
|
local function create_function(self, data, index, data_list)
|
||||||
local instance = gui.clone_tree(self.infinity_prefab)
|
-- In data list create funtion we made all init stuff for this node
|
||||||
gui.set_enabled(instance["infinity_prefab"], true)
|
local nodes = gui.clone_tree(self.prefab)
|
||||||
gui.set_text(instance["infinity_text"], "Record " .. record)
|
local root = nodes["prefab"]
|
||||||
|
gui.set_enabled(root, true)
|
||||||
|
gui.set_enabled(nodes["checkbox"], data.is_checked)
|
||||||
|
gui.set_text(nodes["text"], "Record " .. data.value)
|
||||||
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab"], function()
|
-- Since we have only 1 component, we can return this one
|
||||||
print("Infinity click on", record)
|
-- If we have several components, we should create custom component to
|
||||||
self.infinity_list:add(self.infinity_list:get_length() + 1)
|
-- union them all
|
||||||
end)
|
local button = self.druid:new_button(root, function()
|
||||||
button.on_long_click:subscribe(function()
|
data.is_checked = not data.is_checked
|
||||||
-- self.infinity_list:remove_by_data(record)
|
gui.set_enabled(nodes["checkbox"], data.is_checked)
|
||||||
end)
|
end)
|
||||||
|
button:set_click_zone(data_list.scroll.view_node)
|
||||||
|
|
||||||
return instance["infinity_prefab"], button
|
-- We should return in this function root node and optionally - Druid component
|
||||||
end
|
return root, button
|
||||||
|
|
||||||
|
|
||||||
local function create_infinity_instance_hor(self, record, index)
|
|
||||||
local instance = gui.clone_tree(self.infinity_prefab)
|
|
||||||
gui.set_enabled(instance["infinity_prefab"], true)
|
|
||||||
gui.set_text(instance["infinity_text"], "Record " .. record)
|
|
||||||
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab"], function()
|
|
||||||
print("Infinity click on", record)
|
|
||||||
-- self.infinity_list_hor:remove_by_data(record)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return instance["infinity_prefab"], button
|
|
||||||
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"], record)
|
|
||||||
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_small"], function()
|
|
||||||
print("Infinity click on", record)
|
|
||||||
-- self.infinity_list_small:remove_by_data(record)
|
|
||||||
end)
|
|
||||||
button:set_click_zone(self.infinity_scroll_3.view_node)
|
|
||||||
|
|
||||||
return instance["infinity_prefab_small"], button
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function create_infinity_instance_dynamic(self, record, index)
|
|
||||||
local instance = gui.clone_tree(self.infinity_prefab_dynamic)
|
|
||||||
gui.set_enabled(instance["infinity_prefab_dynamic"], true)
|
|
||||||
gui.set_text(instance["infinity_text_dynamic"], "Record " .. record)
|
|
||||||
|
|
||||||
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(200, 60 + index * 3, 0))
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
|
||||||
print("Dynamic click on", record)
|
|
||||||
-- self.infinity_list_dynamic:remove_by_data(record)
|
|
||||||
end)
|
|
||||||
button:set_click_zone(self.infinity_scroll_dynamic.view_node)
|
|
||||||
|
|
||||||
return instance["infinity_prefab_dynamic"], button
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function create_infinity_instance_dynamic_hor(self, record, index)
|
|
||||||
local instance = gui.clone_tree(self.infinity_prefab_dynamic)
|
|
||||||
gui.set_enabled(instance["infinity_prefab_dynamic"], true)
|
|
||||||
gui.set_text(instance["infinity_text_dynamic"], "Record " .. record)
|
|
||||||
|
|
||||||
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(150 + 2 * index, 60, 0))
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
|
||||||
print("Dynamic click on", record)
|
|
||||||
-- self.infinity_list_dynamic_hor:remove_by_data(record)
|
|
||||||
end)
|
|
||||||
button:set_click_zone(self.infinity_scroll_dynamic_hor.view_node)
|
|
||||||
|
|
||||||
return instance["infinity_prefab_dynamic"], button
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function setup_infinity_list(self)
|
|
||||||
local data = {}
|
|
||||||
for i = 1, 50 do
|
|
||||||
table.insert(data, i)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.infinity_list = self.druid:new_data_list(self.infinity_scroll, self.infinity_grid, function(self, record, index)
|
|
||||||
-- function should return gui_node, [druid_component]
|
|
||||||
local root, button = create_infinity_instance(self, record, index)
|
|
||||||
button:set_click_zone(self.infinity_scroll.view_node)
|
|
||||||
return root, button
|
|
||||||
end):set_data(data)
|
|
||||||
|
|
||||||
self.infinity_list_hor = self.druid:new_data_list(self.infinity_scroll_hor, self.infinity_grid_hor, function(self, record, index)
|
|
||||||
-- function should return gui_node, [druid_component]
|
|
||||||
local root, button = create_infinity_instance_hor(self, record, index)
|
|
||||||
button:set_click_zone(self.infinity_scroll_hor.view_node)
|
|
||||||
return root, button
|
|
||||||
end):set_data(data)
|
|
||||||
|
|
||||||
-- scroll to some index
|
|
||||||
-- local pos = self.infinity_grid:get_pos(25)
|
|
||||||
-- self.infinity_scroll:scroll_to(pos, true)
|
|
||||||
timer.delay(1, false, function()
|
|
||||||
-- self.infinity_list:scroll_to_index(25)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
self.infinity_list_small = self.druid:new_data_list(self.infinity_scroll_3, self.infinity_grid_3, function(self, record, index)
|
|
||||||
-- function should return gui_node, [druid_component]
|
|
||||||
return create_infinity_instance_small(self, record, index)
|
|
||||||
end):set_data(data)
|
|
||||||
|
|
||||||
self.infinity_list_dynamic = self.druid:new_data_list(self.infinity_scroll_dynamic, self.infinity_grid_dynamic, function(self, record, index)
|
|
||||||
-- function should return gui_node, [druid_component]
|
|
||||||
return create_infinity_instance_dynamic(self, record, index)
|
|
||||||
end):set_data(data)
|
|
||||||
|
|
||||||
timer.delay(1, false, function()
|
|
||||||
-- self.infinity_list_dynamic:scroll_to_index(25)
|
|
||||||
end)
|
|
||||||
|
|
||||||
self.infinity_list_dynamic_hor = self.druid:new_data_list(self.infinity_scroll_dynamic_hor, self.infinity_grid_dynamic_hor, function(self, record, index)
|
|
||||||
-- function should return gui_node, [druid_component]
|
|
||||||
return create_infinity_instance_dynamic_hor(self, record, index)
|
|
||||||
end):set_data(data)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function toggle_stencil(self)
|
|
||||||
self._is_stencil = not self._is_stencil
|
|
||||||
local mode = self._is_stencil and gui.CLIPPING_MODE_STENCIL or gui.CLIPPING_MODE_NONE
|
|
||||||
gui.set_clipping_mode(self.infinity_scroll.view_node, mode)
|
|
||||||
gui.set_clipping_mode(self.infinity_scroll_hor.view_node, mode)
|
|
||||||
gui.set_clipping_mode(self.infinity_scroll_3.view_node, mode)
|
|
||||||
gui.set_clipping_mode(self.infinity_scroll_dynamic.view_node, mode)
|
|
||||||
gui.set_clipping_mode(self.infinity_scroll_dynamic_hor.view_node, mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
self.druid:new_scroll("root", "infinity_page_content")
|
|
||||||
|
|
||||||
self.infinity_prefab = gui.get_node("infinity_prefab")
|
self.prefab = gui.get_node("prefab")
|
||||||
self.infinity_prefab_small = gui.get_node("infinity_prefab_small")
|
gui.set_enabled(self.prefab, false)
|
||||||
self.infinity_prefab_dynamic = gui.get_node("infinity_prefab_dynamic")
|
|
||||||
gui.set_enabled(self.infinity_prefab, false)
|
|
||||||
gui.set_enabled(self.infinity_prefab_small, false)
|
|
||||||
gui.set_enabled(self.infinity_prefab_dynamic, false)
|
|
||||||
|
|
||||||
self.infinity_scroll = self.druid:new_scroll("infinity_scroll_stencil", "infinity_scroll_content")
|
local data = {}
|
||||||
:set_horizontal_scroll(false)
|
|
||||||
self.infinity_grid = self.druid:new_static_grid("infinity_scroll_content", "infinity_prefab", 1)
|
|
||||||
|
|
||||||
self.infinity_scroll_hor = self.druid:new_scroll("infinity_scroll_stencil_hor", "infinity_scroll_content_hor")
|
for i = 1, 999 do
|
||||||
:set_vertical_scroll(false)
|
table.insert(data, {
|
||||||
self.infinity_grid_hor = self.druid:new_static_grid("infinity_scroll_content_hor", "infinity_prefab", 999)
|
is_checked = false,
|
||||||
|
value = i
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
self.infinity_scroll_3 = self.druid:new_scroll("infinity_scroll_3_stencil", "infinity_scroll_3_content")
|
self.scroll = self.druid:new_scroll("data_list_view", "data_list_content")
|
||||||
:set_horizontal_scroll(false)
|
self.scroll:set_horizontal_scroll(false)
|
||||||
self.infinity_grid_3 = self.druid:new_static_grid("infinity_scroll_3_content", "infinity_prefab_small", 3)
|
self.grid = self.druid:new_static_grid("data_list_content", "prefab", 1)
|
||||||
|
self.data_list = self.druid:new_data_list(self.scroll, self.grid, create_function)
|
||||||
self.infinity_scroll_dynamic = self.druid:new_scroll("infinity_scroll_stencil_dynamic", "infinity_scroll_content_dynamic")
|
self.data_list:set_data(data)
|
||||||
:set_horizontal_scroll(false)
|
|
||||||
self.infinity_grid_dynamic = self.druid:new_dynamic_grid("infinity_scroll_content_dynamic")
|
|
||||||
|
|
||||||
self.infinity_scroll_dynamic_hor = self.druid:new_scroll("infinity_scroll_stencil_dynamic_hor", "infinity_scroll_content_dynamic_hor")
|
|
||||||
:set_vertical_scroll(false)
|
|
||||||
self.infinity_grid_dynamic_hor = self.druid:new_dynamic_grid("infinity_scroll_content_dynamic_hor")
|
|
||||||
|
|
||||||
self._is_stencil = true
|
|
||||||
self.druid:new_button("button_toggle_stencil/button", toggle_stencil)
|
|
||||||
|
|
||||||
setup_infinity_list(self)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user