mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Move all examples to separate collections
This commit is contained in:
37
example/examples/general/data_list/data_list.collection
Normal file
37
example/examples/general/data_list/data_list.collection
Normal file
@@ -0,0 +1,37 @@
|
||||
name: "data_list"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"data_list\"\n"
|
||||
" component: \"/example/examples/general/data_list/data_list.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
1260
example/examples/general/data_list/data_list.gui
Normal file
1260
example/examples/general/data_list/data_list.gui
Normal file
File diff suppressed because it is too large
Load Diff
198
example/examples/general/data_list/data_list.gui_script
Normal file
198
example/examples/general/data_list/data_list.gui_script
Normal file
@@ -0,0 +1,198 @@
|
||||
local druid = require("druid.druid")
|
||||
|
||||
|
||||
local function create_infinity_instance(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:add(self.infinity_list:get_length() + 1)
|
||||
end)
|
||||
button.on_long_click:subscribe(function()
|
||||
-- self.infinity_list:remove_by_data(record)
|
||||
end)
|
||||
|
||||
return instance["infinity_prefab"], button
|
||||
end
|
||||
|
||||
|
||||
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(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(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(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(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(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
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
self.druid:new_scroll("root", "infinity_page_content")
|
||||
|
||||
self.infinity_prefab = gui.get_node("infinity_prefab")
|
||||
self.infinity_prefab_small = gui.get_node("infinity_prefab_small")
|
||||
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")
|
||||
: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")
|
||||
:set_vertical_scroll(false)
|
||||
self.infinity_grid_hor = self.druid:new_static_grid("infinity_scroll_content_hor", "infinity_prefab", 999)
|
||||
|
||||
self.infinity_scroll_3 = self.druid:new_scroll("infinity_scroll_3_stencil", "infinity_scroll_3_content")
|
||||
:set_horizontal_scroll(false)
|
||||
self.infinity_grid_3 = self.druid:new_static_grid("infinity_scroll_3_content", "infinity_prefab_small", 3)
|
||||
|
||||
self.infinity_scroll_dynamic = self.druid:new_scroll("infinity_scroll_stencil_dynamic", "infinity_scroll_content_dynamic")
|
||||
: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
|
||||
|
||||
|
||||
function final(self)
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
self.druid:update(dt)
|
||||
end
|
||||
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
self.druid:on_message(message_id, message, sender)
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
return self.druid:on_input(action_id, action)
|
||||
end
|
@@ -1,10 +1,10 @@
|
||||
name: "template"
|
||||
name: "grid"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"overview\"\n"
|
||||
" component: \"/example/examples/general/template/template.gui\"\n"
|
||||
" component: \"/example/examples/general/grid/grid.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
2058
example/examples/general/grid/grid.gui
Normal file
2058
example/examples/general/grid/grid.gui
Normal file
File diff suppressed because it is too large
Load Diff
224
example/examples/general/grid/grid.gui_script
Normal file
224
example/examples/general/grid/grid.gui_script
Normal file
@@ -0,0 +1,224 @@
|
||||
local druid = require("druid.druid")
|
||||
local const = require("druid.const")
|
||||
|
||||
local function simple_animate(node, pos)
|
||||
gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2)
|
||||
end
|
||||
|
||||
|
||||
local function remove_node(self, button, no_shift)
|
||||
gui.delete_node(button.node)
|
||||
|
||||
self.druid:remove(button)
|
||||
local index = self.grid_static_grid:get_index_by_node(button.node)
|
||||
self.grid_static_grid:remove(index, no_shift and const.SHIFT.NO_SHIFT or const.SHIFT.RIGHT)
|
||||
for i = 1, #self.grid_node_buttons do
|
||||
if self.grid_node_buttons[i] == button then
|
||||
table.remove(self.grid_node_buttons, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function add_node(self, index)
|
||||
local prefab = gui.get_node("grid_nodes_prefab")
|
||||
local cloned = gui.clone_tree(prefab)
|
||||
gui.set_enabled(cloned["grid_nodes_prefab"], true)
|
||||
|
||||
local button = self.druid:new_button(cloned["grid_nodes_prefab"], function(_, params, button)
|
||||
remove_node(self, button)
|
||||
end)
|
||||
button.on_long_click:subscribe(function()
|
||||
remove_node(self, button, true)
|
||||
end)
|
||||
button:set_click_zone(self.grid_static_scroll.view_node)
|
||||
|
||||
table.insert(self.grid_node_buttons, button)
|
||||
|
||||
self.grid_static_grid:add(cloned["grid_nodes_prefab"], index)
|
||||
end
|
||||
|
||||
|
||||
local function clear_nodes(self)
|
||||
local nodes = self.grid_static_grid.nodes
|
||||
for i, node in pairs(nodes) do
|
||||
gui.delete_node(node)
|
||||
end
|
||||
|
||||
for i = 1, #self.grid_node_buttons do
|
||||
self.druid:remove(self.grid_node_buttons[i])
|
||||
end
|
||||
self.grid_node_buttons = {}
|
||||
|
||||
self.grid_static_grid:clear()
|
||||
end
|
||||
|
||||
|
||||
local function init_static_grid(self)
|
||||
self.grid_node_buttons = {}
|
||||
gui.set_enabled(gui.get_node("grid_nodes_prefab"), false)
|
||||
|
||||
for i = 1, 15 do
|
||||
add_node(self, i)
|
||||
end
|
||||
|
||||
self.druid:new_button("button_add/button", function()
|
||||
add_node(self)
|
||||
end)
|
||||
self.druid:new_button("button_clear/button", function()
|
||||
clear_nodes(self)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
local function remove_dynamic_node(self, button, shift_policy)
|
||||
gui.delete_node(button.node)
|
||||
|
||||
self.druid:remove(button)
|
||||
local index = self.grid_dynamic_grid:get_index_by_node(button.node)
|
||||
self.grid_dynamic_grid:remove(index, shift_policy)
|
||||
for i = 1, #self.dynamic_node_buttons do
|
||||
if self.dynamic_node_buttons[i] == button then
|
||||
table.remove(self.dynamic_node_buttons, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function add_node_dynamic(self, index, is_shift_left)
|
||||
local node = gui.clone(self.prefab_dynamic)
|
||||
gui.set_color(node, vmath.vector4(math.random() * 0.2 + 0.8))
|
||||
gui.set_enabled(node, true)
|
||||
gui.set_size(node, vmath.vector3(250, math.random(60, 150), 0))
|
||||
self.grid_dynamic_grid:add(node, index, is_shift_left)
|
||||
|
||||
local button = self.druid:new_button(node, function(_, params, button)
|
||||
remove_dynamic_node(self, button)
|
||||
end)
|
||||
button.on_long_click:subscribe(function()
|
||||
remove_dynamic_node(self, button, const.SHIFT.LEFT)
|
||||
end)
|
||||
button:set_click_zone(self.grid_dynamic_scroll.view_node)
|
||||
table.insert(self.dynamic_node_buttons, button)
|
||||
end
|
||||
|
||||
|
||||
local function remove_dynamic_hor_node(self, button, shift_policy)
|
||||
gui.delete_node(button.node)
|
||||
|
||||
self.druid:remove(button)
|
||||
local index = self.grid_dynamic_hor_grid:get_index_by_node(button.node)
|
||||
self.grid_dynamic_hor_grid:remove(index, shift_policy)
|
||||
for i = 1, #self.dynamic_node_hor_buttons do
|
||||
if self.dynamic_node_hor_buttons[i] == button then
|
||||
table.remove(self.dynamic_node_hor_buttons, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function add_node_dynamic_hor(self, index)
|
||||
local node = gui.clone(self.prefab_hor_dynamic)
|
||||
gui.set_color(node, vmath.vector4(math.random() * 0.2 + 0.8))
|
||||
gui.set_enabled(node, true)
|
||||
gui.set_size(node, vmath.vector3(80 + math.random(0, 80), 80, 0))
|
||||
|
||||
local button = self.druid:new_button(node, function(_, params, button)
|
||||
remove_dynamic_hor_node(self, button)
|
||||
end)
|
||||
button.on_long_click:subscribe(function()
|
||||
remove_dynamic_hor_node(self, button, const.SHIFT.LEFT)
|
||||
end)
|
||||
button:set_click_zone(self.grid_dynamic_hor_scroll.view_node)
|
||||
|
||||
self.grid_dynamic_hor_grid:add(node, index)
|
||||
table.insert(self.dynamic_node_hor_buttons, button)
|
||||
end
|
||||
|
||||
|
||||
local function init_dynamic_grid(self)
|
||||
-- Vertical horizontal grid
|
||||
self.dynamic_node_buttons = {}
|
||||
self.dynamic_node_hor_buttons = {}
|
||||
|
||||
self.prefab_dynamic = gui.get_node("grid_dynamic_prefab")
|
||||
gui.set_enabled(self.prefab_dynamic, false)
|
||||
|
||||
for i = 1, 10 do
|
||||
add_node_dynamic(self, i)
|
||||
end
|
||||
self.druid:new_button("button_add_start_dynamic/button", function()
|
||||
local start_index = self.grid_dynamic_grid.first_index or 1
|
||||
add_node_dynamic(self, start_index)
|
||||
end)
|
||||
self.druid:new_button("button_add_end_dynamic/button", function()
|
||||
add_node_dynamic(self)
|
||||
end)
|
||||
|
||||
-- Horizontal dynamic grid
|
||||
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.druid:new_button("button_add_start_dynamic_hor/button", function()
|
||||
local start_index = self.grid_dynamic_hor_grid.first_index or 1
|
||||
add_node_dynamic_hor(self, start_index)
|
||||
end)
|
||||
self.druid:new_button("button_add_end_dynamic_hor/button", function()
|
||||
add_node_dynamic_hor(self)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
self.druid:new_scroll("root", "grid_page_content")
|
||||
|
||||
self.grid_static_grid = self.druid:new_static_grid("grid_nodes", "grid_nodes_prefab", 5)
|
||||
:set_position_function(simple_animate)
|
||||
self.grid_static_scroll = self.druid:new_scroll("grid_nodes_view", "grid_nodes")
|
||||
:set_horizontal_scroll(false)
|
||||
:bind_grid(self.grid_static_grid)
|
||||
|
||||
self.grid_dynamic_grid = self.druid:new_dynamic_grid("grid_dynamic_nodes")
|
||||
:set_position_function(simple_animate)
|
||||
self.grid_dynamic_scroll = self.druid:new_scroll("grid_dynamic_view", "grid_dynamic_nodes")
|
||||
:set_horizontal_scroll(false)
|
||||
:bind_grid(self.grid_dynamic_grid)
|
||||
|
||||
self.grid_dynamic_hor_grid = self.druid:new_dynamic_grid("grid_dynamic_hor_nodes")
|
||||
:set_position_function(simple_animate)
|
||||
self.grid_dynamic_hor_scroll = self.druid:new_scroll("grid_dynamic_hor_view", "grid_dynamic_hor_nodes")
|
||||
:set_vertical_scroll(false)
|
||||
:bind_grid(self.grid_dynamic_hor_grid)
|
||||
|
||||
init_static_grid(self)
|
||||
init_dynamic_grid(self)
|
||||
end
|
||||
|
||||
|
||||
function final(self)
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
self.druid:update(dt)
|
||||
end
|
||||
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
self.druid:on_message(message_id, message, sender)
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
return self.druid:on_input(action_id, action)
|
||||
end
|
37
example/examples/general/input/input.collection
Normal file
37
example/examples/general/input/input.collection
Normal file
@@ -0,0 +1,37 @@
|
||||
name: "input"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"overview\"\n"
|
||||
" component: \"/example/examples/general/input/input.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
1022
example/examples/general/input/input.gui
Normal file
1022
example/examples/general/input/input.gui
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,12 @@ local druid = require("druid.druid")
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
self.druid:new_input("input_box_usual", "input_text_usual")
|
||||
self.druid:new_input("input_box_password", "input_text_password", gui.KEYBOARD_TYPE_PASSWORD)
|
||||
self.druid:new_input("input_box_email", "input_text_email", gui.KEYBOARD_TYPE_EMAIL)
|
||||
self.druid:new_input("input_box_numpad", "input_text_numpad", gui.KEYBOARD_TYPE_NUMBER_PAD)
|
||||
:set_allowed_characters("[%d,.]")
|
||||
end
|
||||
|
||||
|
37
example/examples/general/scroll/scroll.collection
Normal file
37
example/examples/general/scroll/scroll.collection
Normal file
@@ -0,0 +1,37 @@
|
||||
name: "scroll"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"scroll\"\n"
|
||||
" component: \"/example/examples/general/scroll/scroll.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
2092
example/examples/general/scroll/scroll.gui
Normal file
2092
example/examples/general/scroll/scroll.gui
Normal file
File diff suppressed because it is too large
Load Diff
90
example/examples/general/scroll/scroll.gui_script
Normal file
90
example/examples/general/scroll/scroll.gui_script
Normal file
@@ -0,0 +1,90 @@
|
||||
local druid = require("druid.druid")
|
||||
|
||||
|
||||
local function init_scroll_with_grid(self)
|
||||
local prefab = gui.get_node("grid_prefab")
|
||||
|
||||
local grid_scroll = self.druid:new_scroll("scroll_with_grid_size", "grid_content")
|
||||
local grid = self.druid:new_static_grid("grid_content", "grid_prefab", 20)
|
||||
|
||||
for i = 1, 40 do
|
||||
local clone_prefab = gui.clone_tree(prefab)
|
||||
|
||||
grid:add(clone_prefab["grid_prefab"])
|
||||
gui.set_text(clone_prefab["grid_prefab_text"], "Node " .. i)
|
||||
|
||||
local button = self.druid:new_button(clone_prefab["grid_button"], function()
|
||||
local position = gui.get_position(clone_prefab["grid_prefab"])
|
||||
grid_scroll:scroll_to(position)
|
||||
end)
|
||||
button:set_click_zone(gui.get_node("scroll_with_grid_size"))
|
||||
end
|
||||
|
||||
gui.set_enabled(prefab, false)
|
||||
|
||||
grid_scroll:set_size(grid:get_size())
|
||||
|
||||
local scroll_slider = self.druid:new_slider("grid_scroll_pin", vmath.vector3(287, 0, 0), function(_, value)
|
||||
grid_scroll:scroll_to_percent(vmath.vector3(value, 0, 0), true)
|
||||
end)
|
||||
|
||||
grid_scroll.on_scroll:subscribe(function(_, point)
|
||||
scroll_slider:set(grid_scroll:get_percent().x, true)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
-- Usual scroll for whole page
|
||||
self.druid:new_scroll("root", "scroll_page_content")
|
||||
|
||||
-- Simple scroll with no adjust
|
||||
self.druid:new_scroll("simple_scroll_input", "simple_scroll_content")
|
||||
|
||||
-- Scroll with grid example
|
||||
init_scroll_with_grid(self)
|
||||
|
||||
-- Scroll contain children scrolls:
|
||||
-- Parent scroll
|
||||
self.druid:new_scroll("children_scroll", "children_scroll_content")
|
||||
-- Childre scrolls
|
||||
self.druid:new_scroll("children_scroll_1", "children_scroll_content_1")
|
||||
self.druid:new_scroll("children_scroll_2", "children_scroll_content_2")
|
||||
self.druid:new_scroll("children_scroll_3", "children_scroll_content_3")
|
||||
|
||||
-- Content with less size than view
|
||||
self.druid:new_scroll("scroll_smaller_view", "scroll_smaller_content")
|
||||
:set_extra_stretch_size(0)
|
||||
:set_inert(false)
|
||||
|
||||
-- Scroll with points of interests
|
||||
self.druid:new_scroll("scroll_with_points", "scroll_with_points_content")
|
||||
:set_points({
|
||||
vmath.vector3(300, 0, 0),
|
||||
vmath.vector3(900, 0, 0),
|
||||
vmath.vector3(1500, 0, 0),
|
||||
vmath.vector3(2100, 0, 0),
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
function final(self)
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
self.druid:update(dt)
|
||||
end
|
||||
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
self.druid:on_message(message_id, message, sender)
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
return self.druid:on_input(action_id, action)
|
||||
end
|
@@ -1,141 +0,0 @@
|
||||
script: "/example/examples/general/template/template.gui_script"
|
||||
fonts {
|
||||
name: "game"
|
||||
font: "/example/assets/fonts/game.font"
|
||||
}
|
||||
textures {
|
||||
name: "kenney"
|
||||
texture: "/example/assets/images/kenney.atlas"
|
||||
}
|
||||
background_color {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 300.0
|
||||
y: 415.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: 830.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/empty"
|
||||
id: "root"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
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: 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: 200.0
|
||||
y: 100.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: "Hello!"
|
||||
font: "game"
|
||||
id: "text_hint"
|
||||
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
|
||||
}
|
||||
layers {
|
||||
name: "image"
|
||||
}
|
||||
layers {
|
||||
name: "text"
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||
max_nodes: 512
|
Reference in New Issue
Block a user