mirror of
https://github.com/Insality/druid
synced 2025-06-27 02:17:52 +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
|
||||
|
||||
---@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 get_debug_info fun(self: example_instance):string?
|
||||
|
||||
---@param examples druid.examples
|
||||
---@param druid_example druid.example @The main GUI component
|
||||
@ -109,8 +110,8 @@ function M:add_example(examples, druid_example)
|
||||
item:set_selected(true)
|
||||
|
||||
druid_example.output_list:clear()
|
||||
if instance.on_create then
|
||||
instance:on_create(druid_example.output_list)
|
||||
if instance.on_example_created then
|
||||
instance:on_example_created(druid_example.output_list)
|
||||
elseif example_data.on_create then
|
||||
example_data.on_create(instance, druid_example.output_list)
|
||||
end
|
||||
@ -177,6 +178,13 @@ function M:update_debug_info()
|
||||
return
|
||||
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
|
||||
if data.get_debug_info then
|
||||
local info = data.get_debug_info(self.selected_example.instance)
|
||||
|
@ -65,7 +65,7 @@ end
|
||||
---@return property_checkbox
|
||||
function M:add_checkbox(text_id, initial_value, on_change_callback)
|
||||
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:set_value(initial_value, true)
|
||||
instance.button.on_click:subscribe(function()
|
||||
@ -108,7 +108,7 @@ end
|
||||
---@param on_click_callback function
|
||||
function M:add_button(text_id, on_click_callback)
|
||||
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)
|
||||
|
||||
gui.set_enabled(instance.root, true)
|
||||
|
@ -8,4 +8,22 @@ function M:init()
|
||||
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
|
||||
|
@ -12,4 +12,16 @@ function M:init()
|
||||
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
|
||||
|
@ -39,4 +39,16 @@ function M:init()
|
||||
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
|
||||
|
@ -12,20 +12,6 @@ function M.get_examples()
|
||||
root = "basic_button/root",
|
||||
code_url = "example/examples/basic/button/basic_button.lua",
|
||||
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",
|
||||
@ -34,15 +20,6 @@ function M.get_examples()
|
||||
root = "basic_button_double_click/root",
|
||||
code_url = "example/examples/basic/button/basic_button_double_click.lua",
|
||||
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",
|
||||
@ -51,15 +28,6 @@ function M.get_examples()
|
||||
root = "basic_button_hold/root",
|
||||
code_url = "example/examples/basic/button/basic_button_hold.lua",
|
||||
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",
|
||||
@ -68,56 +36,6 @@ function M.get_examples()
|
||||
root = "basic_text/root",
|
||||
code_url = "example/examples/basic/text/basic_text.lua",
|
||||
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",
|
||||
|
@ -31,4 +31,56 @@ function M:refresh_text_position()
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user