mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update example with new brand one
This commit is contained in:
190
example/examples/layout/basic/basic_layout.gui
Normal file
190
example/examples/layout/basic/basic_layout.gui
Normal file
@@ -0,0 +1,190 @@
|
||||
script: ""
|
||||
textures {
|
||||
name: "druid"
|
||||
texture: "/example/assets/druid.atlas"
|
||||
}
|
||||
background_color {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
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: 500.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.173
|
||||
y: 0.184
|
||||
z: 0.204
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "druid/ui_circle_64"
|
||||
id: "root"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: true
|
||||
material: ""
|
||||
}
|
||||
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: 500.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: "druid/empty"
|
||||
id: "layout"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
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_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: false
|
||||
material: ""
|
||||
}
|
||||
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: 70.0
|
||||
y: 40.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.631
|
||||
y: 0.843
|
||||
z: 0.961
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "druid/ui_circle_16"
|
||||
id: "prefab"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "layout"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 8.0
|
||||
y: 8.0
|
||||
z: 8.0
|
||||
w: 8.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: false
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
enabled: true
|
||||
visible: true
|
||||
material: ""
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||
max_nodes: 512
|
76
example/examples/layout/basic/basic_layout.lua
Normal file
76
example/examples/layout/basic/basic_layout.lua
Normal file
@@ -0,0 +1,76 @@
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
local layout = require("druid.extended.layout")
|
||||
|
||||
---@class basic_layout: druid.base_component
|
||||
---@field druid druid_instance
|
||||
---@field root node
|
||||
local M = component.create("basic_layout")
|
||||
|
||||
local PIVOTS = {
|
||||
gui.PIVOT_CENTER,
|
||||
gui.PIVOT_N,
|
||||
gui.PIVOT_NE,
|
||||
gui.PIVOT_E,
|
||||
gui.PIVOT_SE,
|
||||
gui.PIVOT_S,
|
||||
gui.PIVOT_SW,
|
||||
gui.PIVOT_W,
|
||||
gui.PIVOT_NW,
|
||||
}
|
||||
|
||||
|
||||
---@param template string
|
||||
---@param nodes table<hash, node>
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
|
||||
self.root = self:get_node("root")
|
||||
self.layout = self.druid:new(layout, "layout", "horizontal_wrap")
|
||||
|
||||
self.prefab = self:get_node("prefab")
|
||||
gui.set_enabled(self.prefab, false)
|
||||
local default_size = gui.get_size(self.prefab)
|
||||
|
||||
self.nodes = {}
|
||||
|
||||
for _ = 1, 12 do
|
||||
local node = gui.clone(self.prefab)
|
||||
|
||||
-- Set different size for some nodes
|
||||
if math.random() > 0.5 then
|
||||
local size = vmath.vector3(default_size.x * 2, default_size.y, 0)
|
||||
gui.set_size(node, size)
|
||||
end
|
||||
|
||||
-- Set random pivot point for each node
|
||||
local pivot = PIVOTS[math.random(1, #PIVOTS)]
|
||||
gui.set_pivot(node, pivot)
|
||||
|
||||
gui.set_enabled(node, true)
|
||||
self.layout:add(node)
|
||||
table.insert(self.nodes, node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M:set_pivot(pivot)
|
||||
local offset = helper.get_pivot_offset(pivot)
|
||||
local size = gui.get_size(self.root)
|
||||
local pos = vmath.vector3(size.x * offset.x, size.y * offset.y, 0)
|
||||
gui.set_position(self.layout.node, pos)
|
||||
gui.set_pivot(self.layout.node, pivot)
|
||||
|
||||
self.layout:refresh_layout()
|
||||
end
|
||||
|
||||
|
||||
function M:on_remove()
|
||||
self.layout:clear_layout()
|
||||
for _, node in ipairs(self.nodes) do
|
||||
gui.delete_node(node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
91
example/examples/layout/examples_list.lua
Normal file
91
example/examples/layout/examples_list.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
local M = {}
|
||||
|
||||
---@return druid.example.data[]
|
||||
function M.get_examples()
|
||||
---@type druid.example.data[]
|
||||
return {
|
||||
{
|
||||
name_id = "ui_example_layout_basic",
|
||||
information_text_id = "ui_example_layout_basic_description",
|
||||
template = "basic_layout",
|
||||
root = "basic_layout/root",
|
||||
code_url = "example/examples/layout/basic/basic_layout.lua",
|
||||
component_class = require("example.examples.layout.basic.basic_layout"),
|
||||
properties_control = function(instance, properties_panel)
|
||||
---@cast instance basic_layout
|
||||
|
||||
properties_panel:add_slider("ui_padding", 0, function(value)
|
||||
local padding = math.floor((value * 64) * 100) / 100
|
||||
instance.layout:set_padding(vmath.vector4(padding))
|
||||
end)
|
||||
|
||||
properties_panel:add_slider("ui_margin_x", 0, function(value)
|
||||
local margin = math.floor((value * 64) * 100) / 100
|
||||
instance.layout:set_margin(margin, nil)
|
||||
end)
|
||||
|
||||
properties_panel:add_slider("ui_margin_y", 0, function(value)
|
||||
local margin = math.floor((value * 64) * 100) / 100
|
||||
instance.layout:set_margin(nil, margin)
|
||||
end)
|
||||
|
||||
properties_panel:add_checkbox("ui_justify", false, function(value)
|
||||
instance.layout:set_justify(value)
|
||||
end)
|
||||
|
||||
local pivot_index = 1
|
||||
local pivot_list = {
|
||||
gui.PIVOT_CENTER,
|
||||
gui.PIVOT_W,
|
||||
gui.PIVOT_SW,
|
||||
gui.PIVOT_S,
|
||||
gui.PIVOT_SE,
|
||||
gui.PIVOT_E,
|
||||
gui.PIVOT_NE,
|
||||
gui.PIVOT_N,
|
||||
gui.PIVOT_NW,
|
||||
}
|
||||
|
||||
properties_panel:add_button("ui_pivot_next", function()
|
||||
pivot_index = pivot_index + 1
|
||||
if pivot_index > #pivot_list then
|
||||
pivot_index = 1
|
||||
end
|
||||
instance:set_pivot(pivot_list[pivot_index])
|
||||
end)
|
||||
|
||||
|
||||
local type_index = 1
|
||||
local type_list = {
|
||||
"horizontal_wrap",
|
||||
"horizontal",
|
||||
"vertical",
|
||||
}
|
||||
|
||||
properties_panel:add_button("ui_type_next", function()
|
||||
type_index = type_index + 1
|
||||
if type_index > #type_list then
|
||||
type_index = 1
|
||||
end
|
||||
instance.layout:set_type(type_list[type_index])
|
||||
end)
|
||||
end,
|
||||
get_debug_info = function(instance)
|
||||
---@cast instance basic_layout
|
||||
local layout = instance.layout
|
||||
local p = layout.padding
|
||||
local info = ""
|
||||
info = info .. "Layout: " .. layout.type .. "\n"
|
||||
info = info .. "Padding: " .. math.floor(p.x) .. " " .. math.floor(p.y) .. " " .. math.floor(p.z) .. " " .. math.floor(p.w) .. "\n"
|
||||
info = info .. "Margin: " .. layout.margin.x .. " " .. layout.margin.y .. "\n"
|
||||
info = info .. "Justify: " .. tostring(layout.is_justify) .. "\n"
|
||||
info = info .. "Pivot: " .. tostring(gui.get_pivot(layout.node)) .. "\n"
|
||||
|
||||
return info
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user