mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Progress with widget examples
This commit is contained in:
@@ -11,6 +11,72 @@ function M.get_examples()
|
||||
code_url = "example/examples/widgets/hover_hint/hover_hint_example.lua",
|
||||
component_class = require("example.examples.widgets.hover_hint.hover_hint_example"),
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_properties_panel",
|
||||
information_text_id = "ui_example_widget_properties_panel_description",
|
||||
template = "properties_panel",
|
||||
root = "properties_panel/root",
|
||||
code_url = "example/examples/widgets/properties_panel/properties_panel.lua",
|
||||
widget_class = require("druid.widget.properties_panel.properties_panel"),
|
||||
on_create = function(instance, output_list)
|
||||
---@cast instance widget.properties_panel
|
||||
|
||||
instance:add_button(function(button)
|
||||
button:set_text_button("Button")
|
||||
button.button.on_click:subscribe(function()
|
||||
print("Button clicked")
|
||||
end)
|
||||
end)
|
||||
|
||||
instance:add_checkbox(function(checkbox)
|
||||
--print("Checkbox clicked", value)
|
||||
checkbox:set_text_property("Checkbox")
|
||||
checkbox.on_change_value:subscribe(function(value)
|
||||
print("Checkbox clicked", value)
|
||||
end)
|
||||
checkbox:set_value(false)
|
||||
end)
|
||||
|
||||
instance:add_input(function(input)
|
||||
input:set_text_property("Input")
|
||||
input:set_text_value("Initial")
|
||||
input:on_change(function(text)
|
||||
print("Input changed", text)
|
||||
end)
|
||||
end)
|
||||
|
||||
instance:add_left_right_selector(function(selector)
|
||||
selector:set_template("Arrows Number")
|
||||
selector.on_change_value:subscribe(function(value)
|
||||
print("Left Right Selector changed", value)
|
||||
end)
|
||||
selector:set_number_type(0, 42, true, 1)
|
||||
selector:set_value(0)
|
||||
end)
|
||||
|
||||
instance:add_left_right_selector(function(selector)
|
||||
selector:set_template("Arrows Array")
|
||||
selector.on_change_value:subscribe(function(value)
|
||||
print("Left Right Array value", value)
|
||||
end)
|
||||
selector:set_array_type({"Zero", "One", "Two", "Three", "Four", "Five"}, false, 1)
|
||||
selector:set_value("Zero")
|
||||
end)
|
||||
|
||||
instance:add_slider(function(slider)
|
||||
slider:set_text_property("Slider")
|
||||
slider:set_value(0.5)
|
||||
slider:on_change(function(value)
|
||||
print("Slider changed", value)
|
||||
end)
|
||||
end)
|
||||
|
||||
instance:add_text(function(text)
|
||||
text:set_text_property("Text")
|
||||
text:set_text_value("Hello, World!")
|
||||
end)
|
||||
end,
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_property_button",
|
||||
information_text_id = "ui_example_widget_property_button_description",
|
||||
@@ -25,6 +91,14 @@ function M.get_examples()
|
||||
end)
|
||||
end,
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_property_input",
|
||||
information_text_id = "ui_example_widget_property_input_description",
|
||||
template = "property_input",
|
||||
root = "property_input/root",
|
||||
code_url = "druid/widget/properties_panel/properties/property_input.lua",
|
||||
widget_class = require("druid.widget.properties_panel.properties.property_input"),
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_property_slider",
|
||||
information_text_id = "ui_example_widget_property_slider_description",
|
||||
@@ -56,27 +130,54 @@ function M.get_examples()
|
||||
{
|
||||
name_id = "ui_example_widget_memory_panel",
|
||||
information_text_id = "ui_example_widget_memory_panel_description",
|
||||
template = "example_memory_panel",
|
||||
root = "example_memory_panel/root",
|
||||
code_url = "example/examples/widgets/memory_panel/example_memory_panel.lua",
|
||||
widget_class = require("example.examples.widgets.memory_panel.example_memory_panel"),
|
||||
template = "memory_panel",
|
||||
root = "memory_panel/root",
|
||||
code_url = "druid.widget.memory_panel.memory_panel.lua",
|
||||
widget_class = require("druid.widget.memory_panel.memory_panel"),
|
||||
on_create = function(instance, output_list)
|
||||
---@cast instance widget.memory_panel
|
||||
print("Memory panel created")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_fps_panel",
|
||||
information_text_id = "ui_example_widget_fps_panel_description",
|
||||
template = "example_fps_panel",
|
||||
root = "example_fps_panel/root",
|
||||
code_url = "example/examples/widgets/fps_panel/example_fps_panel.lua",
|
||||
widget_class = require("example.examples.widgets.fps_panel.example_fps_panel"),
|
||||
template = "fps_panel",
|
||||
root = "fps_panel/root",
|
||||
code_url = "druid.widget.fps_panel.fps_panel.lua",
|
||||
widget_class = require("druid.widget.fps_panel.fps_panel"),
|
||||
on_create = function(instance, output_list)
|
||||
---@cast instance widget.fps_panel
|
||||
print("FPS panel created")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name_id = "ui_example_widget_properties_panel",
|
||||
information_text_id = "ui_example_widget_properties_panel_description",
|
||||
template = "example_properties_panel",
|
||||
root = "example_properties_panel/root",
|
||||
code_url = "example/examples/widgets/properties_panel/example_properties_panel.lua",
|
||||
widget_class = require("example.examples.widgets.properties_panel.example_properties_panel"),
|
||||
},
|
||||
name_id = "ui_example_widget_mini_graph",
|
||||
information_text_id = "ui_example_widget_mini_graph_description",
|
||||
template = "mini_graph",
|
||||
root = "mini_graph/root",
|
||||
code_url = "druid.widget.mini_graph.mini_graph.lua",
|
||||
widget_class = require("druid.widget.mini_graph.mini_graph"),
|
||||
on_create = function(instance, output_list)
|
||||
---@cast instance widget.mini_graph
|
||||
instance:set_samples(50)
|
||||
end,
|
||||
properties_control = function(instance, properties_panel)
|
||||
---@cast instance widget.mini_graph
|
||||
properties_panel:add_slider("value", 0.5, function(value)
|
||||
-- Remap to -1, 2
|
||||
value = value * 3 - 1
|
||||
for index = 1, 50 do
|
||||
-- Take value each 0.1 step, the higher value at argument value
|
||||
local x = index * (1 / 50)
|
||||
local distance = math.abs(x - value)
|
||||
local line_v = 1 - distance^2
|
||||
|
||||
instance:set_line_value(index, line_v)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user