mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update docs
This commit is contained in:
445
api/components/base/component_api.md
Normal file
445
api/components/base/component_api.md
Normal file
@@ -0,0 +1,445 @@
|
||||
# druid.component API
|
||||
|
||||
> at /druid/component.lua
|
||||
|
||||
|
||||
## Functions
|
||||
- [create](#create)
|
||||
- [create_widget](#create_widget)
|
||||
|
||||
- [init](#init)
|
||||
- [update](#update)
|
||||
- [on_remove](#on_remove)
|
||||
- [on_input](#on_input)
|
||||
- [on_input_interrupt](#on_input_interrupt)
|
||||
- [on_message](#on_message)
|
||||
- [on_late_init](#on_late_init)
|
||||
- [on_focus_lost](#on_focus_lost)
|
||||
- [on_focus_gained](#on_focus_gained)
|
||||
- [on_style_change](#on_style_change)
|
||||
- [on_layout_change](#on_layout_change)
|
||||
- [on_window_resized](#on_window_resized)
|
||||
- [on_language_change](#on_language_change)
|
||||
- [set_style](#set_style)
|
||||
- [set_template](#set_template)
|
||||
- [get_template](#get_template)
|
||||
- [set_nodes](#set_nodes)
|
||||
- [get_context](#get_context)
|
||||
- [get_node](#get_node)
|
||||
- [get_druid](#get_druid)
|
||||
- [get_name](#get_name)
|
||||
- [get_parent_name](#get_parent_name)
|
||||
- [get_input_priority](#get_input_priority)
|
||||
- [set_input_priority](#set_input_priority)
|
||||
- [reset_input_priority](#reset_input_priority)
|
||||
- [get_uid](#get_uid)
|
||||
- [set_input_enabled](#set_input_enabled)
|
||||
- [get_input_enabled](#get_input_enabled)
|
||||
- [get_parent_component](#get_parent_component)
|
||||
- [get_nodes](#get_nodes)
|
||||
- [get_childrens](#get_childrens)
|
||||
|
||||
|
||||
## Fields
|
||||
- [druid](#druid)
|
||||
|
||||
|
||||
|
||||
### create
|
||||
|
||||
---
|
||||
```lua
|
||||
component.create([name], [input_priority])
|
||||
```
|
||||
|
||||
Сreate a new component class, which will inherit from the base Druid component.
|
||||
|
||||
- **Parameters:**
|
||||
- `[name]` *(string|nil)*: The name of the component
|
||||
- `[input_priority]` *(number|nil)*: The input priority. The bigger number processed first. Default value: 10
|
||||
|
||||
- **Returns:**
|
||||
- `` *(druid.component)*:
|
||||
|
||||
### create_widget
|
||||
|
||||
---
|
||||
```lua
|
||||
component.create_widget(self, widget_class, context)
|
||||
```
|
||||
|
||||
Create the Druid component instance
|
||||
|
||||
- **Parameters:**
|
||||
- `self` *(druid.instance)*: The Druid Factory used to create components
|
||||
- `widget_class` *(druid.widget)*:
|
||||
- `context` *(table)*:
|
||||
|
||||
- **Returns:**
|
||||
- `` *(druid.widget)*:
|
||||
|
||||
### init
|
||||
|
||||
---
|
||||
```lua
|
||||
component:init()
|
||||
```
|
||||
|
||||
Called when component is created
|
||||
|
||||
### update
|
||||
|
||||
---
|
||||
```lua
|
||||
component:update()
|
||||
```
|
||||
|
||||
Called every frame
|
||||
|
||||
### on_remove
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_remove()
|
||||
```
|
||||
|
||||
Called when component is removed
|
||||
|
||||
### on_input
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_input()
|
||||
```
|
||||
|
||||
Called when input event is triggered
|
||||
|
||||
### on_input_interrupt
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_input_interrupt()
|
||||
```
|
||||
|
||||
Called when input event is consumed before
|
||||
|
||||
### on_message
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_message()
|
||||
```
|
||||
|
||||
Called when message is received
|
||||
|
||||
### on_late_init
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_late_init()
|
||||
```
|
||||
|
||||
Called before update once time after GUI init
|
||||
|
||||
### on_focus_lost
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_focus_lost()
|
||||
```
|
||||
|
||||
Called when app lost focus
|
||||
|
||||
### on_focus_gained
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_focus_gained()
|
||||
```
|
||||
|
||||
Called when app gained focus
|
||||
|
||||
### on_style_change
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_style_change()
|
||||
```
|
||||
|
||||
Called when style is changed
|
||||
|
||||
### on_layout_change
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_layout_change()
|
||||
```
|
||||
|
||||
Called when GUI layout is changed
|
||||
|
||||
### on_window_resized
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_window_resized()
|
||||
```
|
||||
|
||||
Called when window is resized
|
||||
|
||||
### on_language_change
|
||||
|
||||
---
|
||||
```lua
|
||||
component:on_language_change()
|
||||
```
|
||||
|
||||
Called when language is changed
|
||||
|
||||
### set_style
|
||||
|
||||
---
|
||||
```lua
|
||||
component:set_style([druid_style])
|
||||
```
|
||||
|
||||
Set component style. Pass nil to clear style
|
||||
|
||||
- **Parameters:**
|
||||
- `[druid_style]` *(table|nil)*:
|
||||
|
||||
- **Returns:**
|
||||
- `self` *(<T>)*: The component itself for chaining
|
||||
|
||||
### set_template
|
||||
|
||||
---
|
||||
```lua
|
||||
component:set_template([template])
|
||||
```
|
||||
|
||||
Set component template name. Pass nil to clear template.
|
||||
This template id used to access nodes inside the template on GUI scene.
|
||||
Parent template will be added automatically if exist.
|
||||
|
||||
- **Parameters:**
|
||||
- `[template]` *(string|nil)*:
|
||||
|
||||
- **Returns:**
|
||||
- `self` *(<T>)*: The component itself for chaining
|
||||
|
||||
### get_template
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_template()
|
||||
```
|
||||
|
||||
Get full template name.
|
||||
|
||||
- **Returns:**
|
||||
- `` *(string)*:
|
||||
|
||||
### set_nodes
|
||||
|
||||
---
|
||||
```lua
|
||||
component:set_nodes(nodes)
|
||||
```
|
||||
|
||||
Set current component nodes, returned from `gui.clone_tree` function.
|
||||
|
||||
- **Parameters:**
|
||||
- `nodes` *(table<hash, node>)*:
|
||||
|
||||
- **Returns:**
|
||||
- `` *(druid.component)*:
|
||||
|
||||
### get_context
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_context()
|
||||
```
|
||||
|
||||
Return current component context
|
||||
|
||||
- **Returns:**
|
||||
- `context` *(any)*: Usually it's self of script but can be any other Druid component
|
||||
|
||||
### get_node
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_node(node_id)
|
||||
```
|
||||
|
||||
Get component node by node_id. Respect to current template and nodes.
|
||||
|
||||
- **Parameters:**
|
||||
- `node_id` *(string|node)*:
|
||||
|
||||
- **Returns:**
|
||||
- `` *(node)*:
|
||||
|
||||
### get_druid
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_druid([template], [nodes])
|
||||
```
|
||||
|
||||
Get Druid instance for inner component creation.
|
||||
|
||||
- **Parameters:**
|
||||
- `[template]` *(string|nil)*:
|
||||
- `[nodes]` *(table<hash, node>|nil)*:
|
||||
|
||||
- **Returns:**
|
||||
- `` *(druid.instance)*:
|
||||
|
||||
### get_name
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_name()
|
||||
```
|
||||
|
||||
Get component name
|
||||
|
||||
- **Returns:**
|
||||
- `name` *(string)*: The component name + uid
|
||||
|
||||
### get_parent_name
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_parent_name()
|
||||
```
|
||||
|
||||
Get parent component name
|
||||
|
||||
- **Returns:**
|
||||
- `parent_name` *(string|nil)*: The parent component name if exist or nil
|
||||
|
||||
### get_input_priority
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_input_priority()
|
||||
```
|
||||
|
||||
Get component input priority, the bigger number processed first. Default value: 10
|
||||
|
||||
- **Returns:**
|
||||
- `` *(number)*:
|
||||
|
||||
### set_input_priority
|
||||
|
||||
---
|
||||
```lua
|
||||
component:set_input_priority(value, [is_temporary])
|
||||
```
|
||||
|
||||
Set component input priority, the bigger number processed first. Default value: 10
|
||||
|
||||
- **Parameters:**
|
||||
- `value` *(number)*:
|
||||
- `[is_temporary]` *(boolean|nil)*: If true, the reset input priority will return to previous value
|
||||
|
||||
- **Returns:**
|
||||
- `self` *(druid.component)*: The component itself for chaining
|
||||
|
||||
### reset_input_priority
|
||||
|
||||
---
|
||||
```lua
|
||||
component:reset_input_priority()
|
||||
```
|
||||
|
||||
Reset component input priority to it's default value, that was set in `create` function or `set_input_priority`
|
||||
|
||||
- **Returns:**
|
||||
- `self` *(druid.component)*: The component itself for chaining
|
||||
|
||||
### get_uid
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_uid()
|
||||
```
|
||||
|
||||
Get component UID, unique identifier created in component creation order.
|
||||
|
||||
- **Returns:**
|
||||
- `uid` *(number)*: The component uid
|
||||
|
||||
### set_input_enabled
|
||||
|
||||
---
|
||||
```lua
|
||||
component:set_input_enabled(state)
|
||||
```
|
||||
|
||||
Set component input state. By default it's enabled.
|
||||
If input is disabled, the component will not receive input events.
|
||||
Recursive for all children components.
|
||||
|
||||
- **Parameters:**
|
||||
- `state` *(boolean)*:
|
||||
|
||||
- **Returns:**
|
||||
- `self` *(druid.component)*: The component itself for chaining
|
||||
|
||||
### get_input_enabled
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_input_enabled()
|
||||
```
|
||||
|
||||
Get component input state. By default it's enabled. Can be disabled by `set_input_enabled` function.
|
||||
|
||||
- **Returns:**
|
||||
- `` *(boolean)*:
|
||||
|
||||
### get_parent_component
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_parent_component()
|
||||
```
|
||||
|
||||
Get parent component
|
||||
|
||||
- **Returns:**
|
||||
- `parent_component` *(druid.component|nil)*: The parent component if exist or nil
|
||||
|
||||
### get_nodes
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_nodes()
|
||||
```
|
||||
|
||||
Get current component nodes
|
||||
|
||||
- **Returns:**
|
||||
- `` *(table<hash, node>|nil)*:
|
||||
|
||||
### get_childrens
|
||||
|
||||
---
|
||||
```lua
|
||||
component:get_childrens()
|
||||
```
|
||||
|
||||
Return all children components, recursive
|
||||
|
||||
- **Returns:**
|
||||
- `Array` *(table)*: of childrens if the Druid component instance
|
||||
|
||||
|
||||
## Fields
|
||||
<a name="druid"></a>
|
||||
- **druid** (_druid.instance_): Druid instance to create inner components
|
||||
|
@@ -28,7 +28,8 @@
|
||||
|
||||
# API Reference
|
||||
|
||||
## Druid
|
||||
## [Druid](druid_api.md)
|
||||
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
|
||||
@@ -42,7 +43,7 @@ druid.set_text_function(callback)
|
||||
self.druid = druid.new(context, [style])
|
||||
```
|
||||
|
||||
## Druid Instance
|
||||
## [Druid Instance](druid_instance_api.md)
|
||||
```lua
|
||||
-- Lifecycle
|
||||
self.druid:final()
|
||||
@@ -82,7 +83,7 @@ self.druid:set_whitelist(whitelist_components)
|
||||
|
||||
## Components
|
||||
|
||||
### Base Component
|
||||
### [Base Component](components/base/component_api.md)
|
||||
|
||||
Basic methods for all components.
|
||||
|
||||
@@ -103,7 +104,7 @@ component:set_style([druid_style])
|
||||
component:set_template([template])
|
||||
```
|
||||
|
||||
### Blocker
|
||||
### [Blocker](components/base/blocker_api.md)
|
||||
|
||||
```lua
|
||||
local blocker = self.druid:new_blocker(node)
|
||||
@@ -112,7 +113,7 @@ blocker:is_enabled()
|
||||
blocker:set_enabled(state)
|
||||
```
|
||||
|
||||
### Button
|
||||
### [Button](components/base/button_api.md)
|
||||
|
||||
```lua
|
||||
local button = self.druid:new_button(node, [callback], [params], [anim_node])
|
||||
@@ -126,7 +127,7 @@ button:set_key_trigger(key)
|
||||
button:set_web_user_interaction([is_web_mode])
|
||||
```
|
||||
|
||||
### Container
|
||||
### [Container](components/extended/container_api.md)
|
||||
|
||||
```lua
|
||||
local container = self.druid:new_container(node, [mode], [callback])
|
||||
@@ -153,7 +154,7 @@ container:set_size([width], [height], [anchor_pivot])
|
||||
container:update_child_containers()
|
||||
```
|
||||
|
||||
### Data List
|
||||
### [Data List](components/extended/data_list_api.md)
|
||||
|
||||
```lua
|
||||
local data_list = self.druid:new_data_list(druid_scroll, druid_grid, create_function)
|
||||
@@ -171,7 +172,7 @@ data_list:set_data(data)
|
||||
data_list:set_use_cache(is_use_cache)
|
||||
```
|
||||
|
||||
### Drag
|
||||
### [Drag](components/base/drag_api.md)
|
||||
|
||||
```lua
|
||||
local drag = self.druid:new_drag(node, [on_drag_callback])
|
||||
@@ -183,7 +184,7 @@ drag:set_drag_cursors(is_enabled)
|
||||
drag:set_enabled(is_enabled)
|
||||
```
|
||||
|
||||
### Grid
|
||||
### [Grid](components/base/static_grid_api.md)
|
||||
|
||||
```lua
|
||||
local grid = self.druid:new_grid(parent_node, item, [in_row])
|
||||
@@ -209,7 +210,7 @@ grid:set_position_function(callback)
|
||||
grid:sort_nodes(comparator)
|
||||
```
|
||||
|
||||
### Hotkey
|
||||
### [Hotkey](components/extended/hotkey_api.md)
|
||||
|
||||
```lua
|
||||
local hotkey = self.druid:new_hotkey(keys_array, [callback], [callback_argument])
|
||||
@@ -220,7 +221,7 @@ hotkey:on_focus_gained()
|
||||
hotkey:set_repeat(is_enabled_repeated)
|
||||
```
|
||||
|
||||
### Hover
|
||||
### [Hover](components/base/hover_api.md)
|
||||
|
||||
```lua
|
||||
local hover = self.druid:new_hover(node, [on_hover_callback], [on_mouse_hover_callback])
|
||||
@@ -234,7 +235,7 @@ hover:set_hover([state])
|
||||
hover:set_mouse_hover([state])
|
||||
```
|
||||
|
||||
### Input
|
||||
### [Input](components/extended/input_api.md)
|
||||
|
||||
```lua
|
||||
local input = self.druid:new_input(click_node, text_node, [keyboard_type])
|
||||
@@ -253,7 +254,7 @@ input:set_text(input_text)
|
||||
input:unselect()
|
||||
```
|
||||
|
||||
### Lang Text
|
||||
### [Lang Text](components/extended/lang_text_api.md)
|
||||
|
||||
```lua
|
||||
local lang_text = self.druid:new_lang_text(node, [locale_id], [adjust_type])
|
||||
@@ -265,7 +266,7 @@ lang_text:set_to(text)
|
||||
lang_text:translate(locale_id, [a], [b], [c], [d], [e], [f], [g])
|
||||
```
|
||||
|
||||
### Layout
|
||||
### [Layout](components/extended/layout_api.md)
|
||||
|
||||
```lua
|
||||
local layout = self.druid:new_layout(node, [mode])
|
||||
@@ -290,7 +291,7 @@ layout:set_type(type)
|
||||
layout:update()
|
||||
```
|
||||
|
||||
### Progress
|
||||
### [Progress](components/extended/progress_api.md)
|
||||
|
||||
```lua
|
||||
local progress = self.druid:new_progress(node, key, [init_value])
|
||||
@@ -305,7 +306,7 @@ progress:to(to, [callback])
|
||||
progress:update([dt])
|
||||
```
|
||||
|
||||
### Rich Input
|
||||
### [Rich Input](components/custom/rich_input_api.md)
|
||||
|
||||
```lua
|
||||
local rich_input = self.druid:new_rich_input(template, [nodes])
|
||||
@@ -318,7 +319,7 @@ rich_input:set_placeholder(placeholder_text)
|
||||
rich_input:set_text(text)
|
||||
```
|
||||
|
||||
### Rich Text
|
||||
### [Rich Text](components/custom/rich_text_api.md)
|
||||
|
||||
```lua
|
||||
local rich_text = self.druid:new_rich_text(text_node, [value])
|
||||
@@ -332,7 +333,7 @@ rich_text:set_text([text])
|
||||
rich_text:tagged(tag)
|
||||
```
|
||||
|
||||
### Scroll
|
||||
### [Scroll](components/base/scroll_api.md)
|
||||
|
||||
```lua
|
||||
local scroll = self.druid:new_scroll(view_node, content_node)
|
||||
@@ -357,7 +358,7 @@ scroll:update([dt])
|
||||
scroll:update_view_size()
|
||||
```
|
||||
|
||||
### Slider
|
||||
### [Slider](components/extended/slider_api.md)
|
||||
|
||||
```lua
|
||||
local slider = self.druid:new_slider(pin_node, end_pos, [callback])
|
||||
@@ -369,7 +370,7 @@ slider:set_input_node([input_node])
|
||||
slider:set_steps(steps)
|
||||
```
|
||||
|
||||
### Swipe
|
||||
### [Swipe](components/extended/swipe_api.md)
|
||||
|
||||
```lua
|
||||
local swipe = self.druid:new_swipe(node, [on_swipe_callback])
|
||||
@@ -377,7 +378,7 @@ local swipe = self.druid:new_swipe(node, [on_swipe_callback])
|
||||
swipe:set_click_zone([zone])
|
||||
```
|
||||
|
||||
### Text
|
||||
### [Text](components/base/text_api.md)
|
||||
|
||||
```lua
|
||||
local text = self.druid:new_text(node, [value], [no_adjust])
|
||||
@@ -398,7 +399,7 @@ text:set_text_adjust([adjust_type], [minimal_scale])
|
||||
text:set_to(set_to)
|
||||
```
|
||||
|
||||
### Timer
|
||||
### [Timer](components/extended/timer_api.md)
|
||||
|
||||
```lua
|
||||
local timer = self.druid:new_timer(node, [seconds_from], [seconds_to], [callback])
|
||||
@@ -409,7 +410,7 @@ timer:set_to(set_to)
|
||||
timer:update([dt])
|
||||
```
|
||||
|
||||
## Helper
|
||||
## [Helper](druid_helper_api.md)
|
||||
|
||||
```lua
|
||||
local helper = require("druid.helper")
|
||||
|
Reference in New Issue
Block a user