mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update
This commit is contained in:
parent
69cf28e408
commit
6c5210a0fa
1
docs_md/creating_gui_layout.md
Normal file
1
docs_md/creating_gui_layout.md
Normal file
@ -0,0 +1 @@
|
||||
|
5
docs_md/druid_editor_scripts.md
Normal file
5
docs_md/druid_editor_scripts.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Druid Editor Scripts
|
||||
|
||||
## Auto Layers setup
|
||||
|
||||
## Create Druid Widget
|
@ -0,0 +1,10 @@
|
||||
# Widgets
|
||||
|
||||
What are widgets
|
||||
What are difference from custom components
|
||||
Using Druid Widgets
|
||||
Creating your own widgets (it's a new default way to use druid!)
|
||||
Best practices
|
||||
Make reusable widgets
|
||||
Binding Widget to Game Objects
|
||||
Testing you widgets separately
|
@ -5,11 +5,33 @@ local druid_instance = require("druid.system.druid_instance")
|
||||
|
||||
local default_style = require("druid.styles.default.style")
|
||||
|
||||
---Entry point for Druid UI Framework. Create a new Druid instance and adjust the settings.
|
||||
--- Use empty function to save a bit of memory
|
||||
local EMPTY_FUNCTION = function(_, message, context) end
|
||||
|
||||
---@type druid.logger
|
||||
local empty_logger = {
|
||||
trace = EMPTY_FUNCTION,
|
||||
debug = EMPTY_FUNCTION,
|
||||
info = EMPTY_FUNCTION,
|
||||
warn = EMPTY_FUNCTION,
|
||||
error = EMPTY_FUNCTION,
|
||||
}
|
||||
|
||||
---@type druid.logger
|
||||
local logger = {
|
||||
trace = EMPTY_FUNCTION,
|
||||
debug = EMPTY_FUNCTION,
|
||||
info = EMPTY_FUNCTION,
|
||||
warn = EMPTY_FUNCTION,
|
||||
error = EMPTY_FUNCTION,
|
||||
}
|
||||
|
||||
|
||||
---Entry point for Druid UI Framework.
|
||||
---Create a new Druid instance and adjust the Druid settings here.
|
||||
---@class druid
|
||||
local M = {}
|
||||
|
||||
|
||||
---Create a new Druid instance for creating GUI components.
|
||||
---@param context table The Druid context. Usually, this is the self of the gui_script. It is passed into all Druid callbacks.
|
||||
---@param style table|nil The Druid style table to override style parameters for this Druid instance.
|
||||
@ -26,6 +48,13 @@ function M.new(context, style)
|
||||
end
|
||||
|
||||
|
||||
---Set the logger for the Druid instance.
|
||||
---@param logger_instance druid.logger The logger
|
||||
function M:set_logger(logger_instance)
|
||||
self.logger = logger_instance or empty_logger
|
||||
end
|
||||
|
||||
|
||||
---Register a new external Druid component.
|
||||
---Register component just makes the druid:new_{name} function.
|
||||
---For example, if you register a component called "my_component", you can create it using druid:new_my_component(...).
|
||||
@ -33,6 +62,7 @@ end
|
||||
---The default way to create component is `druid_instance:new(component_class, ...)`.
|
||||
---@param name string Module name
|
||||
---@param module table Lua table with component
|
||||
---@deprecated
|
||||
function M.register(name, module)
|
||||
druid_instance["new_" .. name] = function(self, ...)
|
||||
return druid_instance.new(self, module, ...)
|
||||
@ -132,4 +162,29 @@ function M.get_widget(object_url)
|
||||
end
|
||||
|
||||
|
||||
---Release a binded widget to the current game object.
|
||||
---@param object_url string|userdata|url|nil Root object, if nil current object will be used
|
||||
---@return boolean is_released True if the widget was released, false if it was not found
|
||||
function M.release_widget(object_url)
|
||||
object_url = object_url or msg.url()
|
||||
if object_url then
|
||||
object_url = msg.url(object_url --[[@as string]])
|
||||
end
|
||||
|
||||
local socket_widgets = WRAPPED_WIDGETS[object_url.socket]
|
||||
if not socket_widgets then
|
||||
return false
|
||||
end
|
||||
|
||||
socket_widgets[object_url.path] = nil
|
||||
|
||||
-- Remove the socket if it's empty
|
||||
if next(socket_widgets) == nil then
|
||||
WRAPPED_WIDGETS[object_url.socket] = nil
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@ -1,6 +1,13 @@
|
||||
---@class druid.widget: druid.component
|
||||
---@field druid druid.instance Ready to use druid instance
|
||||
|
||||
---@class druid.logger
|
||||
---@field trace fun(message: string, context: any)
|
||||
---@field debug fun(message: string, context: any)
|
||||
---@field info fun(message: string, context: any)
|
||||
---@field warn fun(message: string, context: any)
|
||||
---@field error fun(message: string, context: any)
|
||||
|
||||
---@class GUITextMetrics
|
||||
---@field width number
|
||||
---@field height number
|
||||
|
@ -238,6 +238,7 @@ function M:new(component, ...)
|
||||
if instance.init then
|
||||
instance:init(...)
|
||||
end
|
||||
|
||||
if instance.on_late_init or (not self.input_inited and instance.on_input) then
|
||||
schedule_late_init(self)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user