mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Start update examples to move control things to example itself
This commit is contained in:
parent
d6fb8cad09
commit
e1339a2ca8
@ -47,8 +47,9 @@ function M:init(template, nodes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@class example_instance: druid.widget
|
---@class example_instance: druid.widget
|
||||||
---@field on_create fun(self: example_instance, output_list: output_list)?
|
---@field on_example_created fun(self: example_instance, output_list: output_list)?
|
||||||
---@field properties_control fun(self: example_instance, properties_panel: properties_panel)?
|
---@field properties_control fun(self: example_instance, properties_panel: properties_panel)?
|
||||||
|
---@field get_debug_info fun(self: example_instance):string?
|
||||||
|
|
||||||
---@param examples druid.examples
|
---@param examples druid.examples
|
||||||
---@param druid_example druid.example @The main GUI component
|
---@param druid_example druid.example @The main GUI component
|
||||||
@ -109,8 +110,8 @@ function M:add_example(examples, druid_example)
|
|||||||
item:set_selected(true)
|
item:set_selected(true)
|
||||||
|
|
||||||
druid_example.output_list:clear()
|
druid_example.output_list:clear()
|
||||||
if instance.on_create then
|
if instance.on_example_created then
|
||||||
instance:on_create(druid_example.output_list)
|
instance:on_example_created(druid_example.output_list)
|
||||||
elseif example_data.on_create then
|
elseif example_data.on_create then
|
||||||
example_data.on_create(instance, druid_example.output_list)
|
example_data.on_create(instance, druid_example.output_list)
|
||||||
end
|
end
|
||||||
@ -177,6 +178,13 @@ function M:update_debug_info()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local instance = self.selected_example.instance
|
||||||
|
if instance.get_debug_info then
|
||||||
|
local info = instance:get_debug_info()
|
||||||
|
self.on_debug_info:trigger(info)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local data = self.selected_example.data
|
local data = self.selected_example.data
|
||||||
if data.get_debug_info then
|
if data.get_debug_info then
|
||||||
local info = data.get_debug_info(self.selected_example.instance)
|
local info = data.get_debug_info(self.selected_example.instance)
|
||||||
|
@ -65,7 +65,7 @@ end
|
|||||||
---@return property_checkbox
|
---@return property_checkbox
|
||||||
function M:add_checkbox(text_id, initial_value, on_change_callback)
|
function M:add_checkbox(text_id, initial_value, on_change_callback)
|
||||||
local nodes = gui.clone_tree(self.property_checkbox_prefab)
|
local nodes = gui.clone_tree(self.property_checkbox_prefab)
|
||||||
local instance = self.druid:new(property_checkbox, "property_checkbox", nodes) --[[@as property_checkbox]]
|
local instance = self.druid:new_widget(property_checkbox, "property_checkbox", nodes) --[[@as property_checkbox]]
|
||||||
instance.text_name:translate(text_id)
|
instance.text_name:translate(text_id)
|
||||||
instance:set_value(initial_value, true)
|
instance:set_value(initial_value, true)
|
||||||
instance.button.on_click:subscribe(function()
|
instance.button.on_click:subscribe(function()
|
||||||
@ -108,7 +108,7 @@ end
|
|||||||
---@param on_click_callback function
|
---@param on_click_callback function
|
||||||
function M:add_button(text_id, on_click_callback)
|
function M:add_button(text_id, on_click_callback)
|
||||||
local nodes = gui.clone_tree(self.property_button_prefab)
|
local nodes = gui.clone_tree(self.property_button_prefab)
|
||||||
local instance = self.druid:new(property_button, "property_button", nodes) --[[@as property_button]]
|
local instance = self.druid:new_widget(property_button, "property_button", nodes) --[[@as property_button]]
|
||||||
instance.text_name:translate(text_id)
|
instance.text_name:translate(text_id)
|
||||||
|
|
||||||
gui.set_enabled(instance.root, true)
|
gui.set_enabled(instance.root, true)
|
||||||
|
@ -8,4 +8,22 @@ function M:init()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param output_log output_list
|
||||||
|
function M:on_example_created(output_log)
|
||||||
|
self.button.on_click:subscribe(function()
|
||||||
|
output_log:add_log_text("Button Clicked")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param properties_panel properties_panel
|
||||||
|
function M:properties_control(properties_panel)
|
||||||
|
local checkbox = properties_panel:add_checkbox("ui_enabled", false, function(value)
|
||||||
|
self.button:set_enabled(value)
|
||||||
|
end)
|
||||||
|
checkbox:set_value(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -12,4 +12,16 @@ function M:init()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param output_log output_list
|
||||||
|
function M:on_example_created(output_log)
|
||||||
|
self.button.on_click:subscribe(function()
|
||||||
|
output_log:add_log_text("Clicked")
|
||||||
|
end)
|
||||||
|
self.button.on_double_click:subscribe(function()
|
||||||
|
output_log:add_log_text("Double Clicked")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -39,4 +39,16 @@ function M:init()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param output_log output_list
|
||||||
|
function M:on_example_created(output_log)
|
||||||
|
self.button.on_click:subscribe(function()
|
||||||
|
output_log:add_log_text("Clicked")
|
||||||
|
end)
|
||||||
|
self.button.on_long_click:subscribe(function()
|
||||||
|
output_log:add_log_text("On long click")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -12,20 +12,6 @@ function M.get_examples()
|
|||||||
root = "basic_button/root",
|
root = "basic_button/root",
|
||||||
code_url = "example/examples/basic/button/basic_button.lua",
|
code_url = "example/examples/basic/button/basic_button.lua",
|
||||||
widget_class = require("example.examples.basic.button.basic_button"),
|
widget_class = require("example.examples.basic.button.basic_button"),
|
||||||
properties_control = function(instance, properties_panel)
|
|
||||||
---@cast instance examples.basic_button
|
|
||||||
|
|
||||||
local checkbox = properties_panel:add_checkbox("ui_enabled", false, function(value)
|
|
||||||
instance.button:set_enabled(value)
|
|
||||||
end)
|
|
||||||
checkbox:set_value(true)
|
|
||||||
end,
|
|
||||||
on_create = function(instance, output_log)
|
|
||||||
---@cast instance examples.basic_button
|
|
||||||
instance.button.on_click:subscribe(function()
|
|
||||||
output_log:add_log_text("Button Clicked")
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name_id = "ui_example_basic_button_double_click",
|
name_id = "ui_example_basic_button_double_click",
|
||||||
@ -34,15 +20,6 @@ function M.get_examples()
|
|||||||
root = "basic_button_double_click/root",
|
root = "basic_button_double_click/root",
|
||||||
code_url = "example/examples/basic/button/basic_button_double_click.lua",
|
code_url = "example/examples/basic/button/basic_button_double_click.lua",
|
||||||
widget_class = require("example.examples.basic.button.basic_button_double_click"),
|
widget_class = require("example.examples.basic.button.basic_button_double_click"),
|
||||||
on_create = function(instance, output_log)
|
|
||||||
---@cast instance examples.basic_button_double_click
|
|
||||||
instance.button.on_click:subscribe(function()
|
|
||||||
output_log:add_log_text("Clicked")
|
|
||||||
end)
|
|
||||||
instance.button.on_double_click:subscribe(function()
|
|
||||||
output_log:add_log_text("Double Clicked")
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name_id = "ui_example_basic_button_hold",
|
name_id = "ui_example_basic_button_hold",
|
||||||
@ -51,15 +28,6 @@ function M.get_examples()
|
|||||||
root = "basic_button_hold/root",
|
root = "basic_button_hold/root",
|
||||||
code_url = "example/examples/basic/button/basic_button_hold.lua",
|
code_url = "example/examples/basic/button/basic_button_hold.lua",
|
||||||
widget_class = require("example.examples.basic.button.basic_button_hold"),
|
widget_class = require("example.examples.basic.button.basic_button_hold"),
|
||||||
on_create = function(instance, output_log)
|
|
||||||
---@cast instance examples.basic_button_hold
|
|
||||||
instance.button.on_click:subscribe(function()
|
|
||||||
output_log:add_log_text("Clicked")
|
|
||||||
end)
|
|
||||||
instance.button.on_long_click:subscribe(function()
|
|
||||||
output_log:add_log_text("On long click")
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name_id = "ui_example_basic_text",
|
name_id = "ui_example_basic_text",
|
||||||
@ -68,56 +36,6 @@ function M.get_examples()
|
|||||||
root = "basic_text/root",
|
root = "basic_text/root",
|
||||||
code_url = "example/examples/basic/text/basic_text.lua",
|
code_url = "example/examples/basic/text/basic_text.lua",
|
||||||
widget_class = require("example.examples.basic.text.basic_text"),
|
widget_class = require("example.examples.basic.text.basic_text"),
|
||||||
properties_control = function(instance, properties_panel)
|
|
||||||
---@cast instance examples.basic_text
|
|
||||||
|
|
||||||
local adjust_index = 1
|
|
||||||
local adjust_types = {
|
|
||||||
"downscale",
|
|
||||||
"downscale_limited",
|
|
||||||
--"scale_then_scroll", -- works bad with container for some reason
|
|
||||||
--"scroll", -- works bad with container for some reason
|
|
||||||
"trim",
|
|
||||||
}
|
|
||||||
properties_panel:add_button("ui_adjust_next", function()
|
|
||||||
adjust_index = adjust_index + 1
|
|
||||||
if adjust_index > #adjust_types then
|
|
||||||
adjust_index = 1
|
|
||||||
end
|
|
||||||
instance.text:set_text_adjust(adjust_types[adjust_index], 0.5)
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
---@cast instance examples.rich_text_tags
|
|
||||||
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)
|
|
||||||
end,
|
|
||||||
get_debug_info = function(instance)
|
|
||||||
---@cast instance examples.multiline_text
|
|
||||||
local info = ""
|
|
||||||
|
|
||||||
info = info .. "Text Adjust: " .. instance.text.adjust_type .. "\n"
|
|
||||||
info = info .. "Pivot: " .. gui.get_pivot(instance.text.node) .. "\n"
|
|
||||||
|
|
||||||
return info
|
|
||||||
end
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name_id = "ui_example_basic_multiline_text",
|
name_id = "ui_example_basic_multiline_text",
|
||||||
|
@ -31,4 +31,56 @@ function M:refresh_text_position()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param properties_panel properties_panel
|
||||||
|
function M:properties_control(properties_panel)
|
||||||
|
local adjust_index = 1
|
||||||
|
local adjust_types = {
|
||||||
|
"downscale",
|
||||||
|
"downscale_limited",
|
||||||
|
--"scale_then_scroll", -- works bad with container for some reason
|
||||||
|
--"scroll", -- works bad with container for some reason
|
||||||
|
"trim",
|
||||||
|
}
|
||||||
|
properties_panel:add_button("ui_adjust_next", function()
|
||||||
|
adjust_index = adjust_index + 1
|
||||||
|
if adjust_index > #adjust_types then
|
||||||
|
adjust_index = 1
|
||||||
|
end
|
||||||
|
self.text:set_text_adjust(adjust_types[adjust_index], 0.5)
|
||||||
|
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
|
||||||
|
self:set_pivot(pivot_list[pivot_index])
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@return string
|
||||||
|
function M:get_debug_info()
|
||||||
|
local info = ""
|
||||||
|
|
||||||
|
info = info .. "Text Adjust: " .. self.text.adjust_type .. "\n"
|
||||||
|
info = info .. "Pivot: " .. gui.get_pivot(self.text.node) .. "\n"
|
||||||
|
|
||||||
|
return info
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user