mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
widget.* to druid.widget lls class
This commit is contained in:
parent
ad0447b649
commit
5348561d68
@ -148,4 +148,25 @@ function M.register_druid_as_widget(druid)
|
||||
end
|
||||
|
||||
|
||||
---Unregister a druid instance from the current game object.
|
||||
function M.unregister_druid_as_widget()
|
||||
local gui_url = msg.url()
|
||||
local socket = gui_url.socket
|
||||
local path = gui_url.path
|
||||
local fragment = gui_url.fragment
|
||||
|
||||
for index = 1, #REGISTERED_GUI_WIDGETS[socket] do
|
||||
local gui = REGISTERED_GUI_WIDGETS[socket][index]
|
||||
if gui.path == path and gui.fragment == fragment then
|
||||
table.remove(REGISTERED_GUI_WIDGETS[socket], index)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if #REGISTERED_GUI_WIDGETS[socket] == 0 then
|
||||
REGISTERED_GUI_WIDGETS[socket] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@ -8,6 +8,7 @@ end
|
||||
|
||||
|
||||
function final(self)
|
||||
druid.unregister_druid_as_widget()
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
---@class widget.TEMPLATE: druid.widget
|
||||
---@class druid.widget.TEMPLATE: druid.widget
|
||||
local M = {}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
local helper = require("druid.helper")
|
||||
local mini_graph = require("druid.widget.mini_graph.mini_graph")
|
||||
|
||||
---@class widget.fps_panel: druid.widget
|
||||
---@class druid.widget.fps_panel: druid.widget
|
||||
---@field root node
|
||||
local M = {}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
local helper = require("druid.helper")
|
||||
local mini_graph = require("druid.widget.mini_graph.mini_graph")
|
||||
|
||||
---@class widget.memory_panel: druid.widget
|
||||
---@class druid.widget.memory_panel: druid.widget
|
||||
---@field root node
|
||||
local M = {}
|
||||
|
||||
|
@ -6,7 +6,7 @@ local helper = require("druid.helper")
|
||||
---Use `push_line_value` to add a new value to the line
|
||||
---Or `set_line_value` to set a value to the line by index
|
||||
---Setup colors inside template file (at minimum and maximum)
|
||||
---@class widget.mini_graph: druid.widget
|
||||
---@class druid.widget.mini_graph: druid.widget
|
||||
local M = {}
|
||||
|
||||
local SIZE_Y = hash("size.y")
|
||||
|
@ -1,6 +1,6 @@
|
||||
local color = require("druid.color")
|
||||
|
||||
---@class widget.property_button: druid.widget
|
||||
---@class druid.widget.property_button: druid.widget
|
||||
---@field root node
|
||||
---@field container druid.container
|
||||
---@field text_name druid.text
|
||||
@ -36,7 +36,7 @@ end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return widget.property_button
|
||||
---@return druid.widget.property_button
|
||||
function M:set_text_property(text)
|
||||
self.text_name:set_text(text)
|
||||
return self
|
||||
@ -44,7 +44,7 @@ end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return widget.property_button
|
||||
---@return druid.widget.property_button
|
||||
function M:set_text_button(text)
|
||||
self.text_button:set_text(text)
|
||||
return self
|
||||
|
@ -1,6 +1,6 @@
|
||||
local event = require("event.event")
|
||||
|
||||
---@class widget.property_checkbox: druid.widget
|
||||
---@class druid.widget.property_checkbox: druid.widget
|
||||
---@field root node
|
||||
---@field druid druid.instance
|
||||
---@field text_name druid.text
|
||||
|
@ -1,4 +1,4 @@
|
||||
---@class widget.property_input: druid.widget
|
||||
---@class druid.widget.property_input: druid.widget
|
||||
---@field root node
|
||||
---@field container druid.container
|
||||
---@field text_name druid.text
|
||||
@ -23,7 +23,7 @@ end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return widget.property_input
|
||||
---@return druid.widget.property_input
|
||||
function M:set_text_property(text)
|
||||
self.text_name:set_text(text)
|
||||
return self
|
||||
@ -31,14 +31,14 @@ end
|
||||
|
||||
|
||||
---@param text string|number
|
||||
---@return widget.property_input
|
||||
---@return druid.widget.property_input
|
||||
function M:set_text_value(text)
|
||||
self.rich_input:set_text(tostring(text))
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---@param callback fun(self: widget.property_input, text: string)
|
||||
---@param callback fun(self: druid.widget.property_input, text: string)
|
||||
---@param callback_context any
|
||||
function M:on_change(callback, callback_context)
|
||||
self.rich_input.input.on_input_unselect:subscribe(callback, callback_context)
|
||||
|
@ -1,6 +1,6 @@
|
||||
local event = require("event.event")
|
||||
|
||||
---@class widget.property_left_right_selector: druid.widget
|
||||
---@class druid.widget.property_left_right_selector: druid.widget
|
||||
---@field root node
|
||||
---@field druid druid.instance
|
||||
---@field text_name druid.text
|
||||
|
@ -1,7 +1,7 @@
|
||||
local event = require("event.event")
|
||||
local helper = require("druid.helper")
|
||||
|
||||
---@class widget.property_slider: druid.widget
|
||||
---@class druid.widget.property_slider: druid.widget
|
||||
---@field root node
|
||||
---@field container druid.container
|
||||
---@field druid druid.instance
|
||||
|
@ -1,4 +1,4 @@
|
||||
---@class widget.property_text: druid.widget
|
||||
---@class druid.widget.property_text: druid.widget
|
||||
---@field root node
|
||||
---@field container druid.container
|
||||
---@field text_name druid.text
|
||||
@ -24,7 +24,7 @@ end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return widget.property_text
|
||||
---@return druid.widget.property_text
|
||||
function M:set_text_property(text)
|
||||
self.text_name:set_text(text)
|
||||
return self
|
||||
@ -32,7 +32,7 @@ end
|
||||
|
||||
|
||||
---@param text string|nil
|
||||
---@return widget.property_text
|
||||
---@return druid.widget.property_text
|
||||
function M:set_text_value(text)
|
||||
self.text_right:set_text(text or "")
|
||||
return self
|
||||
|
@ -1,7 +1,7 @@
|
||||
local event = require("event.event")
|
||||
|
||||
|
||||
---@class widget.property_vector3: druid.widget
|
||||
---@class druid.widget.property_vector3: druid.widget
|
||||
---@field root node
|
||||
---@field container druid.container
|
||||
---@field text_name druid.text
|
||||
@ -53,7 +53,7 @@ end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return widget.property_vector3
|
||||
---@return druid.widget.property_vector3
|
||||
function M:set_text_property(text)
|
||||
self.text_name:set_text(text)
|
||||
return self
|
||||
@ -63,7 +63,7 @@ end
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
---@return widget.property_vector3
|
||||
---@return druid.widget.property_vector3
|
||||
function M:set_value(x, y, z)
|
||||
self.rich_input_x:set_text(tostring(x))
|
||||
self.rich_input_y:set_text(tostring(y))
|
||||
|
@ -6,7 +6,7 @@ local property_text = require("druid.widget.properties_panel.properties.property
|
||||
local property_left_right_selector = require("druid.widget.properties_panel.properties.property_left_right_selector")
|
||||
local property_vector3 = require("druid.widget.properties_panel.properties.property_vector3")
|
||||
|
||||
---@class widget.properties_panel: druid.widget
|
||||
---@class druid.widget.properties_panel: druid.widget
|
||||
---@field root node
|
||||
---@field scroll druid.scroll
|
||||
---@field layout druid.layout
|
||||
@ -16,7 +16,7 @@ local property_vector3 = require("druid.widget.properties_panel.properties.prope
|
||||
---@field contaienr_scroll_content druid.container
|
||||
---@field button_hidden druid.button
|
||||
---@field text_header druid.text
|
||||
---@field paginator widget.property_left_right_selector
|
||||
---@field paginator druid.widget.property_left_right_selector
|
||||
---@field properties druid.widget[] List of created properties
|
||||
---@field properties_constructors fun()[] List of properties functions to create a new widget. Used to not spawn non-visible widgets but keep the reference
|
||||
local M = {}
|
||||
@ -176,47 +176,47 @@ function M:update(dt)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(checkbox: widget.property_checkbox)|nil
|
||||
---@return widget.properties_panel
|
||||
---@param on_create fun(checkbox: druid.widget.property_checkbox)|nil
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_checkbox(on_create)
|
||||
return self:add_inner_widget(property_checkbox, "property_checkbox", self.property_checkbox_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(slider: widget.property_slider)|nil
|
||||
---@return widget.properties_panel
|
||||
---@param on_create fun(slider: druid.widget.property_slider)|nil
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_slider(on_create)
|
||||
return self:add_inner_widget(property_slider, "property_slider", self.property_slider_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(button: widget.property_button)|nil
|
||||
---@return widget.properties_panel
|
||||
---@param on_create fun(button: druid.widget.property_button)|nil
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_button(on_create)
|
||||
return self:add_inner_widget(property_button, "property_button", self.property_button_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(input: widget.property_input)|nil
|
||||
---@return widget.properties_panel
|
||||
---@param on_create fun(input: druid.widget.property_input)|nil
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_input(on_create)
|
||||
return self:add_inner_widget(property_input, "property_input", self.property_input_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(text: widget.property_text)|nil
|
||||
---@param on_create fun(text: druid.widget.property_text)|nil
|
||||
function M:add_text(on_create)
|
||||
return self:add_inner_widget(property_text, "property_text", self.property_text_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(selector: widget.property_left_right_selector)|nil
|
||||
---@param on_create fun(selector: druid.widget.property_left_right_selector)|nil
|
||||
function M:add_left_right_selector(on_create)
|
||||
return self:add_inner_widget(property_left_right_selector, "property_left_right_selector", self.property_left_right_selector_prefab, on_create)
|
||||
end
|
||||
|
||||
|
||||
---@param on_create fun(vector3: widget.property_vector3)|nil
|
||||
---@param on_create fun(vector3: druid.widget.property_vector3)|nil
|
||||
function M:add_vector3(on_create)
|
||||
return self:add_inner_widget(property_vector3, "property_vector3", self.property_vector3_prefab, on_create)
|
||||
end
|
||||
@ -227,7 +227,7 @@ end
|
||||
---@param template string|nil
|
||||
---@param nodes table<hash, node>|node|nil
|
||||
---@param on_create fun(widget: T)|nil
|
||||
---@return widget.properties_panel
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_inner_widget(widget_class, template, nodes, on_create)
|
||||
table.insert(self.properties_constructors, function()
|
||||
local widget = self.druid:new_widget(widget_class, template, nodes)
|
||||
@ -245,7 +245,7 @@ end
|
||||
|
||||
|
||||
---@param create_widget_callback fun(): druid.widget
|
||||
---@return widget.properties_panel
|
||||
---@return druid.widget.properties_panel
|
||||
function M:add_widget(create_widget_callback)
|
||||
table.insert(self.properties_constructors, function()
|
||||
local widget = create_widget_callback()
|
||||
|
@ -19,7 +19,7 @@ function M.get_examples()
|
||||
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
|
||||
---@cast instance druid.widget.properties_panel
|
||||
|
||||
instance:add_button(function(button)
|
||||
button:set_text_button("Button")
|
||||
@ -135,7 +135,7 @@ function M.get_examples()
|
||||
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
|
||||
---@cast instance druid.widget.memory_panel
|
||||
print("Memory panel created")
|
||||
end,
|
||||
},
|
||||
@ -147,7 +147,7 @@ function M.get_examples()
|
||||
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
|
||||
---@cast instance druid.widget.fps_panel
|
||||
print("FPS panel created")
|
||||
end,
|
||||
},
|
||||
@ -159,11 +159,11 @@ function M.get_examples()
|
||||
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
|
||||
---@cast instance druid.widget.mini_graph
|
||||
instance:set_samples(50)
|
||||
end,
|
||||
properties_control = function(instance, properties_panel)
|
||||
---@cast instance widget.mini_graph
|
||||
---@cast instance druid.widget.mini_graph
|
||||
properties_panel:add_slider("value", 0.5, function(value)
|
||||
-- Remap to -1, 2
|
||||
value = value * 3 - 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
local properties_panel = require("druid.widget.properties_panel.properties_panel")
|
||||
|
||||
---@class widget.example_properties_panel: druid.widget
|
||||
---@class druid.widget.example_properties_panel: druid.widget
|
||||
local M = {}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ local panthera = require("panthera.panthera")
|
||||
local animation = require("example.other.go_bindings.go_widget_panthera")
|
||||
local memory_panel = require("druid.widget.memory_panel.memory_panel")
|
||||
|
||||
---@class widget.go_widget: druid.widget
|
||||
---@class druid.widget.go_widget: druid.widget
|
||||
local M = {}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user