Module DruidInstance
Druid Instance which you use for component creation.
# Component List #
For a list of all available components, please refer to the "See Also" section.
# Notes #
Please review the following API pages:
Helper - A useful set of functions for working with GUI nodes, such as centering nodes, get GUI scale ratio, etc
DruidEvent - The core event system in Druid. Learn how to subscribe to any event in every Druid component.
BaseComponent - The parent class of all Druid components. You can find all default component methods there.
# Tech Info #
• To use Druid, you need to create a Druid instance first. This instance is used to spawn components.
• When using Druid components, provide the node name as a string argument directly. Avoid calling gui.get_node() before passing it to the component. Because Druid can get nodes from template and cloned gui nodes.
• All Druid and component methods are called using the colon operator (e.g., self.druid:new_button()).
See also:
- BackHandler
- Blocker
- Button
- Checkbox
- CheckboxGroup
- DataList
- Drag
- DynamicGrid
- Hotkey
- Hover
- Input
- LangText
- Layout
- Progress
- RadioGroup
- RichInput
- RichText
- Scroll
- Slider
- StaticGrid
- Swipe
- Text
- Timer
Usage:
local druid = require("druid.druid") local function close_window(self) print("Yeah! You closed the game!") end function init(self) self.druid = druid.new(self) -- Call all druid instance function with ":" syntax: local text = self.druid:new_text("text_header", "Hello Druid!") local button = self.druid:new_button("button_close", close_window) -- You not need to save component reference if not need it self.druid:new_back_handler(close_window) end
Functions
Functions
- final(self)
-
Call this in gui_script final function.
Parameters:
- self DruidInstance
- new(self, component, ...)
-
Create new component.
Parameters:
- self DruidInstance
- component Component Component module
- ... args Other component params to pass it to component:init function
- new_back_handler(self, callback[, params])
-
Create BackHandler component
Parameters:
- self DruidInstance
- callback callback On back button
- params any Callback argument (optional)
Returns:
-
BackHandler
BackHandler component
- new_blocker(self, node)
-
Create Blocker component
Parameters:
- self DruidInstance
- node node Gui node
Returns:
-
Blocker
Blocker component
- new_button(self, node, callback[, params[, anim_node]])
-
Create Button component
Parameters:
- self DruidInstance
- node node GUI node
- callback function Button callback
- params table Button callback params (optional)
- anim_node node Button anim node (node, if not provided) (optional)
Returns:
-
Button
Button component
- new_checkbox(self, node, callback[, click_node=node[, initial_state=false]])
-
Create Checkbox component
Parameters:
- self DruidInstance
- node node Gui node
- callback function Checkbox callback
- click_node node Trigger node, by default equals to node (default node)
- initial_state boolean The initial state of checkbox, default - false (default false)
Returns:
-
Checkbox
Checkbox component
- new_checkbox_group(self, nodes, callback[, click_nodes=node])
-
Create CheckboxGroup component
Parameters:
- self DruidInstance
- nodes node[] Array of gui node
- callback function Checkbox callback
- click_nodes node[] Array of trigger nodes, by default equals to nodes (default node)
Returns:
-
CheckboxGroup
CheckboxGroup component
- new_data_list(self, druid_scroll, druid_grid, create_function)
-
Create DataList component
Parameters:
- self DruidInstance
- druid_scroll Scroll The Scroll instance for Data List component
- druid_grid Grid The Grid instance for Data List component
- create_function function The create function callback(self, data, index, data_list). Function should return (node, [component])
Returns:
-
DataList
DataList component
- new_drag(self, node, on_drag_callback)
-
Create Drag component
Parameters:
- self DruidInstance
- node node GUI node to detect dragging
- on_drag_callback function Callback for on_drag_event(self, dx, dy)
Returns:
-
Drag
Drag component
- new_dynamic_grid(self, parent)
-
Create DynamicGrid component
Parameters:
- self DruidInstance
- parent node The gui node parent, where items will be placed
Returns:
-
DynamicGrid
DynamicGrid component
- new_hotkey(self, keys_array, callback[, params])
-
Create Hotkey component
Parameters:
- self DruidInstance
- keys_array string or string[] Keys for trigger action. Should contains one action key and any amount of modificator keys
- callback function Button callback
- params value Button callback params (optional)
Returns:
-
Hotkey
Hotkey component
- new_hover(self, node, on_hover_callback)
-
Create Hover component
Parameters:
- self DruidInstance
- node node Gui node
- on_hover_callback function Hover callback
Returns:
-
Hover
Hover component
- new_input(self, click_node, text_node[, keyboard_type])
-
Create Input component
Parameters:
- self DruidInstance
- click_node node Button node to enabled input component
- text_node node Text node what will be changed on user input
- keyboard_type number Gui keyboard type for input field (optional)
Returns:
-
Input
Input component
- new_lang_text(self, node, locale_id, no_adjust)
-
Create LangText component
Parameters:
- self DruidInstance
- node node The text node
- locale_id string Default locale id
- no_adjust bool If true, will not correct text size
Returns:
-
LangText
LangText component
- new_layout(self, node, mode)
-
Create Layout component
Parameters:
Returns:
-
Layout
Layout component
- new_progress(self, node, key[, init_value=1])
-
Create Progress component
Parameters:
- self DruidInstance
- node string or node Progress bar fill node or node name
- key string Progress bar direction: const.SIDE.X or const.SIDE.Y
- init_value number Initial value of progress bar (default 1)
Returns:
-
Progress
Progress component
- new_radio_group(self, nodes, callback[, click_nodes=node])
-
Create RadioGroup component
Parameters:
- self DruidInstance
- nodes node[] Array of gui node
- callback function Radio callback
- click_nodes node[] Array of trigger nodes, by default equals to nodes (default node)
Returns:
-
RadioGroup
RadioGroup component
- new_rich_text(self[, template[, nodes]])
-
Create RichText component.
As a template please check rich_text.gui layout.
Parameters:
- self DruidInstance
- template string Template name if used (optional)
- nodes table Nodes table from gui.clone_tree (optional)
Returns:
-
RichText
RichText component
- new_scroll(self, view_node, content_node)
-
Create Scroll component
Parameters:
- self DruidInstance
- view_node node GUI view scroll node
- content_node node GUI content scroll node
Returns:
-
Scroll
Scroll component
- new_slider(self, node, end_pos[, callback])
-
Create Slider component
Parameters:
- self DruidInstance
- node node Gui pin node
- end_pos vector3 The end position of slider
- callback function On slider change callback (optional)
Returns:
-
Slider
Slider component
- new_static_grid(self, parent, element[, in_row=1])
-
Create StaticGrid component
Parameters:
- self DruidInstance
- parent node The gui node parent, where items will be placed
- element node Element prefab. Need to get it size
- in_row number How many nodes in row can be placed (default 1)
Returns:
-
StaticGrid
StaticGrid component
- new_swipe(self, node, on_swipe_callback)
-
Create Swipe component
Parameters:
- self DruidInstance
- node node Gui node
- on_swipe_callback function Swipe callback for on_swipe_end event
Returns:
-
Swipe
Swipe component
- new_text(self, node[, value[, no_adjust]])
-
Create Text component
Parameters:
- self DruidInstance
- node node Gui text node
- value string Initial text. Default value is node text from GUI scene. (optional)
- no_adjust bool If true, text will be not auto-adjust size (optional)
Returns:
-
Text
Text component
- new_timer(self, node, seconds_from[, seconds_to=0[, callback]])
-
Create Timer component
Parameters:
- self DruidInstance
- node node Gui text node
- seconds_from number Start timer value in seconds
- seconds_to number End timer value in seconds (default 0)
- callback function Function on timer end (optional)
Returns:
-
Timer
Timer component
- on_input(self, action_id, action)
-
Call this in gui_script on_input function.
Used for almost all components
Parameters:
- self DruidInstance
- action_id hash Action_id from on_input
- action table Action from on_input
Returns:
-
bool
The boolean value is input was consumed
- on_message(self, message_id, message, sender)
-
Call this in gui_script on_message function.
Used for special actions. See SPECIFIC_UI_MESSAGES table
Parameters:
- self DruidInstance
- message_id hash Message_id from on_message
- message table Message from on_message
- sender hash Sender from on_message
- remove(self, component)
-
Remove created component from Druid instance.
Component `on_remove` function will be invoked, if exist.
Parameters:
- self DruidInstance
- component Component Component instance
- set_blacklist(self[, blacklist_components=nil])
-
Set blacklist components for input processing.
If blacklist is not empty and component contains in this list, component will be not processed on input step
Parameters:
- self DruidInstance DruidInstance
- blacklist_components table or Component The array of component to blacklist (default nil)
Returns:
-
self
DruidInstance
- set_whitelist(self[, whitelist_components=nil])
-
Set whitelist components for input processing.
If whitelist is not empty and component not contains in this list, component will be not processed on input step
Parameters:
- self DruidInstance
- whitelist_components table or Component The array of component to whitelist (default nil)
Returns:
-
self
DruidInstance
- update(self, dt)
-
Call this in gui_script update function.
Used for: scroll, progress, timer components
Parameters:
- self DruidInstance
- dt number Delta time