Add vertical dynamic grid to example

This commit is contained in:
Insality 2020-09-27 18:59:54 +03:00
parent f25a8acd95
commit 5c4497330c
2 changed files with 198 additions and 7 deletions

View File

@ -10644,14 +10644,14 @@ nodes {
w: 1.0 w: 1.0
} }
color { color {
x: 0.9019608 x: 0.6
y: 0.9019608 y: 0.3019608
z: 0.7019608 z: 0.4
w: 1.0 w: 1.0
} }
type: TYPE_BOX type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty" texture: ""
id: "grid_dynamic_nodes" id: "grid_dynamic_nodes"
xanchor: XANCHOR_NONE xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE yanchor: YANCHOR_NONE
@ -10728,6 +10728,171 @@ nodes {
template_node_child: false template_node_child: false
size_mode: SIZE_MODE_MANUAL size_mode: SIZE_MODE_MANUAL
} }
nodes {
position {
x: -250.0
y: -1236.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: 500.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 0.9019608
y: 0.9019608
z: 0.7019608
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: ""
id: "grid_dynamic_hor_view"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_W
adjust_mode: ADJUST_MODE_FIT
parent: "grid_page_content"
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: 500.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 0.4
y: 0.3019608
z: 0.7019608
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: ""
id: "grid_dynamic_hor_nodes"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_W
adjust_mode: ADJUST_MODE_FIT
parent: "grid_dynamic_hor_view"
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: -1232.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: 100.0
y: 80.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_red"
id: "grid_dynamic_hor_prefab"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "grid_page_content"
layer: ""
inherit_alpha: true
slice9 {
x: 20.0
y: 20.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 { nodes {
position { position {
x: 0.0 x: 0.0

View File

@ -3,12 +3,12 @@ local druid_const = require("druid.const")
local M = {} local M = {}
local function remove_node(self, button) local function remove_node(self, button, is_shift)
gui.delete_node(button.node) gui.delete_node(button.node)
self.druid:remove(button) self.druid:remove(button)
local index = self.grid_nodes:get_index_by_node(button.node) local index = self.grid_nodes:get_index_by_node(button.node)
self.grid_nodes:remove(index, true) self.grid_nodes:remove(index, is_shift)
for i = 1, #self.grid_node_buttons do for i = 1, #self.grid_node_buttons do
if self.grid_node_buttons[i] == button then if self.grid_node_buttons[i] == button then
table.remove(self.grid_node_buttons, i) table.remove(self.grid_node_buttons, i)
@ -25,8 +25,12 @@ local function add_node(self, index)
gui.set_enabled(cloned["grid_nodes_prefab"], true) gui.set_enabled(cloned["grid_nodes_prefab"], true)
local button = self.druid:new_button(cloned["grid_nodes_prefab"], function(_, params, button) local button = self.druid:new_button(cloned["grid_nodes_prefab"], function(_, params, button)
remove_node(self, button, true)
end)
button.on_long_click:subscribe(function()
remove_node(self, button) remove_node(self, button)
end) end)
table.insert(self.grid_node_buttons, button) table.insert(self.grid_node_buttons, button)
self.grid_nodes:add(cloned["grid_nodes_prefab"], index) self.grid_nodes:add(cloned["grid_nodes_prefab"], index)
@ -78,17 +82,37 @@ local function add_node_dynamic(self, index)
end end
local function add_node_dynamic_hor(self, index)
local node = gui.clone(self.prefab_hor_dynamic)
gui.set_enabled(node, true)
gui.set_size(node, vmath.vector3(80 + math.random(0, 80), 80, 0))
self.dynamic_hor_grid:add(node)
end
local function init_dynamic_grid(self) local function init_dynamic_grid(self)
self.dynamic_grid = self.druid:new_dynamic_grid("grid_dynamic_nodes") self.dynamic_grid = self.druid:new_dynamic_grid("grid_dynamic_nodes")
self.prefab_dynamic = gui.get_node("grid_dynamic_prefab") self.prefab_dynamic = gui.get_node("grid_dynamic_prefab")
gui.set_enabled(self.prefab_dynamic, false) gui.set_enabled(self.prefab_dynamic, false)
for i = 1, 8 do for i = 1, 10 do
add_node_dynamic(self, i) add_node_dynamic(self, i)
end end
self.grid_dynamic_scroll:set_size(self.dynamic_grid:get_size()) self.grid_dynamic_scroll:set_size(self.dynamic_grid:get_size())
self.dynamic_hor_grid = self.druid:new_dynamic_grid("grid_dynamic_hor_nodes")
self.prefab_hor_dynamic = gui.get_node("grid_dynamic_hor_prefab")
gui.set_enabled(self.prefab_hor_dynamic, false)
for i = 1, 10 do
add_node_dynamic_hor(self, i)
end
self.grid_dynamic_hor_scroll:set_size(self.dynamic_hor_grid:get_size())
end end
@ -99,6 +123,8 @@ function M.setup_page(self)
:set_horizontal_scroll(false) :set_horizontal_scroll(false)
self.grid_dynamic_scroll = self.druid:new_scroll("grid_dynamic_view", "grid_dynamic_nodes") self.grid_dynamic_scroll = self.druid:new_scroll("grid_dynamic_view", "grid_dynamic_nodes")
:set_horizontal_scroll(false) :set_horizontal_scroll(false)
self.grid_dynamic_hor_scroll = self.druid:new_scroll("grid_dynamic_hor_view", "grid_dynamic_hor_nodes")
:set_vertical_scroll(false)
init_static_grid(self) init_static_grid(self)
init_dynamic_grid(self) init_dynamic_grid(self)