mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update docs
This commit is contained in:
@@ -7,24 +7,26 @@
|
||||
-- Druid components or make your own game-specific components to make
|
||||
-- amazing GUI in your games.
|
||||
--
|
||||
-- To start use Druid, check the Basic Usage below.
|
||||
-- To start using Druid, please refer to the Basic Usage section below.
|
||||
--
|
||||
-- # Tech Info #
|
||||
--
|
||||
-- - Each Druid keeps the self context from constructor to pass it into each Druid callback
|
||||
-- • Each Druid instance maintains the self context from the constructor and passes it to each Druid callback.
|
||||
--
|
||||
-- • There is a system in place to track all Druid instances, so it is required to call druid:final()
|
||||
--
|
||||
-- See next: @{DruidInstance}
|
||||
--
|
||||
-- @usage
|
||||
-- local druid = require("druid.druid")
|
||||
--
|
||||
-- local function button_callback(self)
|
||||
-- print("Button was clicked!")
|
||||
-- local function on_play(self)
|
||||
-- print("Gonna play!")
|
||||
-- end
|
||||
--
|
||||
-- function init(self)
|
||||
-- self.druid = druid.new(self)
|
||||
-- self.druid:new_button("button_node_name", button_callback)
|
||||
-- self.druid:new_button("button_play", on_play)
|
||||
-- end
|
||||
--
|
||||
-- function final(self)
|
||||
@@ -67,10 +69,11 @@ local function get_druid_instances()
|
||||
end
|
||||
|
||||
|
||||
--- Register new external Druid component.
|
||||
--- Register a new external Druid component.
|
||||
--
|
||||
-- You can register your own components to create it with druid:new_{name} function
|
||||
-- For example, you can register your own component "my_component" and create it with druid:new_my_component(...)
|
||||
-- You can register your own components by creating them with the druid:new_{name} function.
|
||||
-- For example, if you want to register a component called "my_component", you can create it using druid:new_my_component(...).
|
||||
-- This can be useful if you have your own "basic" components that you don't want to re-create each time.
|
||||
-- @function druid.register
|
||||
-- @tparam string name module name
|
||||
-- @tparam table module lua table with component
|
||||
@@ -81,19 +84,18 @@ end
|
||||
-- local druid = druid.new(self)
|
||||
-- local component_instance = self.druid:new_my_component(...)
|
||||
function M.register(name, module)
|
||||
-- TODO: Find better solution to creating elements?
|
||||
-- Current way is very implicit
|
||||
druid_instance["new_" .. name] = function(self, ...)
|
||||
return druid_instance.new(self, module, ...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Create new Druid instance to create GUI components.
|
||||
--- Create a new Druid instance for creating GUI components.
|
||||
--
|
||||
-- @function druid.new
|
||||
-- @tparam table context Druid context. Usually it is *self* of *gui_script. It passes into all Druid callbacks
|
||||
-- @tparam[opt] table style Druid style table to override style params for this Druid instance
|
||||
-- @treturn druid_instance Druid instance @{DruidInstance}
|
||||
-- @tparam table context The Druid context. Usually, this is the self of the gui_script. It is passed into all Druid callbacks.
|
||||
-- @tparam[opt] table style The Druid style table to override style parameters for this Druid instance.
|
||||
-- @treturn druid_instance The Druid instance @{DruidInstance}.
|
||||
-- @usage
|
||||
-- local druid = require("druid.druid")
|
||||
--
|
||||
@@ -113,8 +115,8 @@ end
|
||||
|
||||
--- Set your own default style for all Druid instances.
|
||||
--
|
||||
-- To create your own style file, copy the default style file and change it.
|
||||
-- Register new style before your Druid instances creation.
|
||||
-- To create your own style file, copy the default style file and make changes to it.
|
||||
-- Register the new style before creating your Druid instances.
|
||||
-- @function druid.set_default_style
|
||||
-- @tparam table style Druid style module
|
||||
-- @usage
|
||||
@@ -125,10 +127,10 @@ function M.set_default_style(style)
|
||||
end
|
||||
|
||||
|
||||
--- Set text function for LangText component.
|
||||
--- Set the text function for the LangText component.
|
||||
--
|
||||
-- Druid locale component will call this function to get translated text. After set_text_funtion
|
||||
-- all existing locale component will be updated
|
||||
-- The Druid locale component will call this function to get translated text.
|
||||
-- After setting the text function, all existing locale components will be updated.
|
||||
-- @function druid.set_text_function
|
||||
-- @tparam function callback Get localized text function
|
||||
-- @usage
|
||||
@@ -141,10 +143,10 @@ function M.set_text_function(callback)
|
||||
end
|
||||
|
||||
|
||||
--- Set Druid sound function to play UI sounds if used.
|
||||
--- Set the Druid sound function to play UI sounds if used.
|
||||
--
|
||||
-- Set function to play sound by sound_id. It used in Button click and play "click" sound.
|
||||
-- Also can be used by play sound in your custom components (see default Druid style file for example)
|
||||
-- Set a function to play a sound given a sound_id. This function is used for button clicks to play the "click" sound.
|
||||
-- It can also be used to play sounds in your custom components (see the default Druid style file for an example).
|
||||
-- @function druid.set_sound_function
|
||||
-- @tparam function callback Sound play callback
|
||||
-- @usage
|
||||
@@ -156,9 +158,9 @@ function M.set_sound_function(callback)
|
||||
end
|
||||
|
||||
|
||||
--- Set window callback to enable *on_focus_gain* and *on_focus_lost* functions.
|
||||
--- Set the window callback to enable on_focus_gain and on_focus_lost functions.
|
||||
--
|
||||
-- Used to trigger on_focus_lost and on_focus_gain in Druid components
|
||||
-- This is used to trigger the on_focus_lost and on_focus_gain functions in Druid components.
|
||||
-- @function druid.on_window_callback
|
||||
-- @tparam string event Event param from window listener
|
||||
-- @usage
|
||||
@@ -188,9 +190,9 @@ function M.on_window_callback(event)
|
||||
end
|
||||
|
||||
|
||||
--- Call this on game language change.
|
||||
--- Call this function when the game language changes.
|
||||
--
|
||||
-- This function will update all LangText components
|
||||
-- This function will translate all current LangText components.
|
||||
-- @function druid.on_language_change
|
||||
-- @usage
|
||||
-- druid.on_language_change()
|
||||
|
Reference in New Issue
Block a user