Test new markdown api generator

This commit is contained in:
Insality 2025-03-14 20:29:05 +02:00
parent 11aeb377c2
commit b30cf9109e
74 changed files with 5581 additions and 2656 deletions

View File

@ -0,0 +1,73 @@
# druid.blocker API
> at /druid/base/blocker.lua
## Functions
- [init](#init)
- [on_input](#on_input)
- [set_enabled](#set_enabled)
- [is_enabled](#is_enabled)
## Fields
- [node](#node)
### init
---
```lua
blocker:init(node)
```
- **Parameters:**
- `node` *(node)*:
### on_input
---
```lua
blocker:on_input(action_id, action)
```
- **Parameters:**
- `action_id` *(string)*:
- `action` *(table)*:
- **Returns:**
- `` *(boolean)*:
### set_enabled
---
```lua
blocker:set_enabled(state)
```
Set blocker enabled state
- **Parameters:**
- `state` *(boolean)*:
- **Returns:**
- `self` *(druid.blocker)*:
### is_enabled
---
```lua
blocker:is_enabled()
```
Get blocker enabled state
- **Returns:**
- `` *(boolean)*:
## Fields
<a name="node"></a>
- **node** (_node_)

View File

@ -0,0 +1,284 @@
# druid.button API
> at /druid/base/button.lua
Druid component to make clickable node with various interaction callbacks
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_late_init](#on_late_init)
- [on_input](#on_input)
- [on_input_interrupt](#on_input_interrupt)
- [set_enabled](#set_enabled)
- [is_enabled](#is_enabled)
- [set_click_zone](#set_click_zone)
- [set_key_trigger](#set_key_trigger)
- [get_key_trigger](#get_key_trigger)
- [set_check_function](#set_check_function)
- [set_web_user_interaction](#set_web_user_interaction)
## Fields
- [on_click](#on_click)
- [on_pressed](#on_pressed)
- [on_repeated_click](#on_repeated_click)
- [on_long_click](#on_long_click)
- [on_double_click](#on_double_click)
- [on_hold_callback](#on_hold_callback)
- [on_click_outside](#on_click_outside)
- [node](#node)
- [node_id](#node_id)
- [anim_node](#anim_node)
- [params](#params)
- [hover](#hover)
- [click_zone](#click_zone)
- [start_scale](#start_scale)
- [start_pos](#start_pos)
- [disabled](#disabled)
- [key_trigger](#key_trigger)
- [style](#style)
- [druid](#druid)
- [is_repeated_started](#is_repeated_started)
- [last_pressed_time](#last_pressed_time)
- [last_released_time](#last_released_time)
- [click_in_row](#click_in_row)
- [can_action](#can_action)
### init
---
```lua
button:init(node_or_node_id, [callback], [custom_args], [anim_node])
```
- **Parameters:**
- `node_or_node_id` *(string|node)*: Node name or GUI Node itself
- `[callback]` *(fun()|nil)*: Callback on button click
- `[custom_args]` *(any)*: Custom args for any Button event
- `[anim_node]` *(string|node|nil)*: Node to animate instead of trigger node
### on_style_change
---
```lua
button:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.button.style)*: Button style params.
You can override this component styles params in Druid styles table or create your own style
### on_late_init
---
```lua
button:on_late_init()
```
### on_input
---
```lua
button:on_input(action_id, action)
```
- **Parameters:**
- `action_id` *(hash)*:
- `action` *(table)*:
- **Returns:**
- `` *(boolean)*:
### on_input_interrupt
---
```lua
button:on_input_interrupt()
```
### set_enabled
---
```lua
button:set_enabled([state])
```
Set button enabled state.
The style.on_set_enabled will be triggered.
Disabled button is not clickable.
- **Parameters:**
- `[state]` *(boolean|nil)*: Enabled state
- **Returns:**
- `self` *(druid.button)*:
### is_enabled
---
```lua
button:is_enabled()
```
Get button enabled state.
By default all Buttons is enabled on creating.
- **Returns:**
- `is_enabled` *(boolean)*: True, if button is enabled now, False overwise
### set_click_zone
---
```lua
button:set_click_zone([zone])
```
Set additional button click area.
Useful to restrict click outside out stencil node or scrollable content.
If button node placed inside stencil node, it will be automatically set to this stencil node.
- **Parameters:**
- `[zone]` *(string|node|nil)*: Gui node
- **Returns:**
- `self` *(druid.button)*:
### set_key_trigger
---
```lua
button:set_key_trigger(key)
```
Set key name to trigger this button by keyboard.
- **Parameters:**
- `key` *(string|hash)*: The action_id of the input key. Example: "key_space"
- **Returns:**
- `self` *(druid.button)*:
### get_key_trigger
---
```lua
button:get_key_trigger()
```
Get current key name to trigger this button.
- **Returns:**
- `key_trigger` *(hash)*: The action_id of the input key
### set_check_function
---
```lua
button:set_check_function([check_function], [failure_callback])
```
Set function for additional check for button click availability
- **Parameters:**
- `[check_function]` *(function|nil)*: Should return true or false. If true - button can be pressed.
- `[failure_callback]` *(function|nil)*: Function will be called on button click, if check function return false
- **Returns:**
- `self` *(druid.button)*:
### set_web_user_interaction
---
```lua
button:set_web_user_interaction([is_web_mode])
```
Set Button mode to work inside user HTML5 interaction event.
It's required to make protected things like copy & paste text, show mobile keyboard, etc
The HTML5 button's doesn't call any events except on_click event.
If the game is not HTML, html mode will be not enabled
- **Parameters:**
- `[is_web_mode]` *(boolean|nil)*: If true - button will be called inside html5 callback
- **Returns:**
- `self` *(druid.button)*:
## Fields
<a name="on_click"></a>
- **on_click** (_event_): function(self, custom_args, button_instance)
<a name="on_pressed"></a>
- **on_pressed** (_event_): function(self, custom_args, button_instance)
<a name="on_repeated_click"></a>
- **on_repeated_click** (_event_): function(self, custom_args, button_instance, click_count)
<a name="on_long_click"></a>
- **on_long_click** (_event_): function(self, custom_args, button_instance, hold_time)
<a name="on_double_click"></a>
- **on_double_click** (_event_): function(self, custom_args, button_instance, click_amount)
<a name="on_hold_callback"></a>
- **on_hold_callback** (_event_): function(self, custom_args, button_instance, press_time)
<a name="on_click_outside"></a>
- **on_click_outside** (_event_): function(self, custom_args, button_instance)
<a name="node"></a>
- **node** (_node_): Clickable node
<a name="node_id"></a>
- **node_id** (_hash_): Node id
<a name="anim_node"></a>
- **anim_node** (_node_): Animation node. In default case equals to clickable node
<a name="params"></a>
- **params** (_any_): Custom arguments for any Button event
<a name="hover"></a>
- **hover** (_druid.hover_): Hover component for this button
<a name="click_zone"></a>
- **click_zone** (_node_): Click zone node to restrict click area
<a name="start_scale"></a>
- **start_scale** (_vector3_): Start scale of the button
<a name="start_pos"></a>
- **start_pos** (_vector3_): Start position of the button
<a name="disabled"></a>
- **disabled** (_boolean_): Is button disabled
<a name="key_trigger"></a>
- **key_trigger** (_hash_): Key trigger for this button
<a name="style"></a>
- **style** (_table_): Style for this button
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="is_repeated_started"></a>
- **is_repeated_started** (_boolean_)
<a name="last_pressed_time"></a>
- **last_pressed_time** (_integer_)
<a name="last_released_time"></a>
- **last_released_time** (_integer_)
<a name="click_in_row"></a>
- **click_in_row** (_integer_)
<a name="can_action"></a>
- **can_action** (_boolean_): Can't interact, if touch outside of button

View File

@ -0,0 +1,222 @@
# druid.drag API
> at /druid/base/drag.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [set_drag_cursors](#set_drag_cursors)
- [on_late_init](#on_late_init)
- [on_window_resized](#on_window_resized)
- [on_input_interrupt](#on_input_interrupt)
- [on_input](#on_input)
- [set_click_zone](#set_click_zone)
- [set_enabled](#set_enabled)
- [is_enabled](#is_enabled)
## Fields
- [node](#node)
- [on_touch_start](#on_touch_start)
- [on_touch_end](#on_touch_end)
- [on_drag_start](#on_drag_start)
- [on_drag](#on_drag)
- [on_drag_end](#on_drag_end)
- [style](#style)
- [click_zone](#click_zone)
- [is_touch](#is_touch)
- [is_drag](#is_drag)
- [can_x](#can_x)
- [can_y](#can_y)
- [dx](#dx)
- [dy](#dy)
- [touch_id](#touch_id)
- [x](#x)
- [y](#y)
- [screen_x](#screen_x)
- [screen_y](#screen_y)
- [touch_start_pos](#touch_start_pos)
- [druid](#druid)
- [hover](#hover)
### init
---
```lua
drag:init(node_or_node_id, on_drag_callback)
```
- **Parameters:**
- `node_or_node_id` *(string|node)*:
- `on_drag_callback` *(function)*:
### on_style_change
---
```lua
drag:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.drag.style)*:
### set_drag_cursors
---
```lua
drag:set_drag_cursors(is_enabled)
```
Set Drag component enabled state.
- **Parameters:**
- `is_enabled` *(boolean)*:
### on_late_init
---
```lua
drag:on_late_init()
```
### on_window_resized
---
```lua
drag:on_window_resized()
```
### on_input_interrupt
---
```lua
drag:on_input_interrupt()
```
### on_input
---
```lua
drag:on_input(action_id, action)
```
- **Parameters:**
- `action_id` *(hash)*:
- `action` *(table)*:
- **Returns:**
- `` *(boolean)*:
### set_click_zone
---
```lua
drag:set_click_zone([node])
```
Set Drag click zone
- **Parameters:**
- `[node]` *(string|node|nil)*:
- **Returns:**
- `self` *(druid.drag)*: Current instance
### set_enabled
---
```lua
drag:set_enabled(is_enabled)
```
Set Drag component enabled state.
- **Parameters:**
- `is_enabled` *(boolean)*:
- **Returns:**
- `self` *(druid.drag)*: Current instance
### is_enabled
---
```lua
drag:is_enabled()
```
Check if Drag component is capture input
- **Returns:**
- `` *(boolean)*:
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="on_touch_start"></a>
- **on_touch_start** (_event_)
<a name="on_touch_end"></a>
- **on_touch_end** (_event_)
<a name="on_drag_start"></a>
- **on_drag_start** (_event_)
<a name="on_drag"></a>
- **on_drag** (_event_)
<a name="on_drag_end"></a>
- **on_drag_end** (_event_)
<a name="style"></a>
- **style** (_druid.drag.style_)
<a name="click_zone"></a>
- **click_zone** (_node_)
<a name="is_touch"></a>
- **is_touch** (_boolean_)
<a name="is_drag"></a>
- **is_drag** (_boolean_)
<a name="can_x"></a>
- **can_x** (_boolean_)
<a name="can_y"></a>
- **can_y** (_boolean_)
<a name="dx"></a>
- **dx** (_number_)
<a name="dy"></a>
- **dy** (_number_)
<a name="touch_id"></a>
- **touch_id** (_number_)
<a name="x"></a>
- **x** (_number_)
<a name="y"></a>
- **y** (_number_)
<a name="screen_x"></a>
- **screen_x** (_number_)
<a name="screen_y"></a>
- **screen_y** (_number_)
<a name="touch_start_pos"></a>
- **touch_start_pos** (_vector3_)
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="hover"></a>
- **hover** (_druid.hover_)

View File

@ -0,0 +1,182 @@
# druid.hover API
> at /druid/base/hover.lua
## Functions
- [init](#init)
- [on_late_init](#on_late_init)
- [on_style_change](#on_style_change)
- [on_input](#on_input)
- [on_input_interrupt](#on_input_interrupt)
- [set_hover](#set_hover)
- [is_hovered](#is_hovered)
- [set_mouse_hover](#set_mouse_hover)
- [is_mouse_hovered](#is_mouse_hovered)
- [set_click_zone](#set_click_zone)
- [set_enabled](#set_enabled)
- [is_enabled](#is_enabled)
## Fields
- [node](#node)
- [on_hover](#on_hover)
- [on_mouse_hover](#on_mouse_hover)
- [style](#style)
- [click_zone](#click_zone)
### init
---
```lua
hover:init(node, on_hover_callback, on_mouse_hover)
```
- **Parameters:**
- `node` *(node)*: Gui node
- `on_hover_callback` *(function)*: Hover callback
- `on_mouse_hover` *(function)*: On mouse hover callback
### on_late_init
---
```lua
hover:on_late_init()
```
### on_style_change
---
```lua
hover:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.hover.style)*:
### on_input
---
```lua
hover:on_input(action_id, action)
```
- **Parameters:**
- `action_id` *(hash)*:
- `action` *(table)*:
- **Returns:**
- `` *(boolean)*:
### on_input_interrupt
---
```lua
hover:on_input_interrupt()
```
### set_hover
---
```lua
hover:set_hover([state])
```
Set hover state
- **Parameters:**
- `[state]` *(boolean|nil)*: The hover state
### is_hovered
---
```lua
hover:is_hovered()
```
Return current hover state. True if touch action was on the node at current time
- **Returns:**
- `is_hovered` *(boolean)*: The current hovered state
### set_mouse_hover
---
```lua
hover:set_mouse_hover([state])
```
Set mouse hover state
- **Parameters:**
- `[state]` *(boolean|nil)*: The mouse hover state
### is_mouse_hovered
---
```lua
hover:is_mouse_hovered()
```
Return current hover state. True if nil action_id (usually desktop mouse) was on the node at current time
- **Returns:**
- `The` *(boolean)*: current hovered state
### set_click_zone
---
```lua
hover:set_click_zone([zone])
```
Strict hover click area. Useful for no click events outside stencil node
- **Parameters:**
- `[zone]` *(string|node|nil)*: Gui node
### set_enabled
---
```lua
hover:set_enabled([state])
```
Set enable state of hover component.
If hover is not enabled, it will not generate
any hover events
- **Parameters:**
- `[state]` *(boolean|nil)*: The hover enabled state
### is_enabled
---
```lua
hover:is_enabled()
```
Return current hover enabled state
- **Returns:**
- `The` *(boolean)*: hover enabled state
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="on_hover"></a>
- **on_hover** (_event_)
<a name="on_mouse_hover"></a>
- **on_mouse_hover** (_event_)
<a name="style"></a>
- **style** (_druid.hover.style_)
<a name="click_zone"></a>
- **click_zone** (_node_)

View File

@ -0,0 +1,438 @@
# druid.scroll API
> at /druid/base/scroll.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_late_init](#on_late_init)
- [on_layout_change](#on_layout_change)
- [update](#update)
- [on_input](#on_input)
- [on_remove](#on_remove)
- [scroll_to](#scroll_to)
- [scroll_to_index](#scroll_to_index)
- [scroll_to_percent](#scroll_to_percent)
- [get_percent](#get_percent)
- [set_size](#set_size)
- [set_view_size](#set_view_size)
- [update_view_size](#update_view_size)
- [set_inert](#set_inert)
- [is_inert](#is_inert)
- [set_extra_stretch_size](#set_extra_stretch_size)
- [get_scroll_size](#get_scroll_size)
- [set_points](#set_points)
- [set_horizontal_scroll](#set_horizontal_scroll)
- [set_vertical_scroll](#set_vertical_scroll)
- [is_node_in_view](#is_node_in_view)
- [bind_grid](#bind_grid)
- [set_click_zone](#set_click_zone)
## Fields
- [node](#node)
- [click_zone](#click_zone)
- [on_scroll](#on_scroll)
- [on_scroll_to](#on_scroll_to)
- [on_point_scroll](#on_point_scroll)
- [view_node](#view_node)
- [view_border](#view_border)
- [content_node](#content_node)
- [view_size](#view_size)
- [position](#position)
- [target_position](#target_position)
- [available_pos](#available_pos)
- [available_size](#available_size)
- [drag](#drag)
- [selected](#selected)
- [is_animate](#is_animate)
- [style](#style)
- [druid](#druid)
- [hover](#hover)
- [points](#points)
- [available_pos_extra](#available_pos_extra)
- [available_size_extra](#available_size_extra)
### init
---
```lua
scroll:init(view_node, content_node)
```
The Scroll constructor
- **Parameters:**
- `view_node` *(string|node)*: GUI view scroll node
- `content_node` *(string|node)*: GUI content scroll node
### on_style_change
---
```lua
scroll:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.scroll.style)*: Scroll style parameters
### on_late_init
---
```lua
scroll:on_late_init()
```
### on_layout_change
---
```lua
scroll:on_layout_change()
```
### update
---
```lua
scroll:update([dt])
```
- **Parameters:**
- `[dt]` *(any)*:
### on_input
---
```lua
scroll:on_input([action_id], [action])
```
- **Parameters:**
- `[action_id]` *(any)*:
- `[action]` *(any)*:
- **Returns:**
- `` *(boolean)*:
### on_remove
---
```lua
scroll:on_remove()
```
### scroll_to
---
```lua
scroll:scroll_to(point, [is_instant])
```
Start scroll to target point.
- **Parameters:**
- `point` *(vector3)*: Target point
- `[is_instant]` *(boolean|nil)*: Instant scroll flag
### scroll_to_index
---
```lua
scroll:scroll_to_index(index, [skip_cb])
```
Scroll to item in scroll by point index.
- **Parameters:**
- `index` *(number)*: Point index
- `[skip_cb]` *(boolean|nil)*: If true, skip the point callback
### scroll_to_percent
---
```lua
scroll:scroll_to_percent(percent, [is_instant])
```
Start scroll to target scroll percent
- **Parameters:**
- `percent` *(vector3)*: target percent
- `[is_instant]` *(boolean|nil)*: instant scroll flag
### get_percent
---
```lua
scroll:get_percent()
```
Return current scroll progress status.
Values will be in [0..1] interval
- **Returns:**
- `New` *(vector3)*: vector with scroll progress values
### set_size
---
```lua
scroll:set_size(size, [offset])
```
Set scroll content size.
It will change content gui node size
- **Parameters:**
- `size` *(vector3)*: The new size for content node
- `[offset]` *(vector3|nil)*: Offset value to set, where content is starts
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### set_view_size
---
```lua
scroll:set_view_size(size)
```
Set new scroll view size in case the node size was changed.
- **Parameters:**
- `size` *(vector3)*: The new size for view node
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### update_view_size
---
```lua
scroll:update_view_size()
```
Refresh scroll view size
- **Returns:**
- `` *(druid.scroll)*:
### set_inert
---
```lua
scroll:set_inert(state)
```
Enable or disable scroll inert
If disabled, scroll through points (if exist)
If no points, just simple drag without inertion
- **Parameters:**
- `state` *(boolean)*: Inert scroll state
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### is_inert
---
```lua
scroll:is_inert()
```
Return if scroll have inertion
- **Returns:**
- `is_inert` *(boolean)*: If scroll have inertion
### set_extra_stretch_size
---
```lua
scroll:set_extra_stretch_size([stretch_size])
```
Set extra size for scroll stretching
Set 0 to disable stretching effect
- **Parameters:**
- `[stretch_size]` *(number|nil)*: Size in pixels of additional scroll area
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### get_scroll_size
---
```lua
scroll:get_scroll_size()
```
Return vector of scroll size with width and height.
- **Returns:**
- `Available` *(vector3)*: scroll size
### set_points
---
```lua
scroll:set_points(points)
```
Set points of interest.
Scroll will always centered on closer points
- **Parameters:**
- `points` *(table)*: Array of vector3 points
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### set_horizontal_scroll
---
```lua
scroll:set_horizontal_scroll(state)
```
Lock or unlock horizontal scroll
- **Parameters:**
- `state` *(boolean)*: True, if horizontal scroll is enabled
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### set_vertical_scroll
---
```lua
scroll:set_vertical_scroll(state)
```
Lock or unlock vertical scroll
- **Parameters:**
- `state` *(boolean)*: True, if vertical scroll is enabled
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### is_node_in_view
---
```lua
scroll:is_node_in_view(node)
```
Check node if it visible now on scroll.
Extra border is not affected. Return true for elements in extra scroll zone
- **Parameters:**
- `node` *(node)*: The node to check
- **Returns:**
- `True` *(boolean)*: if node in visible scroll area
### bind_grid
---
```lua
scroll:bind_grid([grid])
```
Bind the grid component (Static or Dynamic) to recalculate
scroll size on grid changes
- **Parameters:**
- `[grid]` *(druid.grid|nil)*: Druid grid component
- **Returns:**
- `Current` *(druid.scroll)*: scroll instance
### set_click_zone
---
```lua
scroll:set_click_zone(node)
```
Strict drag scroll area. Useful for
restrict events outside stencil node
- **Parameters:**
- `node` *(string|node)*: Gui node
## Fields
<a name="node"></a>
- **node** (_node_): The root node
<a name="click_zone"></a>
- **click_zone** (_node_): Optional click zone to restrict scroll area
<a name="on_scroll"></a>
- **on_scroll** (_event_): Triggered on scroll move with (self, position)
<a name="on_scroll_to"></a>
- **on_scroll_to** (_event_): Triggered on scroll_to with (self, target, is_instant)
<a name="on_point_scroll"></a>
- **on_point_scroll** (_event_): Triggered on scroll_to_index with (self, index, point)
<a name="view_node"></a>
- **view_node** (_node_): The scroll view node (static part)
<a name="view_border"></a>
- **view_border** (_vector4_): The scroll view borders
<a name="content_node"></a>
- **content_node** (_node_): The scroll content node (moving part)
<a name="view_size"></a>
- **view_size** (_vector3_): Size of the view node
<a name="position"></a>
- **position** (_vector3_): Current scroll position
<a name="target_position"></a>
- **target_position** (_vector3_): Target scroll position for animations
<a name="available_pos"></a>
- **available_pos** (_vector4_): Available content position (min_x, max_y, max_x, min_y)
<a name="available_size"></a>
- **available_size** (_vector3_): Size of available positions (width, height, 0)
<a name="drag"></a>
- **drag** (_druid.drag_): The drag component instance
<a name="selected"></a>
- **selected** (_number_): Current selected point of interest index
<a name="is_animate"></a>
- **is_animate** (_boolean_): True if scroll is animating
<a name="style"></a>
- **style** (_druid.scroll.style_): Component style parameters
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="hover"></a>
- **hover** (_druid.hover_)
<a name="points"></a>
- **points** (_table_)
<a name="available_pos_extra"></a>
- **available_pos_extra** (_unknown_)
<a name="available_size_extra"></a>
- **available_size_extra** (_vector3_)

View File

@ -0,0 +1,383 @@
# druid.grid API
> at /druid/base/static_grid.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [get_pos](#get_pos)
- [get_index](#get_index)
- [get_index_by_node](#get_index_by_node)
- [on_layout_change](#on_layout_change)
- [set_anchor](#set_anchor)
- [refresh](#refresh)
- [set_pivot](#set_pivot)
- [add](#add)
- [set_items](#set_items)
- [remove](#remove)
- [get_size](#get_size)
- [get_size_for](#get_size_for)
- [get_borders](#get_borders)
- [get_all_pos](#get_all_pos)
- [set_position_function](#set_position_function)
- [clear](#clear)
- [get_offset](#get_offset)
- [set_in_row](#set_in_row)
- [set_item_size](#set_item_size)
- [sort_nodes](#sort_nodes)
## Fields
- [on_add_item](#on_add_item)
- [on_remove_item](#on_remove_item)
- [on_change_items](#on_change_items)
- [on_clear](#on_clear)
- [on_update_positions](#on_update_positions)
- [parent](#parent)
- [nodes](#nodes)
- [first_index](#first_index)
- [last_index](#last_index)
- [anchor](#anchor)
- [pivot](#pivot)
- [node_size](#node_size)
- [border](#border)
- [in_row](#in_row)
- [style](#style)
- [node_pivot](#node_pivot)
### init
---
```lua
grid:init(parent, element, [in_row])
```
- **Parameters:**
- `parent` *(string|node)*: The GUI Node container, where grid's items will be placed
- `element` *(node)*: Element prefab. Need to get it size
- `[in_row]` *(number|nil)*: How many nodes in row can be placed. By default 1
### on_style_change
---
```lua
grid:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.grid.style)*:
### get_pos
---
```lua
grid:get_pos(index)
```
Return pos for grid node index
- **Parameters:**
- `index` *(number)*: The grid element index
- **Returns:**
- `position` *(vector3)*: Node position
### get_index
---
```lua
grid:get_index(pos)
```
Return index for grid pos
- **Parameters:**
- `pos` *(vector3)*: The node position in the grid
- **Returns:**
- `The` *(number)*: node index
### get_index_by_node
---
```lua
grid:get_index_by_node(node)
```
Return grid index by node
- **Parameters:**
- `node` *(node)*: The gui node in the grid
- **Returns:**
- `index` *(number|nil)*: The node index
### on_layout_change
---
```lua
grid:on_layout_change()
```
### set_anchor
---
```lua
grid:set_anchor(anchor)
```
Set grid anchor. Default anchor is equal to anchor of grid parent node
- **Parameters:**
- `anchor` *(vector3)*: Anchor
### refresh
---
```lua
grid:refresh()
```
Update grid content
### set_pivot
---
```lua
grid:set_pivot([pivot])
```
- **Parameters:**
- `[pivot]` *(any)*:
### add
---
```lua
grid:add(item, [index], [shift_policy], [is_instant])
```
Add new item to the grid
- **Parameters:**
- `item` *(node)*: GUI node
- `[index]` *(number|nil)*: The item position. By default add as last item
- `[shift_policy]` *(number|nil)*: How shift nodes, if required. Default: const.SHIFT.RIGHT
- `[is_instant]` *(boolean|nil)*: If true, update node positions instantly
### set_items
---
```lua
grid:set_items(nodes, [is_instant])
```
Set new items to the grid. All previous items will be removed
- **Parameters:**
- `nodes` *(node[])*: The new grid nodes
- `[is_instant]` *(boolean|nil)*: If true, update node positions instantly
### remove
---
```lua
grid:remove(index, [shift_policy], [is_instant])
```
Remove the item from the grid. Note that gui node will be not deleted
- **Parameters:**
- `index` *(number)*: The grid node index to remove
- `[shift_policy]` *(number|nil)*: How shift nodes, if required. Default: const.SHIFT.RIGHT
- `[is_instant]` *(boolean|nil)*: If true, update node positions instantly
- **Returns:**
- `The` *(node)*: deleted gui node from grid
### get_size
---
```lua
grid:get_size()
```
Return grid content size
- **Returns:**
- `The` *(vector3)*: grid content size
### get_size_for
---
```lua
grid:get_size_for([count])
```
- **Parameters:**
- `[count]` *(any)*:
### get_borders
---
```lua
grid:get_borders()
```
Return grid content borders
- **Returns:**
- `The` *(vector4)*: grid content borders
### get_all_pos
---
```lua
grid:get_all_pos()
```
Return array of all node positions
- **Returns:**
- `All` *(vector3[])*: grid node positions
### set_position_function
---
```lua
grid:set_position_function(callback)
```
Change set position function for grid nodes. It will call on
update poses on grid elements. Default: gui.set_position
- **Parameters:**
- `callback` *(function)*: Function on node set position
- **Returns:**
- `Current` *(druid.grid)*: grid instance
### clear
---
```lua
grid:clear()
```
Clear grid nodes array. GUI nodes will be not deleted!
If you want to delete GUI nodes, use static_grid.nodes array before grid:clear
- **Returns:**
- `Current` *(druid.grid)*: grid instance
### get_offset
---
```lua
grid:get_offset()
```
Return StaticGrid offset, where StaticGrid content starts.
- **Returns:**
- `The` *(vector3)*: StaticGrid offset
### set_in_row
---
```lua
grid:set_in_row(in_row)
```
Set new in_row elements for grid
- **Parameters:**
- `in_row` *(number)*: The new in_row value
- **Returns:**
- `Current` *(druid.grid)*: grid instance
### set_item_size
---
```lua
grid:set_item_size([width], [height])
```
Set new node size for grid
- **Parameters:**
- `[width]` *(number|nil)*: The new node width
- `[height]` *(number|nil)*: The new node height
- **Returns:**
- `Current` *(druid.grid)*: grid instance
### sort_nodes
---
```lua
grid:sort_nodes(comparator)
```
Sort grid nodes by custom comparator function
- **Parameters:**
- `comparator` *(function)*: The comparator function. (a, b) -> boolean
- **Returns:**
- `self` *(druid.grid)*: Current grid instance
## Fields
<a name="on_add_item"></a>
- **on_add_item** (_event_)
<a name="on_remove_item"></a>
- **on_remove_item** (_event_)
<a name="on_change_items"></a>
- **on_change_items** (_event_)
<a name="on_clear"></a>
- **on_clear** (_event_)
<a name="on_update_positions"></a>
- **on_update_positions** (_event_)
<a name="parent"></a>
- **parent** (_node_)
<a name="nodes"></a>
- **nodes** (_node[]_)
<a name="first_index"></a>
- **first_index** (_number_)
<a name="last_index"></a>
- **last_index** (_number_)
<a name="anchor"></a>
- **anchor** (_vector3_)
<a name="pivot"></a>
- **pivot** (_vector3_)
<a name="node_size"></a>
- **node_size** (_vector3_)
<a name="border"></a>
- **border** (_vector4_)
<a name="in_row"></a>
- **in_row** (_number_)
<a name="style"></a>
- **style** (_table_)
<a name="node_pivot"></a>
- **node_pivot** (_unknown_)

View File

@ -0,0 +1,318 @@
# druid.text API
> at /druid/base/text.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_layout_change](#on_layout_change)
- [get_text_size](#get_text_size)
- [get_text_index_by_width](#get_text_index_by_width)
- [set_to](#set_to)
- [set_text](#set_text)
- [get_text](#get_text)
- [set_size](#set_size)
- [set_color](#set_color)
- [set_alpha](#set_alpha)
- [set_scale](#set_scale)
- [set_pivot](#set_pivot)
- [is_multiline](#is_multiline)
- [set_text_adjust](#set_text_adjust)
- [set_minimal_scale](#set_minimal_scale)
- [get_text_adjust](#get_text_adjust)
## Fields
- [node](#node)
- [on_set_text](#on_set_text)
- [on_update_text_scale](#on_update_text_scale)
- [on_set_pivot](#on_set_pivot)
- [style](#style)
- [pos](#pos)
- [node_id](#node_id)
- [start_size](#start_size)
- [text_area](#text_area)
- [adjust_type](#adjust_type)
- [color](#color)
- [last_value](#last_value)
- [last_scale](#last_scale)
### init
---
```lua
text:init(node, [value], [adjust_type])
```
The Text constructor
- **Parameters:**
- `node` *(string|node)*: Node name or GUI Text Node itself
- `[value]` *(string|nil)*: Initial text. Default value is node text from GUI scene. Default: nil
- `[adjust_type]` *(string|nil)*: Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
- **Returns:**
- `` *(druid.text)*:
### on_style_change
---
```lua
text:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.text.style)*:
### on_layout_change
---
```lua
text:on_layout_change()
```
### get_text_size
---
```lua
text:get_text_size([text])
```
Calculate text width with font with respect to trailing space
- **Parameters:**
- `[text]` *(string|nil)*:
- **Returns:**
- `Width` *(number)*:
- `Height` *(number)*:
### get_text_index_by_width
---
```lua
text:get_text_index_by_width(width)
```
Get chars count by width
- **Parameters:**
- `width` *(number)*:
- **Returns:**
- `Chars` *(number)*: count
### set_to
---
```lua
text:set_to(set_to)
```
Set text to text field
- **Parameters:**
- `set_to` *(string)*: Text for node
- **Returns:**
- `Current` *(druid.text)*: text instance
### set_text
---
```lua
text:set_text([new_text])
```
- **Parameters:**
- `[new_text]` *(any)*:
- **Returns:**
- `` *(druid.text)*:
### get_text
---
```lua
text:get_text()
```
- **Returns:**
- `` *(unknown)*:
### set_size
---
```lua
text:set_size(size)
```
Set text area size
- **Parameters:**
- `size` *(vector3)*: The new text area size
- **Returns:**
- `self` *(druid.text)*: Current text instance
### set_color
---
```lua
text:set_color(color)
```
Set color
- **Parameters:**
- `color` *(vector4)*: Color for node
- **Returns:**
- `Current` *(druid.text)*: text instance
### set_alpha
---
```lua
text:set_alpha(alpha)
```
Set alpha
- **Parameters:**
- `alpha` *(number)*: Alpha for node
- **Returns:**
- `Current` *(druid.text)*: text instance
### set_scale
---
```lua
text:set_scale(scale)
```
Set scale
- **Parameters:**
- `scale` *(vector3)*: Scale for node
- **Returns:**
- `Current` *(druid.text)*: text instance
### set_pivot
---
```lua
text:set_pivot(pivot)
```
Set text pivot. Text will re-anchor inside text area
- **Parameters:**
- `pivot` *(userdata)*: The gui.PIVOT_* constant
- **Returns:**
- `Current` *(druid.text)*: text instance
### is_multiline
---
```lua
text:is_multiline()
```
Return true, if text with line break
- **Returns:**
- `Is` *(boolean)*: text node with line break
### set_text_adjust
---
```lua
text:set_text_adjust([adjust_type], [minimal_scale])
```
Set text adjust, refresh the current text visuals, if needed
Values are: "downscale", "trim", "no_adjust", "downscale_limited",
"scroll", "scale_then_scroll", "trim_left", "scale_then_trim", "scale_then_trim_left"
- **Parameters:**
- `[adjust_type]` *(string|nil)*: See const.TEXT_ADJUST. If pass nil - use current adjust type
- `[minimal_scale]` *(number|nil)*: To remove minimal scale, use `text:set_minimal_scale(nil)`, if pass nil - not change minimal scale
- **Returns:**
- `self` *(druid.text)*: Current text instance
### set_minimal_scale
---
```lua
text:set_minimal_scale(minimal_scale)
```
Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
- **Parameters:**
- `minimal_scale` *(number)*: If pass nil - not use minimal scale
- **Returns:**
- `Current` *(druid.text)*: text instance
### get_text_adjust
---
```lua
text:get_text_adjust()
```
Return current text adjust type
- **Returns:**
- `adjust_type` *(string)*: The current text adjust type
## Fields
<a name="node"></a>
- **node** (_node_): The text node
<a name="on_set_text"></a>
- **on_set_text** (_event_): The event triggered when the text is set, fun(self, text)
<a name="on_update_text_scale"></a>
- **on_update_text_scale** (_event_): The event triggered when the text scale is updated, fun(self, scale, metrics)
<a name="on_set_pivot"></a>
- **on_set_pivot** (_event_): The event triggered when the text pivot is set, fun(self, pivot)
<a name="style"></a>
- **style** (_druid.text.style_): The style of the text
<a name="pos"></a>
- **pos** (_unknown_)
<a name="node_id"></a>
- **node_id** (_unknown_)
<a name="start_size"></a>
- **start_size** (_unknown_)
<a name="text_area"></a>
- **text_area** (_unknown_)
<a name="adjust_type"></a>
- **adjust_type** (_string|nil_)
<a name="color"></a>
- **color** (_unknown_)
<a name="last_value"></a>
- **last_value** (_unknown_)
<a name="last_scale"></a>
- **last_scale** (_vector3_)

View File

@ -0,0 +1,178 @@
# druid.rich_input API
> at /druid/custom/rich_input/rich_input.lua
## Functions
- [init](#init)
- [on_input](#on_input)
- [set_placeholder](#set_placeholder)
- [select](#select)
- [set_text](#set_text)
- [set_font](#set_font)
- [get_text](#get_text)
- [set_allowed_characters](#set_allowed_characters)
## Fields
- [root](#root)
- [input](#input)
- [cursor](#cursor)
- [cursor_text](#cursor_text)
- [cursor_position](#cursor_position)
- [druid](#druid)
- [is_lshift](#is_lshift)
- [is_lctrl](#is_lctrl)
- [is_button_input_enabled](#is_button_input_enabled)
- [drag](#drag)
- [placeholder](#placeholder)
- [text_position](#text_position)
### init
---
```lua
rich_input:init(template, nodes)
```
- **Parameters:**
- `template` *(string)*: The template string name
- `nodes` *(table)*: Nodes table from gui.clone_tree
### on_input
---
```lua
rich_input:on_input([action_id], [action])
```
- **Parameters:**
- `[action_id]` *(any)*:
- `[action]` *(any)*:
- **Returns:**
- `` *(boolean)*:
### set_placeholder
---
```lua
rich_input:set_placeholder(placeholder_text)
```
Set placeholder text
- **Parameters:**
- `placeholder_text` *(string)*: The placeholder text
- **Returns:**
- `` *(druid.rich_input)*:
### select
---
```lua
rich_input:select()
```
Select input field
### set_text
---
```lua
rich_input:set_text(text)
```
Set input field text
- **Parameters:**
- `text` *(string)*: The input text
- **Returns:**
- `self` *(druid.rich_input)*: Current instance
### set_font
---
```lua
rich_input:set_font(font)
```
Set input field font
- **Parameters:**
- `font` *(hash)*: The font hash
- **Returns:**
- `self` *(druid.rich_input)*: Current instance
### get_text
---
```lua
rich_input:get_text()
```
Set input field text
- **Returns:**
- `` *(string)*:
### set_allowed_characters
---
```lua
rich_input:set_allowed_characters(characters)
```
Set allowed charaters for input field.
See: https://defold.com/ref/stable/string/
ex: [%a%d] for alpha and numeric
- **Parameters:**
- `characters` *(string)*: Regulax exp. for validate user input
- **Returns:**
- `Current` *(druid.rich_input)*: instance
## Fields
<a name="root"></a>
- **root** (_node_)
<a name="input"></a>
- **input** (_druid.input_)
<a name="cursor"></a>
- **cursor** (_node_)
<a name="cursor_text"></a>
- **cursor_text** (_node_)
<a name="cursor_position"></a>
- **cursor_position** (_vector3_)
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="is_lshift"></a>
- **is_lshift** (_boolean_)
<a name="is_lctrl"></a>
- **is_lctrl** (_boolean_)
<a name="is_button_input_enabled"></a>
- **is_button_input_enabled** (_unknown_)
<a name="drag"></a>
- **drag** (_druid.drag_)
<a name="placeholder"></a>
- **placeholder** (_druid.text_)
<a name="text_position"></a>
- **text_position** (_unknown_)

View File

@ -0,0 +1,187 @@
# druid.rich_text API
> at /druid/custom/rich_text/rich_text.lua
## Functions
- [init](#init)
- [on_layout_change](#on_layout_change)
- [on_style_change](#on_style_change)
- [set_text](#set_text)
- [get_text](#get_text)
- [on_remove](#on_remove)
- [clear](#clear)
- [tagged](#tagged)
- [characters](#characters)
- [get_words](#get_words)
- [get_line_metric](#get_line_metric)
## Fields
- [root](#root)
- [text_prefab](#text_prefab)
- [style](#style)
### init
---
```lua
rich_text:init(text_node, [value])
```
- **Parameters:**
- `text_node` *(string|node)*: The text node to make Rich Text
- `[value]` *(string|nil)*: The initial text value. Default will be gui.get_text(text_node)
### on_layout_change
---
```lua
rich_text:on_layout_change()
```
### on_style_change
---
```lua
rich_text:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.rich_text.style)*:
### set_text
---
```lua
rich_text:set_text([text])
```
Set text for Rich Text
- **Parameters:**
- `[text]` *(string|nil)*: The text to set
- **Returns:**
- `words` *(druid.rich_text.word[])*:
- `line_metrics` *(druid.rich_text.lines_metrics)*:
- **Example Usage:**
```lua
rich_text:set_text("color=redFoobar/color")
rich_text:set_text("color=1.0,0,0,1.0Foobar/color")
rich_text:set_text("color=#ff0000Foobar/color")
rich_text:set_text("color=#ff0000ffFoobar/color")
rich_text:set_text("shadow=redFoobar/shadow")
rich_text:set_text("shadow=1.0,0,0,1.0Foobar/shadow")
rich_text:set_text("shadow=#ff0000Foobar/shadow")
rich_text:set_text("shadow=#ff0000ffFoobar/shadow")
rich_text:set_text("outline=redFoobar/outline")
rich_text:set_text("outline=1.0,0,0,1.0Foobar/outline")
rich_text:set_text("outline=#ff0000Foobar/outline")
rich_text:set_text("outline=#ff0000ffFoobar/outline")
rich_text:set_text("font=MyCoolFontFoobar/font")
rich_text:set_text("size=2Twice as large/size")
rich_text:set_text("br/Insert a line break")
rich_text:set_text("nobrPrevent the text from breaking")
rich_text:set_text("img=texture:imageDisplay image")
rich_text:set_text("img=texture:image,sizeDisplay image with size")
rich_text:set_text("img=texture:image,width,heightDisplay image with width and height")
```
### get_text
---
```lua
rich_text:get_text()
```
Get current text
- **Returns:**
- `text` *(string)*:
### on_remove
---
```lua
rich_text:on_remove()
```
### clear
---
```lua
rich_text:clear()
```
Clear all created words.
### tagged
---
```lua
rich_text:tagged(tag)
```
Get all words, which has a passed tag.
- **Parameters:**
- `tag` *(string)*:
- **Returns:**
- `words` *(druid.rich_text.word[])*:
### characters
---
```lua
rich_text:characters(word)
```
Split a word into it's characters
- **Parameters:**
- `word` *(druid.rich_text.word)*:
- **Returns:**
- `characters` *(druid.rich_text.word[])*:
### get_words
---
```lua
rich_text:get_words()
```
Get all current words.
- **Returns:**
- `` *(druid.rich_text.word[])*:
### get_line_metric
---
```lua
rich_text:get_line_metric()
```
Get current line metrics
-@return druid.rich_text.lines_metrics
- **Returns:**
- `` *(druid.rich_text.lines_metrics)*:
## Fields
<a name="root"></a>
- **root** (_node_)
<a name="text_prefab"></a>
- **text_prefab** (_node_)
<a name="style"></a>
- **style** (_table_)

View File

@ -0,0 +1,382 @@
# druid.container API
> at /druid/extended/container.lua
## Functions
- [init](#init)
- [on_late_init](#on_late_init)
- [on_remove](#on_remove)
- [refresh_origins](#refresh_origins)
- [set_pivot](#set_pivot)
- [on_style_change](#on_style_change)
- [set_size](#set_size)
- [get_position](#get_position)
- [set_position](#set_position)
- [get_size](#get_size)
- [get_scale](#get_scale)
- [fit_into_size](#fit_into_size)
- [fit_into_window](#fit_into_window)
- [on_window_resized](#on_window_resized)
- [add_container](#add_container)
- [remove_container_by_node](#remove_container_by_node)
- [set_parent_container](#set_parent_container)
- [refresh](#refresh)
- [refresh_scale](#refresh_scale)
- [update_child_containers](#update_child_containers)
- [create_draggable_corners](#create_draggable_corners)
- [clear_draggable_corners](#clear_draggable_corners)
- [fit_into_node](#fit_into_node)
- [set_min_size](#set_min_size)
## Fields
- [node](#node)
- [druid](#druid)
- [node_offset](#node_offset)
- [origin_size](#origin_size)
- [size](#size)
- [origin_position](#origin_position)
- [position](#position)
- [pivot_offset](#pivot_offset)
- [center_offset](#center_offset)
- [mode](#mode)
- [fit_size](#fit_size)
- [min_size_x](#min_size_x)
- [min_size_y](#min_size_y)
- [on_size_changed](#on_size_changed)
- [node_fill_x](#node_fill_x)
- [node_fill_y](#node_fill_y)
- [x_koef](#x_koef)
- [y_koef](#y_koef)
- [x_anchor](#x_anchor)
- [y_anchor](#y_anchor)
- [style](#style)
### init
---
```lua
container:init(node, mode, [callback])
```
- **Parameters:**
- `node` *(node)*: Gui node
- `mode` *(string)*: Layout mode
- `[callback]` *(fun(self: druid.container, size: vector3)|nil)*: Callback on size changed
### on_late_init
---
```lua
container:on_late_init()
```
### on_remove
---
```lua
container:on_remove()
```
### refresh_origins
---
```lua
container:refresh_origins()
```
### set_pivot
---
```lua
container:set_pivot(pivot)
```
- **Parameters:**
- `pivot` *(constant)*:
### on_style_change
---
```lua
container:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.container.style)*:
### set_size
---
```lua
container:set_size([width], [height], [anchor_pivot])
```
Set new size of layout node
- **Parameters:**
- `[width]` *(number|nil)*:
- `[height]` *(number|nil)*:
- `[anchor_pivot]` *(constant|nil)*: If set will keep the corner possition relative to the new size
- **Returns:**
- `Container` *(druid.container)*:
### get_position
---
```lua
container:get_position()
```
- **Returns:**
- `` *(unknown)*:
### set_position
---
```lua
container:set_position(pos_x, pos_y)
```
- **Parameters:**
- `pos_x` *(number)*:
- `pos_y` *(number)*:
### get_size
---
```lua
container:get_size()
```
Get current size of layout node
- **Returns:**
- `size` *(vector3)*:
### get_scale
---
```lua
container:get_scale()
```
Get current scale of layout node
- **Returns:**
- `scale` *(vector3)*:
### fit_into_size
---
```lua
container:fit_into_size(target_size)
```
Set size for layout node to fit inside it
- **Parameters:**
- `target_size` *(vector3)*:
- **Returns:**
- `Container` *(druid.container)*:
### fit_into_window
---
```lua
container:fit_into_window()
```
Set current size for layout node to fit inside it
- **Returns:**
- `Container` *(druid.container)*:
### on_window_resized
---
```lua
container:on_window_resized()
```
### add_container
---
```lua
container:add_container(node_or_container, [mode], [on_resize_callback])
```
- **Parameters:**
- `node_or_container` *(string|table|druid.container|node)*:
- `[mode]` *(string|nil)*: stretch, fit, stretch_x, stretch_y. Default: Pick from node, "fit" or "stretch"
- `[on_resize_callback]` *(fun(self: userdata, size: vector3)|nil)*:
- **Returns:**
- `Container` *(druid.container)*: New created layout instance
### remove_container_by_node
---
```lua
container:remove_container_by_node([node])
```
- **Parameters:**
- `[node]` *(any)*:
- **Returns:**
- `` *(druid.container|nil)*:
### set_parent_container
---
```lua
container:set_parent_container([parent_container])
```
- **Parameters:**
- `[parent_container]` *(druid.container|nil)*:
### refresh
---
```lua
container:refresh()
```
Glossary
Center Offset - vector from node position to visual center of node
### refresh_scale
---
```lua
container:refresh_scale()
```
### update_child_containers
---
```lua
container:update_child_containers()
```
### create_draggable_corners
---
```lua
container:create_draggable_corners()
```
- **Returns:**
- `Container` *(druid.container)*:
### clear_draggable_corners
---
```lua
container:clear_draggable_corners()
```
- **Returns:**
- `Container` *(druid.container)*:
### fit_into_node
---
```lua
container:fit_into_node(node)
```
Set node for layout node to fit inside it. Pass nil to reset
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- **Returns:**
- `Layout` *(druid.container)*:
### set_min_size
---
```lua
container:set_min_size([min_size_x], [min_size_y])
```
- **Parameters:**
- `[min_size_x]` *(number|nil)*:
- `[min_size_y]` *(number|nil)*:
- **Returns:**
- `` *(druid.container)*:
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="node_offset"></a>
- **node_offset** (_vector4_)
<a name="origin_size"></a>
- **origin_size** (_vector3_)
<a name="size"></a>
- **size** (_vector3_)
<a name="origin_position"></a>
- **origin_position** (_vector3_)
<a name="position"></a>
- **position** (_vector3_)
<a name="pivot_offset"></a>
- **pivot_offset** (_vector3_)
<a name="center_offset"></a>
- **center_offset** (_vector3_)
<a name="mode"></a>
- **mode** (_string_)
<a name="fit_size"></a>
- **fit_size** (_vector3_)
<a name="min_size_x"></a>
- **min_size_x** (_number_)
<a name="min_size_y"></a>
- **min_size_y** (_number_)
<a name="on_size_changed"></a>
- **on_size_changed** (_event_): fun(self: druid.container, size: vector3)
<a name="node_fill_x"></a>
- **node_fill_x** (_nil_)
<a name="node_fill_y"></a>
- **node_fill_y** (_nil_)
<a name="x_koef"></a>
- **x_koef** (_number_)
<a name="y_koef"></a>
- **y_koef** (_number_)
<a name="x_anchor"></a>
- **x_anchor** (_unknown_)
<a name="y_anchor"></a>
- **y_anchor** (_unknown_)
<a name="style"></a>
- **style** (_table_)

View File

@ -0,0 +1,222 @@
# druid.data_list API
> at /druid/extended/data_list.lua
## Functions
- [init](#init)
- [on_remove](#on_remove)
- [set_use_cache](#set_use_cache)
- [set_data](#set_data)
- [get_data](#get_data)
- [add](#add)
- [remove](#remove)
- [remove_by_data](#remove_by_data)
- [clear](#clear)
- [get_index](#get_index)
- [get_created_nodes](#get_created_nodes)
- [get_created_components](#get_created_components)
- [scroll_to_index](#scroll_to_index)
## Fields
- [scroll](#scroll)
- [grid](#grid)
- [on_scroll_progress_change](#on_scroll_progress_change)
- [on_element_add](#on_element_add)
- [on_element_remove](#on_element_remove)
- [top_index](#top_index)
- [last_index](#last_index)
- [scroll_progress](#scroll_progress)
### init
---
```lua
data_list:init(scroll, grid, create_function)
```
- **Parameters:**
- `scroll` *(druid.scroll)*: The Scroll instance for Data List component
- `grid` *(druid.grid)*: The StaticGrid} or @{DynamicGrid instance for Data List component
- `create_function` *(function)*: The create function callback(self, data, index, data_list). Function should return (node, [component])
### on_remove
---
```lua
data_list:on_remove()
```
Druid System on_remove function
### set_use_cache
---
```lua
data_list:set_use_cache(is_use_cache)
```
Set refresh function for DataList component
- **Parameters:**
- `is_use_cache` *(boolean)*: Use cache version of DataList. Requires make setup of components in on_element_add callback and clean in on_element_remove
- **Returns:**
- `Current` *(druid.data_list)*: DataList instance
### set_data
---
```lua
data_list:set_data(data)
```
Set new data set for DataList component
- **Parameters:**
- `data` *(table)*: The new data array
- **Returns:**
- `Current` *(druid.data_list)*: DataList instance
### get_data
---
```lua
data_list:get_data()
```
Return current data from DataList component
- **Returns:**
- `The` *(table)*: current data array
### add
---
```lua
data_list:add(data, [index], [shift_policy])
```
Add element to DataList. Currenly untested
- **Parameters:**
- `data` *(table)*:
- `[index]` *(number|nil)*:
- `[shift_policy]` *(number|nil)*: The constant from const.SHIFT.*
### remove
---
```lua
data_list:remove([index], [shift_policy])
```
Remove element from DataList. Currenly untested
- **Parameters:**
- `[index]` *(number|nil)*:
- `[shift_policy]` *(number|nil)*: The constant from const.SHIFT.*
### remove_by_data
---
```lua
data_list:remove_by_data(data, [shift_policy])
```
Remove element from DataList by data value. Currenly untested
- **Parameters:**
- `data` *(table)*:
- `[shift_policy]` *(number|nil)*: The constant from const.SHIFT.*
### clear
---
```lua
data_list:clear()
```
Clear the DataList and refresh visuals
### get_index
---
```lua
data_list:get_index(data)
```
Return index for data value
- **Parameters:**
- `data` *(table)*:
- **Returns:**
- `` *(unknown|nil)*:
### get_created_nodes
---
```lua
data_list:get_created_nodes()
```
Return all currenly created nodes in DataList
- **Returns:**
- `List` *(node[])*: of created nodes
### get_created_components
---
```lua
data_list:get_created_components()
```
Return all currenly created components in DataList
- **Returns:**
- `List` *(druid.component[])*: of created nodes
### scroll_to_index
---
```lua
data_list:scroll_to_index(index)
```
Instant scroll to element with passed index
- **Parameters:**
- `index` *(number)*:
## Fields
<a name="scroll"></a>
- **scroll** (_druid.scroll_)
<a name="grid"></a>
- **grid** (_druid.grid_)
<a name="on_scroll_progress_change"></a>
- **on_scroll_progress_change** (_event_)
<a name="on_element_add"></a>
- **on_element_add** (_event_)
<a name="on_element_remove"></a>
- **on_element_remove** (_event_)
<a name="top_index"></a>
- **top_index** (_number_)
<a name="last_index"></a>
- **last_index** (_number_)
<a name="scroll_progress"></a>
- **scroll_progress** (_number_)

View File

@ -0,0 +1,123 @@
# druid.hotkey API
> at /druid/extended/hotkey.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [add_hotkey](#add_hotkey)
- [is_processing](#is_processing)
- [on_focus_gained](#on_focus_gained)
- [on_input](#on_input)
- [set_repeat](#set_repeat)
## Fields
- [on_hotkey_pressed](#on_hotkey_pressed)
- [on_hotkey_released](#on_hotkey_released)
- [style](#style)
- [druid](#druid)
### init
---
```lua
hotkey:init(keys, callback, [callback_argument])
```
The Hotkey constructor
- **Parameters:**
- `keys` *(string|string[])*: The keys to be pressed for trigger callback. Should contains one key and any modificator keys
- `callback` *(function)*: The callback function
- `[callback_argument]` *(any)*: The argument to pass into the callback function
### on_style_change
---
```lua
hotkey:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.hotkey.style)*:
### add_hotkey
---
```lua
hotkey:add_hotkey(keys, [callback_argument])
```
Add hotkey for component callback
- **Parameters:**
- `keys` *(string|hash|hash[]|string[])*: that have to be pressed before key pressed to activate
- `[callback_argument]` *(any)*: The argument to pass into the callback function
- **Returns:**
- `Current` *(druid.hotkey)*: instance
### is_processing
---
```lua
hotkey:is_processing()
```
- **Returns:**
- `` *(boolean)*:
### on_focus_gained
---
```lua
hotkey:on_focus_gained()
```
### on_input
---
```lua
hotkey:on_input([action_id], action)
```
- **Parameters:**
- `[action_id]` *(hash|nil)*:
- `action` *(action)*:
- **Returns:**
- `` *(boolean)*:
### set_repeat
---
```lua
hotkey:set_repeat(is_enabled_repeated)
```
If true, the callback will be triggered on action.repeated
- **Parameters:**
- `is_enabled_repeated` *(bool)*: The flag value
- **Returns:**
- `` *(druid.hotkey)*:
## Fields
<a name="on_hotkey_pressed"></a>
- **on_hotkey_pressed** (_event_)
<a name="on_hotkey_released"></a>
- **on_hotkey_released** (_event_)
<a name="style"></a>
- **style** (_druid.hotkey.style_)
<a name="druid"></a>
- **druid** (_druid.instance_)

View File

@ -0,0 +1,335 @@
# druid.input API
> at /druid/extended/input.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_input](#on_input)
- [on_focus_lost](#on_focus_lost)
- [on_input_interrupt](#on_input_interrupt)
- [get_text_selected](#get_text_selected)
- [get_text_selected_replaced](#get_text_selected_replaced)
- [set_text](#set_text)
- [select](#select)
- [unselect](#unselect)
- [get_text](#get_text)
- [set_max_length](#set_max_length)
- [set_allowed_characters](#set_allowed_characters)
- [reset_changes](#reset_changes)
- [select_cursor](#select_cursor)
- [move_selection](#move_selection)
## Fields
- [on_input_select](#on_input_select)
- [on_input_unselect](#on_input_unselect)
- [on_input_text](#on_input_text)
- [on_input_empty](#on_input_empty)
- [on_input_full](#on_input_full)
- [on_input_wrong](#on_input_wrong)
- [on_select_cursor_change](#on_select_cursor_change)
- [style](#style)
- [text](#text)
- [ALLOWED_ACTIONS](#ALLOWED_ACTIONS)
- [druid](#druid)
- [is_selected](#is_selected)
- [value](#value)
- [previous_value](#previous_value)
- [current_value](#current_value)
- [marked_value](#marked_value)
- [is_empty](#is_empty)
- [text_width](#text_width)
- [market_text_width](#market_text_width)
- [total_width](#total_width)
- [cursor_index](#cursor_index)
- [start_index](#start_index)
- [end_index](#end_index)
- [max_length](#max_length)
- [allowed_characters](#allowed_characters)
- [keyboard_type](#keyboard_type)
- [button](#button)
- [marked_text_width](#marked_text_width)
### init
---
```lua
input:init(click_node, text_node, [keyboard_type])
```
- **Parameters:**
- `click_node` *(node)*: Node to enabled input component
- `text_node` *(druid.text|node)*: Text node what will be changed on user input. You can pass text component instead of text node name Text
- `[keyboard_type]` *(number|nil)*: Gui keyboard type for input field
### on_style_change
---
```lua
input:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.input.style)*:
### on_input
---
```lua
input:on_input([action_id], [action])
```
- **Parameters:**
- `[action_id]` *(any)*:
- `[action]` *(any)*:
- **Returns:**
- `` *(boolean)*:
### on_focus_lost
---
```lua
input:on_focus_lost()
```
### on_input_interrupt
---
```lua
input:on_input_interrupt()
```
### get_text_selected
---
```lua
input:get_text_selected()
```
- **Returns:**
- `` *(string|unknown)*:
### get_text_selected_replaced
---
```lua
input:get_text_selected_replaced(text)
```
Replace selected text with new text
- **Parameters:**
- `text` *(string)*: The text to replace selected text
- **Returns:**
- `New` *(string)*: input text
### set_text
---
```lua
input:set_text(input_text)
```
Set text for input field
- **Parameters:**
- `input_text` *(string)*: The string to apply for input field
### select
---
```lua
input:select()
```
Select input field. It will show the keyboard and trigger on_select events
### unselect
---
```lua
input:unselect()
```
Remove selection from input. It will hide the keyboard and trigger on_unselect events
### get_text
---
```lua
input:get_text()
```
Return current input field text
- **Returns:**
- `The` *(string)*: current input field text
### set_max_length
---
```lua
input:set_max_length(max_length)
```
Set maximum length for input field.
Pass nil to make input field unliminted (by default)
- **Parameters:**
- `max_length` *(number)*: Maximum length for input text field
- **Returns:**
- `Current` *(druid.input)*: input instance
### set_allowed_characters
---
```lua
input:set_allowed_characters(characters)
```
Set allowed charaters for input field.
See: https://defold.com/ref/stable/string/
ex: [%a%d] for alpha and numeric
- **Parameters:**
- `characters` *(string)*: Regulax exp. for validate user input
- **Returns:**
- `Current` *(druid.input)*: input instance
### reset_changes
---
```lua
input:reset_changes()
```
Reset current input selection and return previous value
- **Returns:**
- `Current` *(druid.input)*: input instance
### select_cursor
---
```lua
input:select_cursor([cursor_index], [start_index], [end_index])
```
Set cursor position in input field
- **Parameters:**
- `[cursor_index]` *(number|nil)*: Cursor index for cursor position, if nil - will be set to the end of the text
- `[start_index]` *(number|nil)*: Start index for cursor position, if nil - will be set to the end of the text
- `[end_index]` *(number|nil)*: End index for cursor position, if nil - will be set to the start_index
- **Returns:**
- `Current` *(druid.input)*: input instance
### move_selection
---
```lua
input:move_selection(delta, is_add_to_selection, is_move_to_end)
```
Change cursor position by delta
- **Parameters:**
- `delta` *(number)*: side for cursor position, -1 for left, 1 for right
- `is_add_to_selection` *(boolean)*: (Shift key)
- `is_move_to_end` *(boolean)*: (Ctrl key)
## Fields
<a name="on_input_select"></a>
- **on_input_select** (_event_)
<a name="on_input_unselect"></a>
- **on_input_unselect** (_event_)
<a name="on_input_text"></a>
- **on_input_text** (_event_)
<a name="on_input_empty"></a>
- **on_input_empty** (_event_)
<a name="on_input_full"></a>
- **on_input_full** (_event_)
<a name="on_input_wrong"></a>
- **on_input_wrong** (_event_)
<a name="on_select_cursor_change"></a>
- **on_select_cursor_change** (_event_)
<a name="style"></a>
- **style** (_table_)
<a name="text"></a>
- **text** (_druid.text_)
<a name="ALLOWED_ACTIONS"></a>
- **ALLOWED_ACTIONS** (_table_)
<a name="druid"></a>
- **druid** (_druid.instance_)
<a name="is_selected"></a>
- **is_selected** (_boolean_)
<a name="value"></a>
- **value** (_unknown_)
<a name="previous_value"></a>
- **previous_value** (_unknown_)
<a name="current_value"></a>
- **current_value** (_unknown_)
<a name="marked_value"></a>
- **marked_value** (_string_)
<a name="is_empty"></a>
- **is_empty** (_boolean_)
<a name="text_width"></a>
- **text_width** (_integer_)
<a name="market_text_width"></a>
- **market_text_width** (_integer_)
<a name="total_width"></a>
- **total_width** (_integer_)
<a name="cursor_index"></a>
- **cursor_index** (_integer_)
<a name="start_index"></a>
- **start_index** (_number_)
<a name="end_index"></a>
- **end_index** (_number_)
<a name="max_length"></a>
- **max_length** (_nil_)
<a name="allowed_characters"></a>
- **allowed_characters** (_nil_)
<a name="keyboard_type"></a>
- **keyboard_type** (_number_)
<a name="button"></a>
- **button** (_druid.button_): Druid component to make clickable node with various interaction callbacks
<a name="marked_text_width"></a>
- **marked_text_width** (_number_)

View File

@ -0,0 +1,119 @@
# druid.lang_text API
> at /druid/extended/lang_text.lua
## Functions
- [init](#init)
- [on_language_change](#on_language_change)
- [set_to](#set_to)
- [set_text](#set_text)
- [translate](#translate)
- [format](#format)
## Fields
- [text](#text)
- [node](#node)
- [on_change](#on_change)
- [druid](#druid)
### init
---
```lua
lang_text:init(node, [locale_id], [adjust_type])
```
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- `[locale_id]` *(string|nil)*: Default locale id or text from node as default
- `[adjust_type]` *(string|nil)*: Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
- **Returns:**
- `` *(druid.lang_text)*:
### on_language_change
---
```lua
lang_text:on_language_change()
```
### set_to
---
```lua
lang_text:set_to(text)
```
Setup raw text to lang_text component
- **Parameters:**
- `text` *(string)*: Text for text node
- **Returns:**
- `Current` *(druid.lang_text)*: instance
### set_text
---
```lua
lang_text:set_text(text)
```
Setup raw text to lang_text component
- **Parameters:**
- `text` *(string)*: Text for text node
- **Returns:**
- `Current` *(druid.lang_text)*: instance
### translate
---
```lua
lang_text:translate(locale_id, ...)
```
Translate the text by locale_id
- **Parameters:**
- `locale_id` *(string)*: Locale id
- `...` *(...)*: vararg
- **Returns:**
- `Current` *(druid.lang_text)*: instance
### format
---
```lua
lang_text:format(...)
```
Format string with new text params on localized text
- **Parameters:**
- `...` *(...)*: vararg
- **Returns:**
- `Current` *(druid.lang_text)*: instance
## Fields
<a name="text"></a>
- **text** (_druid.text_)
<a name="node"></a>
- **node** (_node_)
<a name="on_change"></a>
- **on_change** (_event_)
<a name="druid"></a>
- **druid** (_druid.instance_)

View File

@ -0,0 +1,319 @@
# druid.layout API
> at /druid/extended/layout.lua
## Functions
- [init](#init)
- [update](#update)
- [get_entities](#get_entities)
- [set_node_index](#set_node_index)
- [set_margin](#set_margin)
- [set_padding](#set_padding)
- [set_dirty](#set_dirty)
- [set_justify](#set_justify)
- [set_type](#set_type)
- [set_hug_content](#set_hug_content)
- [add](#add)
- [remove](#remove)
- [get_size](#get_size)
- [get_content_size](#get_content_size)
- [refresh_layout](#refresh_layout)
- [clear_layout](#clear_layout)
- [get_node_size](#get_node_size)
- [calculate_rows_data](#calculate_rows_data)
- [set_node_position](#set_node_position)
## Fields
- [node](#node)
- [rows_data](#rows_data)
- [is_dirty](#is_dirty)
- [entities](#entities)
- [margin](#margin)
- [padding](#padding)
- [type](#type)
- [is_resize_width](#is_resize_width)
- [is_resize_height](#is_resize_height)
- [is_justify](#is_justify)
- [on_size_changed](#on_size_changed)
- [size](#size)
### init
---
```lua
layout:init(node_or_node_id, layout_type)
```
```lua
layout_type:
| "horizontal"
| "vertical"
| "horizontal_wrap"
```
- **Parameters:**
- `node_or_node_id` *(string|node)*:
- `layout_type` *(druid.layout.mode)*:
### update
---
```lua
layout:update()
```
### get_entities
---
```lua
layout:get_entities()
```
- **Returns:**
- `` *(node[])*:
### set_node_index
---
```lua
layout:set_node_index([node], [index])
```
- **Parameters:**
- `[node]` *(any)*:
- `[index]` *(any)*:
### set_margin
---
```lua
layout:set_margin([margin_x], [margin_y])
```
- **Parameters:**
- `[margin_x]` *(number|nil)*:
- `[margin_y]` *(number|nil)*:
- **Returns:**
- `` *(druid.layout)*:
### set_padding
---
```lua
layout:set_padding([padding_x], [padding_y], [padding_z], [padding_w])
```
- **Parameters:**
- `[padding_x]` *(number|nil)*:
- `[padding_y]` *(number|nil)*:
- `[padding_z]` *(number|nil)*:
- `[padding_w]` *(number|nil)*:
- **Returns:**
- `` *(druid.layout)*:
### set_dirty
---
```lua
layout:set_dirty()
```
- **Returns:**
- `` *(druid.layout)*:
### set_justify
---
```lua
layout:set_justify(is_justify)
```
- **Parameters:**
- `is_justify` *(boolean)*:
- **Returns:**
- `` *(druid.layout)*:
### set_type
---
```lua
layout:set_type(type)
```
- **Parameters:**
- `type` *(string)*: The layout type: "horizontal", "vertical", "horizontal_wrap"
- **Returns:**
- `` *(druid.layout)*:
### set_hug_content
---
```lua
layout:set_hug_content(is_hug_width, is_hug_height)
```
- **Parameters:**
- `is_hug_width` *(boolean)*:
- `is_hug_height` *(boolean)*:
- **Returns:**
- `` *(druid.layout)*:
### add
---
```lua
layout:add(node_or_node_id)
```
Add node to layout
- **Parameters:**
- `node_or_node_id` *(string|node)*: node_or_node_id
- **Returns:**
- `` *(druid.layout)*:
### remove
---
```lua
layout:remove(node_or_node_id)
```
Remove node from layout
- **Parameters:**
- `node_or_node_id` *(string|node)*: node_or_node_id
- **Returns:**
- `self` *(druid.layout)*: for chaining
### get_size
---
```lua
layout:get_size()
```
- **Returns:**
- `` *(vector3)*:
### get_content_size
---
```lua
layout:get_content_size()
```
- **Returns:**
- `` *(number)*:
- `` *(number)*:
### refresh_layout
---
```lua
layout:refresh_layout()
```
- **Returns:**
- `` *(druid.layout)*:
### clear_layout
---
```lua
layout:clear_layout()
```
- **Returns:**
- `` *(druid.layout)*:
### get_node_size
---
```lua
layout:get_node_size(node)
```
- **Parameters:**
- `node` *(node)*:
- **Returns:**
- `` *(number)*:
- `` *(number)*:
### calculate_rows_data
---
```lua
layout:calculate_rows_data()
```
Calculate rows data for layout. Contains total width, height and rows info (width, height, count of elements in row)
- **Returns:**
- `` *(druid.layout.rows_data)*:
### set_node_position
---
```lua
layout:set_node_position(node, x, y)
```
- **Parameters:**
- `node` *(node)*:
- `x` *(number)*:
- `y` *(number)*:
- **Returns:**
- `` *(node)*:
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="rows_data"></a>
- **rows_data** (_druid.layout.rows_data_): Last calculated rows data
<a name="is_dirty"></a>
- **is_dirty** (_boolean_)
<a name="entities"></a>
- **entities** (_node[]_)
<a name="margin"></a>
- **margin** (_{ x: number, y: number }_)
<a name="padding"></a>
- **padding** (_vector4_)
<a name="type"></a>
- **type** (_string_)
<a name="is_resize_width"></a>
- **is_resize_width** (_boolean_)
<a name="is_resize_height"></a>
- **is_resize_height** (_boolean_)
<a name="is_justify"></a>
- **is_justify** (_boolean_)
<a name="on_size_changed"></a>
- **on_size_changed** (_event.on_size_changed_)
<a name="size"></a>
- **size** (_unknown_)

View File

@ -0,0 +1,215 @@
# druid.progress API
> at /druid/extended/progress.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_layout_change](#on_layout_change)
- [on_remove](#on_remove)
- [update](#update)
- [fill](#fill)
- [empty](#empty)
- [set_to](#set_to)
- [get](#get)
- [set_steps](#set_steps)
- [to](#to)
- [set_max_size](#set_max_size)
## Fields
- [node](#node)
- [on_change](#on_change)
- [style](#style)
- [key](#key)
- [prop](#prop)
- [scale](#scale)
- [size](#size)
- [max_size](#max_size)
- [slice](#slice)
- [last_value](#last_value)
- [slice_size](#slice_size)
- [target](#target)
- [steps](#steps)
- [step_callback](#step_callback)
- [target_callback](#target_callback)
### init
---
```lua
progress:init(node, key, [init_value])
```
- **Parameters:**
- `node` *(string|node)*: Node name or GUI Node itself.
- `key` *(string)*: Progress bar direction: const.SIDE.X or const.SIDE.Y
- `[init_value]` *(number|nil)*: Initial value of progress bar. Default: 1
### on_style_change
---
```lua
progress:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.progress.style)*:
### on_layout_change
---
```lua
progress:on_layout_change()
```
### on_remove
---
```lua
progress:on_remove()
```
### update
---
```lua
progress:update(dt)
```
- **Parameters:**
- `dt` *(number)*: Delta time
### fill
---
```lua
progress:fill()
```
Fill a progress bar and stop progress animation
### empty
---
```lua
progress:empty()
```
Empty a progress bar
### set_to
---
```lua
progress:set_to(to)
```
Instant fill progress bar to value
- **Parameters:**
- `to` *(number)*: Progress bar value, from 0 to 1
### get
---
```lua
progress:get()
```
Return current progress bar value
- **Returns:**
- `` *(number)*:
### set_steps
---
```lua
progress:set_steps(steps, callback)
```
Set points on progress bar to fire the callback
- **Parameters:**
- `steps` *(number[])*: Array of progress bar values
- `callback` *(function)*: Callback on intersect step value
### to
---
```lua
progress:to(to, [callback])
```
Start animation of a progress bar
- **Parameters:**
- `to` *(number)*: value between 0..1
- `[callback]` *(function|nil)*: Callback on animation ends
### set_max_size
---
```lua
progress:set_max_size(max_size)
```
Set progress bar max node size
- **Parameters:**
- `max_size` *(vector3)*: The new node maximum (full) size
- **Returns:**
- `Progress` *(druid.progress)*:
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="on_change"></a>
- **on_change** (_event_)
<a name="style"></a>
- **style** (_druid.progress.style_)
<a name="key"></a>
- **key** (_string_)
<a name="prop"></a>
- **prop** (_hash_)
<a name="scale"></a>
- **scale** (_unknown_)
<a name="size"></a>
- **size** (_unknown_)
<a name="max_size"></a>
- **max_size** (_unknown_)
<a name="slice"></a>
- **slice** (_unknown_)
<a name="last_value"></a>
- **last_value** (_number_)
<a name="slice_size"></a>
- **slice_size** (_unknown_)
<a name="target"></a>
- **target** (_nil_)
<a name="steps"></a>
- **steps** (_number[]_)
<a name="step_callback"></a>
- **step_callback** (_function_)
<a name="target_callback"></a>
- **target_callback** (_function|nil_)

View File

@ -0,0 +1,215 @@
# druid.progress API
> at /druid/extended/progress.lua
## Functions
- [init](#init)
- [on_style_change](#on_style_change)
- [on_layout_change](#on_layout_change)
- [on_remove](#on_remove)
- [update](#update)
- [fill](#fill)
- [empty](#empty)
- [set_to](#set_to)
- [get](#get)
- [set_steps](#set_steps)
- [to](#to)
- [set_max_size](#set_max_size)
## Fields
- [node](#node)
- [on_change](#on_change)
- [style](#style)
- [key](#key)
- [prop](#prop)
- [scale](#scale)
- [size](#size)
- [max_size](#max_size)
- [slice](#slice)
- [last_value](#last_value)
- [slice_size](#slice_size)
- [target](#target)
- [steps](#steps)
- [step_callback](#step_callback)
- [target_callback](#target_callback)
### init
---
```lua
progress:init(node, key, [init_value])
```
- **Parameters:**
- `node` *(string|node)*: Node name or GUI Node itself.
- `key` *(string)*: Progress bar direction: const.SIDE.X or const.SIDE.Y
- `[init_value]` *(number|nil)*: Initial value of progress bar. Default: 1
### on_style_change
---
```lua
progress:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.progress.style)*:
### on_layout_change
---
```lua
progress:on_layout_change()
```
### on_remove
---
```lua
progress:on_remove()
```
### update
---
```lua
progress:update(dt)
```
- **Parameters:**
- `dt` *(number)*: Delta time
### fill
---
```lua
progress:fill()
```
Fill a progress bar and stop progress animation
### empty
---
```lua
progress:empty()
```
Empty a progress bar
### set_to
---
```lua
progress:set_to(to)
```
Instant fill progress bar to value
- **Parameters:**
- `to` *(number)*: Progress bar value, from 0 to 1
### get
---
```lua
progress:get()
```
Return current progress bar value
- **Returns:**
- `` *(number)*:
### set_steps
---
```lua
progress:set_steps(steps, callback)
```
Set points on progress bar to fire the callback
- **Parameters:**
- `steps` *(number[])*: Array of progress bar values
- `callback` *(function)*: Callback on intersect step value
### to
---
```lua
progress:to(to, [callback])
```
Start animation of a progress bar
- **Parameters:**
- `to` *(number)*: value between 0..1
- `[callback]` *(function|nil)*: Callback on animation ends
### set_max_size
---
```lua
progress:set_max_size(max_size)
```
Set progress bar max node size
- **Parameters:**
- `max_size` *(vector3)*: The new node maximum (full) size
- **Returns:**
- `Progress` *(druid.progress)*:
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="on_change"></a>
- **on_change** (_event_)
<a name="style"></a>
- **style** (_druid.progress.style_)
<a name="key"></a>
- **key** (_string_)
<a name="prop"></a>
- **prop** (_hash_)
<a name="scale"></a>
- **scale** (_unknown_)
<a name="size"></a>
- **size** (_unknown_)
<a name="max_size"></a>
- **max_size** (_unknown_)
<a name="slice"></a>
- **slice** (_unknown_)
<a name="last_value"></a>
- **last_value** (_number_)
<a name="slice_size"></a>
- **slice_size** (_unknown_)
<a name="target"></a>
- **target** (_nil_)
<a name="steps"></a>
- **steps** (_number[]_)
<a name="step_callback"></a>
- **step_callback** (_function_)
<a name="target_callback"></a>
- **target_callback** (_function|nil_)

View File

@ -0,0 +1,98 @@
# druid.swipe API
> at /druid/extended/swipe.lua
## Functions
- [init](#init)
- [on_late_init](#on_late_init)
- [on_style_change](#on_style_change)
- [on_input](#on_input)
- [on_input_interrupt](#on_input_interrupt)
- [set_click_zone](#set_click_zone)
## Fields
- [node](#node)
- [on_swipe](#on_swipe)
- [style](#style)
- [click_zone](#click_zone)
### init
---
```lua
swipe:init(node_or_node_id, on_swipe_callback)
```
- **Parameters:**
- `node_or_node_id` *(string|node)*:
- `on_swipe_callback` *(function)*:
### on_late_init
---
```lua
swipe:on_late_init()
```
### on_style_change
---
```lua
swipe:on_style_change(style)
```
- **Parameters:**
- `style` *(druid.swipe.style)*:
### on_input
---
```lua
swipe:on_input(action_id, action)
```
- **Parameters:**
- `action_id` *(hash)*:
- `action` *(action)*:
- **Returns:**
- `` *(boolean)*:
### on_input_interrupt
---
```lua
swipe:on_input_interrupt()
```
### set_click_zone
---
```lua
swipe:set_click_zone([zone])
```
Strict swipe click area. Useful for
restrict events outside stencil node
- **Parameters:**
- `[zone]` *(string|node|nil)*: Gui node
## Fields
<a name="node"></a>
- **node** (_node_)
<a name="on_swipe"></a>
- **on_swipe** (_event_): function(side, dist, dt), side - "left", "right", "up", "down"
<a name="style"></a>
- **style** (_table_)
<a name="click_zone"></a>
- **click_zone** (_node_)

View File

@ -0,0 +1,133 @@
# druid.timer API
> at /druid/extended/timer.lua
## Functions
- [init](#init)
- [update](#update)
- [on_layout_change](#on_layout_change)
- [set_to](#set_to)
- [set_state](#set_state)
- [set_interval](#set_interval)
## Fields
- [on_tick](#on_tick)
- [on_set_enabled](#on_set_enabled)
- [on_timer_end](#on_timer_end)
- [node](#node)
- [from](#from)
- [target](#target)
- [value](#value)
- [is_on](#is_on)
- [temp](#temp)
- [last_value](#last_value)
### init
---
```lua
timer:init(node, [seconds_from], [seconds_to], [callback])
```
- **Parameters:**
- `node` *(node)*: Gui text node
- `[seconds_from]` *(number|nil)*: Start timer value in seconds
- `[seconds_to]` *(number|nil)*: End timer value in seconds
- `[callback]` *(function|nil)*: Function on timer end
- **Returns:**
- `` *(druid.timer)*:
### update
---
```lua
timer:update([dt])
```
- **Parameters:**
- `[dt]` *(any)*:
### on_layout_change
---
```lua
timer:on_layout_change()
```
### set_to
---
```lua
timer:set_to(set_to)
```
- **Parameters:**
- `set_to` *(number)*: Value in seconds
- **Returns:**
- `self` *(druid.timer)*:
### set_state
---
```lua
timer:set_state([is_on])
```
- **Parameters:**
- `[is_on]` *(boolean|nil)*: Timer enable state
- **Returns:**
- `self` *(druid.timer)*:
### set_interval
---
```lua
timer:set_interval(from, to)
```
- **Parameters:**
- `from` *(number)*: Start time in seconds
- `to` *(number)*: Target time in seconds
- **Returns:**
- `self` *(druid.timer)*:
## Fields
<a name="on_tick"></a>
- **on_tick** (_event_)
<a name="on_set_enabled"></a>
- **on_set_enabled** (_event_)
<a name="on_timer_end"></a>
- **on_timer_end** (_event_)
<a name="node"></a>
- **node** (_node_)
<a name="from"></a>
- **from** (_number_)
<a name="target"></a>
- **target** (_number_)
<a name="value"></a>
- **value** (_number_)
<a name="is_on"></a>
- **is_on** (_boolean_)
<a name="temp"></a>
- **temp** (_unknown_)
<a name="last_value"></a>
- **last_value** (_number_)

104
api/druid_api.md Normal file
View File

@ -0,0 +1,104 @@
# druid API
> at /druid/druid.lua
Entry point for Druid UI Framework.
Create a new Druid instance and adjust the Druid settings here.
## Table of Contents
## Functions
- [new](#new)
- [set_default_style](#set_default_style)
- [set_text_function](#set_text_function)
- [set_sound_function](#set_sound_function)
- [init_window_listener](#init_window_listener)
- [on_window_callback](#on_window_callback)
- [on_language_change](#on_language_change)
### new
---
```lua
druid.new(context, [style])
```
Create a new Druid instance for creating GUI components.
- **Parameters:**
- `context` *(table)*: The Druid context. Usually, this is the self of the gui_script. It is passed into all Druid callbacks.
- `[style]` *(table|nil)*: The Druid style table to override style parameters for this Druid instance.
- **Returns:**
- `druid_instance` *(druid.instance)*: The new Druid instance
### set_default_style
---
```lua
druid.set_default_style(style)
```
Set the default style for all Druid instances.
- **Parameters:**
- `style` *(table)*: Default style
### set_text_function
---
```lua
druid.set_text_function(callback)
```
Set the text function for the LangText component.
- **Parameters:**
- `callback` *(fun(text_id: string):string)*: Get localized text function
### set_sound_function
---
```lua
druid.set_sound_function(callback)
```
Set the sound function to able components to play sounds.
- **Parameters:**
- `callback` *(fun(sound_id: string))*: Sound play callback
### init_window_listener
---
```lua
druid.init_window_listener()
```
Subscribe Druid to the window listener. It will override your previous
window listener, so if you have one, you should call M.on_window_callback manually.
### on_window_callback
---
```lua
druid.on_window_callback(window_event)
```
Set the window callback to enable Druid window events.
- **Parameters:**
- `window_event` *(constant)*: Event param from window listener
### on_language_change
---
```lua
druid.on_language_change()
```
Call this function when the game language changes.
It will notify all Druid instances to update the lang text components.

518
api/druid_helper_api.md Normal file
View File

@ -0,0 +1,518 @@
# druid.helper API
> at /druid/helper.lua
The helper module contains various functions that are used in the Druid library.
You can use these functions in your projects as well.
## Functions
- [centrate_text_with_icon](#centrate_text_with_icon)
- [centrate_icon_with_text](#centrate_icon_with_text)
- [centrate_nodes](#centrate_nodes)
- [get_node](#get_node)
- [get_screen_aspect_koef](#get_screen_aspect_koef)
- [get_gui_scale](#get_gui_scale)
- [step](#step)
- [clamp](#clamp)
- [distance](#distance)
- [sign](#sign)
- [round](#round)
- [lerp](#lerp)
- [contains](#contains)
- [deepcopy](#deepcopy)
- [add_array](#add_array)
- [pick_node](#pick_node)
- [get_scaled_size](#get_scaled_size)
- [get_scene_scale](#get_scene_scale)
- [get_closest_stencil_node](#get_closest_stencil_node)
- [get_pivot_offset](#get_pivot_offset)
- [is_mobile](#is_mobile)
- [is_web](#is_web)
- [is_web_mobile](#is_web_mobile)
- [is_multitouch_supported](#is_multitouch_supported)
- [table_to_string](#table_to_string)
- [get_border](#get_border)
- [get_text_metrics_from_node](#get_text_metrics_from_node)
- [insert_with_shift](#insert_with_shift)
- [remove_with_shift](#remove_with_shift)
- [get_full_position](#get_full_position)
## Fields
- [PROP_SIZE_X](#PROP_SIZE_X)
- [PROP_SIZE_Y](#PROP_SIZE_Y)
- [PROP_SCALE_X](#PROP_SCALE_X)
- [PROP_SCALE_Y](#PROP_SCALE_Y)
### centrate_text_with_icon
---
```lua
helper.centrate_text_with_icon([text_node], [icon_node], margin)
```
Center two nodes.
Nodes will be center around 0 x position
text_node will be first (at left side)
- **Parameters:**
- `[text_node]` *(node|nil)*: Gui text node
- `[icon_node]` *(node|nil)*: Gui box node
- `margin` *(number)*: Offset between nodes
- **Returns:**
- `` *(unknown)*:
### centrate_icon_with_text
---
```lua
helper.centrate_icon_with_text([icon_node], [text_node], [margin])
```
Center two nodes.
Nodes will be center around 0 x position
icon_node will be first (at left side)
- **Parameters:**
- `[icon_node]` *(node|nil)*: Gui box node
- `[text_node]` *(node|nil)*: Gui text node
- `[margin]` *(number|nil)*: Offset between nodes
- **Returns:**
- `` *(unknown)*:
### centrate_nodes
---
```lua
helper.centrate_nodes([margin], ...)
```
Centerate nodes by x position with margin.
This functions calculate total width of nodes and set position for each node.
The centrate will be around 0 x position.
- **Parameters:**
- `[margin]` *(number|nil)*: Offset between nodes
- `...` *(...)*: vararg
- **Returns:**
- `` *(unknown)*:
### get_node
---
```lua
helper.get_node(node_id, [template], [nodes])
```
- **Parameters:**
- `node_id` *(string|node)*:
- `[template]` *(string|nil)*: Full Path to the template
- `[nodes]` *(table<hash, node>|nil)*: Nodes what created with gui.clone_tree
- **Returns:**
- `` *(node)*:
### get_screen_aspect_koef
---
```lua
helper.get_screen_aspect_koef()
```
Get current screen stretch multiplier for each side
- **Returns:**
- `stretch_x` *(number)*:
- `stretch_y` *(number)*:
### get_gui_scale
---
```lua
helper.get_gui_scale()
```
Get current GUI scale for each side
- **Returns:**
- `scale_x` *(number)*:
### step
---
```lua
helper.step(current, target, step)
```
Move value from current to target value with step amount
- **Parameters:**
- `current` *(number)*: Current value
- `target` *(number)*: Target value
- `step` *(number)*: Step amount
- **Returns:**
- `New` *(number)*: value
### clamp
---
```lua
helper.clamp(value, [v1], [v2])
```
Clamp value between min and max. Works with nil values and swap min and max if needed.
- **Parameters:**
- `value` *(number)*: Value
- `[v1]` *(number|nil)*: Min value. If nil, value will be clamped to positive infinity
- `[v2]` *(number|nil)*: Max value If nil, value will be clamped to negative infinity
- **Returns:**
- `value` *(number)*: Clamped value
### distance
---
```lua
helper.distance(x1, y1, x2, y2)
```
Calculate distance between two points
- **Parameters:**
- `x1` *(number)*: First point x
- `y1` *(number)*: First point y
- `x2` *(number)*: Second point x
- `y2` *(number)*: Second point y
- **Returns:**
- `Distance` *(number)*:
### sign
---
```lua
helper.sign(val)
```
Return sign of value
- **Parameters:**
- `val` *(number)*: Value
- **Returns:**
- `sign` *(number)*: Sign of value, -1, 0 or 1
### round
---
```lua
helper.round(num, [num_decimal_places])
```
Round number to specified decimal places
- **Parameters:**
- `num` *(number)*: Number
- `[num_decimal_places]` *(number|nil)*: Decimal places
- **Returns:**
- `value` *(number)*: Rounded number
### lerp
---
```lua
helper.lerp(a, b, t)
```
Lerp between two values
- **Parameters:**
- `a` *(number)*: First value
- `b` *(number)*: Second value
- `t` *(number)*: Lerp amount
- **Returns:**
- `value` *(number)*: Lerped value
### contains
---
```lua
helper.contains([array], [value])
```
Check if value contains in array
- **Parameters:**
- `[array]` *(any[])*: Array to check
- `[value]` *(any)*: Value
- **Returns:**
- `` *(integer|nil)*:
### deepcopy
---
```lua
helper.deepcopy(orig_table)
```
Make a copy table with all nested tables
- **Parameters:**
- `orig_table` *(table)*: Original table
- **Returns:**
- `Copy` *(table)*: of original table
### add_array
---
```lua
helper.add_array([target], [source])
```
Add all elements from source array to the target array
- **Parameters:**
- `[target]` *(any[])*: Array to put elements from source
- `[source]` *(any[]|nil)*: The source array to get elements from
- **Returns:**
- `The` *(any[])*: target array
### pick_node
---
```lua
helper.pick_node(node, x, y, [node_click_area])
```
Make a check with gui.pick_node, but with additional node_click_area check.
- **Parameters:**
- `node` *(node)*:
- `x` *(number)*:
- `y` *(number)*:
- `[node_click_area]` *(node|nil)*: Additional node to check for click area. If nil, only node will be checked
- **Returns:**
- `` *(unknown)*:
### get_scaled_size
---
```lua
helper.get_scaled_size(node)
```
Get size of node with scale multiplier
- **Parameters:**
- `node` *(node)*: GUI node
- **Returns:**
- `scaled_size` *(vector3)*:
### get_scene_scale
---
```lua
helper.get_scene_scale(node, [include_passed_node_scale])
```
Get cumulative parent's node scale
- **Parameters:**
- `node` *(node)*: Gui node
- `[include_passed_node_scale]` *(boolean|nil)*: True if add current node scale to result
- **Returns:**
- `The` *(vector3)*: scene node scale
### get_closest_stencil_node
---
```lua
helper.get_closest_stencil_node(node)
```
Return closest non inverted clipping parent node for given node
- **Parameters:**
- `node` *(node)*: GUI node
- **Returns:**
- `stencil_node` *(node|nil)*: The closest stencil node or nil
### get_pivot_offset
---
```lua
helper.get_pivot_offset(pivot_or_node)
```
Get pivot offset for given pivot or node
Offset shown in [-0.5 .. 0.5] range, where -0.5 is left or bottom, 0.5 is right or top.
- **Parameters:**
- `pivot_or_node` *(number|node)*: GUI pivot or node
- **Returns:**
- `offset` *(vector3)*: The pivot offset
### is_mobile
---
```lua
helper.is_mobile()
```
Check if device is native mobile (Android or iOS)
- **Returns:**
- `Is` *(boolean)*: mobile
### is_web
---
```lua
helper.is_web()
```
Check if device is HTML5
- **Returns:**
- `` *(boolean)*:
### is_web_mobile
---
```lua
helper.is_web_mobile()
```
Check if device is HTML5 mobile
- **Returns:**
- `` *(boolean)*:
### is_multitouch_supported
---
```lua
helper.is_multitouch_supported()
```
Check if device is mobile and can support multitouch
- **Returns:**
- `is_multitouch` *(boolean)*: Is multitouch supported
### table_to_string
---
```lua
helper.table_to_string(t)
```
Simple table to one-line string converter
- **Parameters:**
- `t` *(table)*:
- **Returns:**
- `` *(string)*:
### get_border
---
```lua
helper.get_border(node, [offset])
```
Distance from node position to his borders
- **Parameters:**
- `node` *(node)*: GUI node
- `[offset]` *(vector3|nil)*: Offset from node position. Pass current node position to get non relative border values
- **Returns:**
- `border` *(vector4)*: Vector4 with border values (left, top, right, down)
### get_text_metrics_from_node
---
```lua
helper.get_text_metrics_from_node(text_node)
```
Get text metric from GUI node.
- **Parameters:**
- `text_node` *(node)*:
- **Returns:**
- `` *(GUITextMetrics)*:
### insert_with_shift
---
```lua
helper.insert_with_shift(array, [item], [index], [shift_policy])
```
Add value to array with shift policy
Shift policy can be: left, right, no_shift
- **Parameters:**
- `array` *(table)*: Array
- `[item]` *(any)*: Item to insert
- `[index]` *(number|nil)*: Index to insert. If nil, item will be inserted at the end of array
- `[shift_policy]` *(number|nil)*: The druid_const.SHIFT.* constant
- **Returns:**
- `Inserted` *(any)*: item
### remove_with_shift
---
```lua
helper.remove_with_shift([array], [index], [shift_policy])
```
Remove value from array with shift policy
Shift policy can be: left, right, no_shift
- **Parameters:**
- `[array]` *(any[])*: Array
- `[index]` *(number|nil)*: Index to remove. If nil, item will be removed from the end of array
- `[shift_policy]` *(number|nil)*: The druid_const.SHIFT.* constant
- **Returns:**
- `Removed` *(any)*: item
### get_full_position
---
```lua
helper.get_full_position(node, [root])
```
Get full position of node in the GUI tree
- **Parameters:**
- `node` *(node)*: GUI node
- `[root]` *(node|nil)*: GUI root node to stop search
- **Returns:**
- `` *(unknown)*:

530
api/druid_instance_api.md Normal file
View File

@ -0,0 +1,530 @@
# druid.instance API
> at /druid/system/druid_instance.lua
## Functions
- [new](#new)
- [final](#final)
- [remove](#remove)
- [update](#update)
- [on_input](#on_input)
- [on_message](#on_message)
- [set_whitelist](#set_whitelist)
- [set_blacklist](#set_blacklist)
- [new_widget](#new_widget)
- [new_button](#new_button)
- [new_blocker](#new_blocker)
- [new_back_handler](#new_back_handler)
- [new_hover](#new_hover)
- [new_text](#new_text)
- [new_grid](#new_grid)
- [new_scroll](#new_scroll)
- [new_drag](#new_drag)
- [new_swipe](#new_swipe)
- [new_lang_text](#new_lang_text)
- [new_slider](#new_slider)
- [new_input](#new_input)
- [new_data_list](#new_data_list)
- [new_timer](#new_timer)
- [new_progress](#new_progress)
- [new_layout](#new_layout)
- [new_container](#new_container)
- [new_hotkey](#new_hotkey)
- [new_rich_text](#new_rich_text)
- [new_rich_input](#new_rich_input)
### create_druid_instance
---
```lua
instance.create_druid_instance(context, [style])
```
Druid class constructor which used to create a Druid's components
- **Parameters:**
- `context` *(table)*: Druid context. Usually it is self of gui script
- `[style]` *(table?)*: Druid style table
- **Returns:**
- `` *(druid.instance)*:
### new
---
```lua
instance:new(component, ...)
```
Create new Druid component instance
- **Parameters:**
- `component` *(<T:druid.component>)*:
- `...` *(...)*: vararg
- **Returns:**
- `` *(<T:druid.component>)*:
### final
---
```lua
instance:final()
```
Call this in gui_script final function.
### remove
---
```lua
instance:remove(component)
```
Remove created component from Druid instance.
Component `on_remove` function will be invoked, if exist.
- **Parameters:**
- `component` *(<T:druid.component>)*: Component instance
- **Returns:**
- `True` *(boolean)*: if component was removed
### update
---
```lua
instance:update(dt)
```
Call this in gui_script update function.
- **Parameters:**
- `dt` *(number)*: Delta time
### on_input
---
```lua
instance:on_input(action_id, action)
```
Call this in gui_script on_input function.
- **Parameters:**
- `action_id` *(hash)*: Action_id from on_input
- `action` *(table)*: Action from on_input
- **Returns:**
- `The` *(boolean)*: boolean value is input was consumed
### on_message
---
```lua
instance:on_message(message_id, message, sender)
```
Call this in gui_script on_message function.
- **Parameters:**
- `message_id` *(hash)*: Message_id from on_message
- `message` *(table)*: Message from on_message
- `sender` *(url)*: Sender from on_message
### on_window_event
---
```lua
instance:on_window_event([window_event])
```
- **Parameters:**
- `[window_event]` *(any)*:
### set_whitelist
---
```lua
instance:set_whitelist(whitelist_components)
```
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:**
- `whitelist_components` *(table|druid.component[])*: The array of component to whitelist
- **Returns:**
- `` *(druid.instance)*:
### set_blacklist
---
```lua
instance:set_blacklist(blacklist_components)
```
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 DruidInstance
- **Parameters:**
- `blacklist_components` *(table|druid.component[])*: The array of component to blacklist
- **Returns:**
- `` *(druid.instance)*:
### new_widget
---
```lua
instance:new_widget(widget, [template], [nodes], ...)
```
Create new Druid widget instance
- **Parameters:**
- `widget` *(<T:druid.component>)*:
- `[template]` *(string|nil)*: The template name used by widget
- `[nodes]` *(node|table<hash, node>|nil)*: The nodes table from gui.clone_tree or prefab node to use for clone
- `...` *(...)*: vararg
- **Returns:**
- `` *(<T:druid.component>)*:
### new_button
---
```lua
instance:new_button(node, [callback], [params], [anim_node])
```
Create Button component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- `[callback]` *(function|event|nil)*: Button callback
- `[params]` *(any)*: Button callback params
- `[anim_node]` *(string|node|nil)*: Button anim node (node, if not provided)
- **Returns:**
- `Button` *(druid.button)*: component
### new_blocker
---
```lua
instance:new_blocker(node)
```
Create Blocker component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- **Returns:**
- `component` *(druid.blocker)*: Blocker component
### new_back_handler
---
```lua
instance:new_back_handler([callback], [params])
```
Create BackHandler component
- **Parameters:**
- `[callback]` *(function|nil)*: The callback(self, custom_args) to call on back event
- `[params]` *(any)*: Callback argument
- **Returns:**
- `component` *(druid.back_handler)*: BackHandler component
### new_hover
---
```lua
instance:new_hover(node, [on_hover_callback], [on_mouse_hover_callback])
```
Create Hover component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- `[on_hover_callback]` *(function|nil)*: Hover callback
- `[on_mouse_hover_callback]` *(function|nil)*: Mouse hover callback
- **Returns:**
- `component` *(druid.hover)*: Hover component
### new_text
---
```lua
instance:new_text(node, [value], [adjust_type])
```
Create Text component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id)
- `[value]` *(string|nil)*: Initial text. Default value is node text from GUI scene.
- `[adjust_type]` *(string|nil)*: Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
- **Returns:**
- `component` *(druid.text)*: Text component
### new_grid
---
```lua
instance:new_grid(parent_node, item, [in_row])
```
Create Grid component
- **Parameters:**
- `parent_node` *(string|node)*: The node_id or gui.get_node(node_id). Parent of all Grid items.
- `item` *(string|node)*: Item prefab. Required to get grid's item size. Can be adjusted separately.
- `[in_row]` *(number|nil)*: How many nodes in row can be placed
- **Returns:**
- `component` *(druid.grid)*: Grid component
### new_scroll
---
```lua
instance:new_scroll(view_node, content_node)
```
Create Scroll component
- **Parameters:**
- `view_node` *(string|node)*: The node_id or gui.get_node(node_id). Will used as user input node.
- `content_node` *(string|node)*: The node_id or gui.get_node(node_id). Will used as scrollable node inside view_node.
- **Returns:**
- `component` *(druid.scroll)*: Scroll component
### new_drag
---
```lua
instance:new_drag(node, [on_drag_callback])
```
Create Drag component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id). Will used as user input node.
- `[on_drag_callback]` *(function|nil)*: Callback for on_drag_event(self, dx, dy)
- **Returns:**
- `component` *(druid.drag)*: Drag component
### new_swipe
---
```lua
instance:new_swipe(node, [on_swipe_callback])
```
Create Swipe component
- **Parameters:**
- `node` *(string|node)*: The node_id or gui.get_node(node_id). Will used as user input node.
- `[on_swipe_callback]` *(function|nil)*: Swipe callback for on_swipe_end event
- **Returns:**
- `component` *(druid.swipe)*: Swipe component
### new_lang_text
---
```lua
instance:new_lang_text(node, [locale_id], [adjust_type])
```
Create LangText component
- **Parameters:**
- `node` *(string|node)*: The_node id or gui.get_node(node_id)
- `[locale_id]` *(string|nil)*: Default locale id or text from node as default
- `[adjust_type]` *(string|nil)*: Adjust type for text node. Default: const.TEXT_ADJUST.DOWNSCALE
- **Returns:**
- `component` *(druid.lang_text)*: LangText component
### new_slider
---
```lua
instance:new_slider(pin_node, end_pos, [callback])
```
Create Slider component
- **Parameters:**
- `pin_node` *(string|node)*: The_node id or gui.get_node(node_id).
- `end_pos` *(vector3)*: The end position of slider
- `[callback]` *(function|nil)*: On slider change callback
- **Returns:**
- `component` *(druid.slider)*: Slider component
### new_input
---
```lua
instance:new_input(click_node, text_node, [keyboard_type])
```
Create Input component
- **Parameters:**
- `click_node` *(string|node)*: Button node to enabled input component
- `text_node` *(string|druid.text|node)*: Text node what will be changed on user input
- `[keyboard_type]` *(number|nil)*: Gui keyboard type for input field
- **Returns:**
- `component` *(druid.input)*: Input component
### new_data_list
---
```lua
instance:new_data_list(druid_scroll, druid_grid, create_function)
```
Create DataList component
- **Parameters:**
- `druid_scroll` *(druid.scroll)*: The Scroll instance for Data List component
- `druid_grid` *(druid.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:**
- `component` *(druid.data_list)*: DataList component
### new_timer
---
```lua
instance:new_timer(node, [seconds_from], [seconds_to], [callback])
```
Create Timer component
- **Parameters:**
- `node` *(string|node)*: Gui text node
- `[seconds_from]` *(number|nil)*: Start timer value in seconds
- `[seconds_to]` *(number|nil)*: End timer value in seconds
- `[callback]` *(function|nil)*: Function on timer end
- **Returns:**
- `component` *(druid.timer)*: Timer component
### new_progress
---
```lua
instance:new_progress(node, key, [init_value])
```
Create Progress component
- **Parameters:**
- `node` *(string|node)*: Progress bar fill node or node name
- `key` *(string)*: Progress bar direction: const.SIDE.X or const.SIDE.Y
- `[init_value]` *(number|nil)*: Initial value of progress bar. Default: 1
- **Returns:**
- `component` *(druid.progress)*: Progress component
### new_layout
---
```lua
instance:new_layout(node, [mode])
```
Create Layout component
- **Parameters:**
- `node` *(string|node)*: The_node id or gui.get_node(node_id).
- `[mode]` *(string|nil)*: vertical|horizontal|horizontal_wrap. Default: horizontal
- **Returns:**
- `component` *(druid.layout)*: Layout component
### new_container
---
```lua
instance:new_container(node, [mode], [callback])
```
Create Container component
- **Parameters:**
- `node` *(string|node)*: The_node id or gui.get_node(node_id).
- `[mode]` *(string|nil)*: Layout mode
- `[callback]` *(fun(self: druid.container, size: vector3)|nil)*: Callback on size changed
- **Returns:**
- `container` *(druid.container)*: component
### new_hotkey
---
```lua
instance:new_hotkey(keys_array, [callback], [callback_argument])
```
Create Hotkey component
- **Parameters:**
- `keys_array` *(string|string[])*: Keys for trigger action. Should contains one action key and any amount of modificator keys
- `[callback]` *(function|nil)*: The callback function
- `[callback_argument]` *(any)*: The argument to pass into the callback function
- **Returns:**
- `component` *(druid.hotkey)*: Hotkey component
### new_rich_text
---
```lua
instance:new_rich_text(text_node, [value])
```
Create RichText component.
- **Parameters:**
- `text_node` *(string|node)*: The text node to make Rich Text
- `[value]` *(string|nil)*: The initial text value. Default will be gui.get_text(text_node)
- **Returns:**
- `component` *(druid.rich_text)*: RichText component
### new_rich_input
---
```lua
instance:new_rich_input(template, [nodes])
```
Create RichInput component.
As a template please check rich_input.gui layout.
- **Parameters:**
- `template` *(string)*: The template string name
- `[nodes]` *(table|nil)*: Nodes table from gui.clone_tree
- **Returns:**
- `component` *(druid.rich_input)*: RichInput component

View File

@ -1,47 +0,0 @@
# Druid Back Handler Component
## Description
The Back Handler component is designed to handle back button actions, including the Android back button and the Backspace key. It provides a simple way to implement back navigation or other actions when the user presses the back button.
## Features
- Handles Android back button and Backspace key presses
- Customizable callback function
- Optional parameters to pass to the callback
- Event-based architecture
## Basic Usage
```lua
local callback = function(self, params)
-- Handle back action here
print("Back button pressed!")
end
local params = { custom_data = "value" }
local back_handler = self.druid:new_back_handler(callback, params)
```
### Parameters
- **callback**: (optional) Function to call when back button is pressed
- **params**: (optional) Custom data to pass to the callback
## Events
The Back Handler component provides an event you can subscribe to:
```lua
-- Subscribe to back event
back_handler.on_back:subscribe(function(self, params)
print("Back button was pressed!")
end)
```
## Notes
- The Back Handler component requires proper key triggers setup in your `input.binding` file for correct operation
- Back Handler is recommended to be placed in every game window to handle closing or in the main screen to call settings windows
- Multiple Back Handlers can be active at the same time, but only the first one that processes the input will trigger its callback
- Back Handler reacts on release action of ACTION_BACK or ACTION_BACKSPACE

View File

@ -1,8 +0,0 @@
# Blocker Quick API reference
```lua
blocker:init(node)
blocker:is_enabled()
blocker:on_input([action_id], [action])
blocker:set_enabled([state])
```

View File

@ -1,50 +0,0 @@
# Druid Blocker Component
## Description
The Blocker component is designed to consume input in a specific zone defined by a GUI node. It's useful for creating unclickable zones within buttons or for creating panels of buttons on top of another button.
## Features
- Blocks input in a specific zone
- Can be enabled or disabled programmatically
- Useful for creating safe zones in UI
## Basic Usage
```lua
local blocker = self.druid:new_blocker("blocker_node")
```
### Parameters
- **node**: The node or node_id of the blocker node
## Methods
```lua
-- Enable or disable the blocker
blocker:set_enabled(true) -- Enable
blocker:set_enabled(false) -- Disable
-- Check if blocker is enabled
local is_enabled = blocker:is_enabled()
```
## Notes
- The Blocker component consumes input if `gui.pick_node` works on it
- The Blocker node should be enabled to capture input
- The initial enabled state is determined by `gui.is_enabled(node, true)`
- Blocker is useful for creating "safe zones" in your UI, where you have large buttons with specific clickable areas
- A common use case is to place a blocker with window content behind a close button, so clicking outside the close button (but still on the window) doesn't trigger actions from elements behind the window
### Example Use Case
![Blocker Scheme](../../../media/blocker_scheme.png)
In this example:
- Blue zone is a **button** with close_window callback
- Yellow zone is a blocker with window content
This setup creates a safe zone where the user can interact with the window content without accidentally triggering actions from elements behind the window.

View File

@ -1,91 +0,0 @@
# Druid Button Component
## Description
Button component is a basic component that can be used to create a clickable button. It provides various interaction callbacks such as click, long click, double click, and more. The component makes any GUI node clickable and allows you to define different behaviors for various user interactions.
Button component is not support multitouch. In case of multitouch required (ex. on screen control) the custom component should be written with own input handling.
## Features
- Regular click handling
- Long click detection
- Double click detection
- Repeated click handling (while holding)
- Hold state callbacks
- Click outside detection
- Keyboard key triggering
- Custom animation node support
- Enabled/disabled states
- Customizable click zones
- HTML5 interaction support
## Basic Usage
```lua
local button = self.druid:new_button(node, [callback], [params], [anim_node])
```
### Parameters
- **node**: The node or node_id to make clickable
- **callback**: (optional) Function to call when button is clicked
- **params**: (optional) Custom arguments to pass to the callback
- **anim_node**: (optional) Node to animate instead of the trigger node
### Example
```lua
-- Simple button with callback
local button = self.druid:new_button("button_node", function(self, params, button_instance)
print("Button clicked!")
end)
-- Button with custom parameters
local custom_args = "Any data to pass to callback"
local button = self.druid:new_button("button_node", on_button_click, custom_args)
-- Button with separate animation node
local button = self.druid:new_button("big_panel", callback, nil, "small_icon")
```
## HTML5 Interaction
The Button component supports HTML5 interaction mode, which allows you to define different behaviors for various user interactions. Use this mode when you need to use special interactions like copy/paste, keyboard, etc.
```lua
button:set_web_user_interaction(true)
```
## Events
The Button component provides several events you can subscribe to:
- **on_click**: Triggered when button is clicked
- **on_pressed**: Triggered when button is pressed down
- **on_repeated_click**: Triggered repeatedly while holding the button
- **on_long_click**: Triggered when button is held for a certain time
- **on_double_click**: Triggered when button is clicked twice in quick succession
- **on_hold_callback**: Triggered while holding the button, before long_click
- **on_click_outside**: Triggered when click is released outside the button
### Example
```lua
-- Subscribe to double click event
button.on_double_click:subscribe(function(self, params, button_instance, click_amount)
print("Double clicked! Click amount: " .. click_amount)
end)
-- Subscribe to long click event
button.on_long_click:subscribe(function(self, params, button_instance, hold_time)
print("Long press detected! Hold time: " .. hold_time)
end)
```
## Notes
- The click callback will not trigger if the cursor moves outside the node's area between pressed and released states
- If a button has a double click event and it is triggered, the regular click callback will not be invoked
- If you have a stencil on buttons and don't want to trigger them outside the stencil node, use `button:set_click_zone`
- Animation node can be used to animate a small icon on a big panel (trigger zone is the big panel, animation node is the small icon)

View File

@ -1,14 +0,0 @@
# Drag Quick API reference
```lua
drag:init(node_or_node_id, on_drag_callback)
drag:is_enabled()
drag:on_input([action_id], [action])
drag:on_input_interrupt()
drag:on_late_init()
drag:on_style_change(style)
drag:on_window_resized()
drag:set_click_zone([node])
drag:set_drag_cursors([is_enabled])
drag:set_enabled([is_enabled])
```

View File

@ -1,79 +0,0 @@
# Druid Drag Component
## Description
The Drag component handles drag actions on a node, allowing users to move UI elements by dragging them. It provides proper handling for multitouch and swap touches while dragging.
## Features
- Handles drag actions on nodes
- Supports multitouch and touch swapping
- Provides drag start, drag, and drag end events
- Customizable drag deadzone
- Optional click zone restriction
## Basic Usage
```lua
local drag = self.druid:new_drag("drag_node", function(self, dx, dy, x, y, touch)
-- Handle drag action
local position = gui.get_position(drag.node)
gui.set_position(drag.node, vmath.vector3(position.x + dx, position.y + dy, position.z))
end)
```
### Parameters
- **node**: The node or node_id of the draggable node
- **on_drag_callback**: (optional) Function to call during drag with parameters (self, dx, dy, total_x, total_y, touch)
## Events
The Drag component provides several events you can subscribe to:
```lua
-- Subscribe to drag start event
drag.on_drag_start:subscribe(function(self, touch)
print("Drag started")
end)
-- Subscribe to drag end event
drag.on_drag_end:subscribe(function(self, x, y, touch)
print("Drag ended, total movement: " .. x .. ", " .. y)
end)
-- Subscribe to touch start/end events
drag.on_touch_start:subscribe(function(self, touch)
print("Touch started")
end)
drag.on_touch_end:subscribe(function(self, touch)
print("Touch ended")
end)
```
## Methods
```lua
-- Set a click zone to restrict drag area
drag:set_click_zone("stencil_node")
-- Enable or disable drag
drag:set_enabled(true) -- Enable
drag:set_enabled(false) -- Disable
-- Check if drag is enabled
local is_enabled = drag:is_enabled()
-- Set drag cursor appearance (requires defos)
drag:set_drag_cursors(true) -- Enable custom cursors
drag:set_drag_cursors(false) -- Disable custom cursors
```
## Notes
- Drag will be processed even if the cursor is outside of the node, as long as the drag has already started
- The component has a configurable deadzone (default: 10 pixels) before drag is triggered
- You can restrict the drag area by setting a click zone, which is useful for stencil nodes
- The drag component automatically detects the closest stencil node and sets it as the click zone if none is specified
- The drag component can be configured to use screen aspect ratio for drag values

View File

@ -1,16 +0,0 @@
# Hover Quick API reference
```lua
hover:init(node, on_hover_callback, on_mouse_hover)
hover:is_enabled()
hover:is_hovered()
hover:is_mouse_hovered()
hover:on_input([action_id], [action])
hover:on_input_interrupt()
hover:on_late_init()
hover:on_style_change(style)
hover:set_click_zone([zone])
hover:set_enabled([state])
hover:set_hover([state])
hover:set_mouse_hover([state])
```

View File

@ -1,84 +0,0 @@
# Druid Hover Component
## Description
The Hover component handles hover interactions with nodes, providing callbacks for both touch hover and mouse hover states. It's useful for creating interactive UI elements that respond to user hover actions.
## Features
- Handles touch hover (with pressed action)
- Handles mouse hover (without pressing)
- Provides hover state tracking
- Customizable cursor styles (with defos)
- Optional click zone restriction
## Basic Usage
```lua
-- Basic hover with touch hover callback
local hover = self.druid:new_hover("node", function(self, is_hover)
-- Handle hover state change
local color = is_hover and vmath.vector4(1, 0.8, 0.8, 1) or vmath.vector4(1, 1, 1, 1)
gui.animate(hover.node, "color", color, gui.EASING_LINEAR, 0.2)
end)
-- Hover with both touch and mouse hover callbacks
local hover = self.druid:new_hover("node",
function(self, is_hover)
-- Handle touch hover
end,
function(self, is_hover)
-- Handle mouse hover
end
)
```
### Parameters
- **node**: The node or node_id of the hover node
- **on_hover_callback**: (optional) Function to call on touch hover state change
- **on_mouse_hover_callback**: (optional) Function to call on mouse hover state change
## Events
The Hover component provides two events you can subscribe to:
```lua
-- Subscribe to touch hover event
hover.on_hover:subscribe(function(self, is_hover)
print("Touch hover state: " .. tostring(is_hover))
end)
-- Subscribe to mouse hover event
hover.on_mouse_hover:subscribe(function(self, is_hover)
print("Mouse hover state: " .. tostring(is_hover))
end)
```
## Methods
```lua
-- Set hover state manually
hover:set_hover(true)
hover:set_hover(false)
-- Set mouse hover state manually
hover:set_mouse_hover(true)
hover:set_mouse_hover(false)
-- Check current hover states
local is_hovered = hover:is_hovered()
local is_mouse_hovered = hover:is_mouse_hovered()
-- Set a click zone to restrict hover area
hover:set_click_zone("stencil_node")
```
## Notes
- By default, hover handles the "hover event" with pressed touch action_id, meaning the mouse or touch has to be pressed
- On desktop platforms, there is an "on_mouse_hover" event that triggers on mouse hover without any action id
- By default, the component assumes the node is in a non-hovered state (both hover and mouse_hover)
- The hover component automatically detects the closest stencil node and sets it as the click zone if none is specified
- You can customize cursor styles for hover states if you're using the defos extension
- Hover state is automatically reset when input is interrupted or the node is disabled

View File

@ -1,20 +0,0 @@
# Scroll Quick API reference
```lua
scroll:init(view_node, content_node)
scroll:bind_grid([grid], [callback])
scroll:get_percent()
scroll:on_input([action_id], [action])
scroll:on_layout_change()
scroll:on_late_init()
scroll:on_remove()
scroll:on_style_change(style)
scroll:scroll_to(point, [is_instant])
scroll:scroll_to_index(index, [skip_cb])
scroll:scroll_to_percent(percent, [is_instant])
scroll:set_click_zone([zone])
scroll:set_horizontal_scroll([is_horizontal])
scroll:set_size(size, [offset])
scroll:set_vertical_scroll([is_vertical])
scroll:update(dt)
```

View File

@ -1,106 +0,0 @@
# Druid Scroll Component
## Description
The Scroll component handles scrollable content in your UI. It consists of two main parts: a static view node that captures user input, and a dynamic content node that moves in response to user interaction.
## Features
- Horizontal and vertical scrolling
- Inertial scrolling with customizable friction
- Points of interest for snap-to-position scrolling
- Scroll-to-position and scroll-to-percent functions
- Mouse wheel support
- Stretch effect for overscrolling
- Grid binding for automatic content size adjustment
## Basic Usage
```lua
local scroll = self.druid:new_scroll("view_node", "content_node")
```
### Parameters
- **view_node**: The node or node_id of the static view part (captures input)
- **content_node**: The node or node_id of the dynamic content part (moves when scrolling)
## Setup
The typical setup involves placing a view_node and adding a content_node as its child:
![Scroll Scheme](../../../media/scroll_scheme.png)
The view_node captures user input and defines the visible area, while the content_node contains all the scrollable content and moves in response to user interaction.
## Methods
```lua
-- Scroll to a specific position
scroll:scroll_to(vmath.vector3(100, 200, 0), false) -- Animated scroll
scroll:scroll_to(vmath.vector3(100, 200, 0), true) -- Instant scroll
-- Scroll to a percentage of the content
scroll:scroll_to_percent(vmath.vector3(0.5, 0.5, 0), false) -- Scroll to middle
-- Get current scroll percentage
local percent = scroll:get_percent()
-- Set content size
scroll:set_size(vmath.vector3(500, 1000, 0))
-- Update view size if it changes
scroll:update_view_size()
-- Enable/disable inertial scrolling
scroll:set_inert(true)
scroll:set_inert(false)
-- Set points of interest for snap-to-position scrolling
scroll:set_points({
vmath.vector3(0, 0, 0),
vmath.vector3(0, 200, 0),
vmath.vector3(0, 400, 0)
})
-- Scroll to a specific point of interest
scroll:scroll_to_index(2)
-- Enable/disable horizontal or vertical scrolling
scroll:set_horizontal_scroll(true)
scroll:set_vertical_scroll(true)
-- Check if a node is visible in the scroll view
local is_visible = scroll:is_node_in_view(node)
-- Bind a grid to automatically adjust scroll size
scroll:bind_grid(grid)
```
## Events
```lua
-- Subscribe to scroll movement
scroll.on_scroll:subscribe(function(self, position)
print("Scroll position: " .. position.x .. ", " .. position.y)
end)
-- Subscribe to scroll_to events
scroll.on_scroll_to:subscribe(function(self, target, is_instant)
print("Scrolling to: " .. target.x .. ", " .. target.y)
end)
-- Subscribe to point scroll events
scroll.on_point_scroll:subscribe(function(self, index, point)
print("Scrolled to point: " .. index)
end)
```
## Notes
- The scroll component has customizable style parameters for friction, inertia, and stretch effects
- By default, scroll has inertia and a stretching effect, which can be adjusted via style settings
- You can set up "points of interest" to make the scroll always center on the closest point
- When using a stencil node with the scroll, buttons inside the scroll may be clickable outside the stencil bounds. Use `button:set_click_zone(scroll.view_node)` to restrict button clicks to the visible area
- The scroll component automatically detects the closest stencil node and sets it as the click zone if none is specified
- Mouse wheel scrolling is supported and can be customized or disabled via style settings

View File

@ -1,17 +0,0 @@
# Static Grid Quick API reference
```lua
static_grid:init(parent, element, [in_row])
static_grid:add(item, [index], [shift_policy], [is_instant])
static_grid:get_index(pos)
static_grid:get_index_by_node(node)
static_grid:get_pos(index)
static_grid:get_size()
static_grid:get_size_for(count)
static_grid:on_layout_change()
static_grid:on_style_change(style)
static_grid:refresh()
static_grid:remove(index, [shift_policy], [is_instant])
static_grid:set_anchor(anchor)
static_grid:set_items(nodes, [is_instant])
static_grid:set_pivot(pivot)

View File

@ -1,119 +0,0 @@
# Druid Static Grid Component
## Description
The Static Grid component handles the positioning of UI elements in a grid layout with rows and columns. It provides a way to organize nodes in a structured grid with consistent spacing.
## Features
- Automatic positioning of nodes in rows and columns
- Customizable number of elements per row
- Dynamic addition and removal of nodes
- Node sorting capabilities
- Events for grid changes
- Automatic size calculation
## Basic Usage
```lua
local grid = self.druid:new_grid("parent_node", "item_prefab", 3)
-- Add nodes to the grid
local node1 = gui.clone(prefab)
local node2 = gui.clone(prefab)
grid:add(node1)
grid:add(node2)
```
### Parameters
- **parent_node**: The node or node_id of the parent container where grid items will be placed
- **item_prefab**: The node or node_id of the item prefab (used to determine item size)
- **in_row**: (optional) Number of items per row (default: 1)
## Methods
```lua
-- Add a node to the grid
local node = gui.clone(prefab)
grid:add(node)
-- Add multiple nodes
grid:add_many({node1, node2, node3})
-- Remove a node from the grid
grid:remove(node)
-- Clear all nodes from the grid
grid:clear()
-- Get node position by index
local position = grid:get_pos(5)
-- Get grid size for a specific number of elements
local size = grid:get_size_for(10)
-- Get current grid borders
local borders = grid:get_borders()
-- Get all node positions
local positions = grid:get_all_pos()
-- Set custom position function
grid:set_position_function(function(node, pos)
-- Custom positioning logic
gui.set_position(node, pos)
end)
-- Change items per row
grid:set_in_row(4)
-- Set item size
grid:set_item_size(100, 50)
-- Sort grid nodes
grid:sort_nodes(function(a, b)
-- Custom sorting logic
return gui.get_id(a) < gui.get_id(b)
end)
```
## Events
```lua
-- Subscribe to node addition
grid.on_add_item:subscribe(function(self, node)
print("Node added to grid")
end)
-- Subscribe to node removal
grid.on_remove_item:subscribe(function(self, node)
print("Node removed from grid")
end)
-- Subscribe to grid changes
grid.on_change_items:subscribe(function(self)
print("Grid items changed")
end)
-- Subscribe to grid clear
grid.on_clear:subscribe(function(self)
print("Grid cleared")
end)
-- Subscribe to position updates
grid.on_update_positions:subscribe(function(self)
print("Grid positions updated")
end)
```
## Notes
- The grid component calculates positions based on the size of the item prefab
- The grid's pivot point affects how items are positioned within the grid
- You can customize the grid's behavior with style settings:
- `IS_DYNAMIC_NODE_POSES`: If true, always centers grid content based on the grid's pivot
- `IS_ALIGN_LAST_ROW`: If true, always aligns the last row of the grid based on the grid's pivot
- The grid component does not automatically delete GUI nodes when cleared or when nodes are removed
- The grid can be used with the Scroll component to create scrollable lists
- When used with DataList, the grid can efficiently handle large collections of data

View File

@ -1,17 +0,0 @@
# Text Quick API reference
```lua
text:init(node, [value], [adjust_type])
text:get_text()
text:get_text_index_by_width(width)
text:get_text_size([text])
text:is_multiline()
text:on_layout_change()
text:on_style_change(style)
text:set_alpha(alpha)
text:set_color(color)
text:set_pivot(pivot)
text:set_scale(scale)
text:set_size(size)
text:set_text(new_text)
text:set_text_adjust([adjust_type], [minimal_scale])

View File

@ -1,141 +0,0 @@
# Druid Text Component
## Description
Text component is a basic component that provides various adjustment modes for text nodes. It allows text to be scaled down to fit within the size of the text node, trimmed, scrolled, or a combination of these adjustments. The component makes it easy to handle text display in different scenarios.
## Features
- Automatic text size adjustment
- Multiple text adjustment modes (downscale, trim, scroll, etc.)
- Text pivot control
- Text color and alpha management
- Text size and scale control
- Text metrics calculation
- Event-based architecture for text changes
## Basic Usage
```lua
local text = self.druid:new_text(node, [initial_value], [adjust_type])
```
### Parameters
- **node**: The node or node_id of the text node
- **initial_value**: (optional) Initial text value. Default is the text from the GUI node
- **adjust_type**: (optional) Adjustment type for text. Default is "DOWNSCALE". See adjustment types below
### Example
```lua
-- Simple text component
local text = self.druid:new_text("text_node")
-- Text with initial value
local text = self.druid:new_text("text_node", "Hello, World!")
-- Text with specific adjustment type
local text = self.druid:new_text("text_node", "Hello, World!", const.TEXT_ADJUST.TRIM)
```
## Text Adjustment Types
The Text component supports several adjustment types to handle different text display scenarios:
- **DOWNSCALE**: Scales down the text to fit within the text node's size
- **NO_ADJUST**: No adjustment, text displays as is
- **TRIM**: Trims the text with an ellipsis (...) if it doesn't fit
- **TRIM_LEFT**: Trims the text from the left with an ellipsis if it doesn't fit
- **DOWNSCALE_LIMITED**: Scales down the text but not below a minimum scale
- **SCROLL**: Shifts the text anchor when it doesn't fit
- **SCALE_THEN_SCROLL**: First scales down the text, then scrolls if needed
- **SCALE_THEN_TRIM**: First scales down the text, then trims if needed
- **SCALE_THEN_TRIM_LEFT**: First scales down the text, then trims from the left if needed
### Example
```lua
-- Import constants
local const = require("druid.const")
-- Create text with TRIM adjustment
local text = self.druid:new_text("text_node", "Long text that might not fit", const.TEXT_ADJUST.TRIM)
-- Change adjustment type later
text:set_text_adjust(const.TEXT_ADJUST.SCALE_THEN_TRIM)
```
## Events
The Text component provides several events you can subscribe to:
- **on_set_text**: Triggered when text is set or changed
- **on_update_text_scale**: Triggered when text scale is updated
- **on_set_pivot**: Triggered when text pivot is changed
### Example
```lua
-- Subscribe to text change event
text.on_set_text:subscribe(function(self, text_value)
print("Text changed to: " .. text_value)
end)
-- Subscribe to scale update event
text.on_update_text_scale:subscribe(function(self, scale, metrics)
print("Text scale updated to: " .. scale.x)
end)
```
## Methods
```lua
-- Set text content
text:set_text("New text content")
-- Get current text content
local current_text = text:get_text()
-- Set text area size
text:set_size(vmath.vector3(200, 100, 0))
-- Set text color
text:set_color(vmath.vector4(1, 0, 0, 1)) -- Red color
-- Set text alpha
text:set_alpha(0.5) -- 50% opacity
-- Set text scale
text:set_scale(vmath.vector3(1.5, 1.5, 1)) -- 150% scale
-- Set text pivot
text:set_pivot(gui.PIVOT_CENTER)
-- Check if text is multiline
local is_multiline = text:is_multiline()
-- Set text adjustment type
text:set_text_adjust(const.TEXT_ADJUST.TRIM)
-- Set minimal scale for limited adjustment types
text:set_minimal_scale(0.5) -- 50% minimum scale
-- Get current text adjustment type
local adjust_type = text:get_text_adjust()
-- Get text size (width and height)
local width, height = text:get_text_size()
-- Get text index by width (useful for cursor positioning)
local char_index = text:get_text_index_by_width(100)
```
## Notes
- Text component by default has auto-adjust text sizing. Text will never be bigger than the text node size, which you can set up in the GUI scene.
- Auto-adjustment can be disabled by setting the adjustment type to `NO_ADJUST`.
- Text pivot can be changed with `text:set_pivot()`, and the text will maintain its position inside the text size box.
- For multiline text, the component will try to fit the text within both width and height constraints.
- The trim postfix (default: "...") can be customized in the style settings.
- When using `DOWNSCALE_LIMITED` or `SCALE_THEN_SCROLL`, you can set a minimal scale to prevent text from becoming too small.

View File

@ -1,12 +0,0 @@
## Rich Input Quick API reference
```lua
rich_input:get_text()
rich_input:init(template, nodes)
rich_input:on_input([action_id], [action])
rich_input:select()
rich_input:set_allowed_characters(characters)
rich_input:set_font(font)
rich_input:set_placeholder(placeholder_text)
rich_input:set_text(text)
```

View File

@ -1,197 +0,0 @@
# Druid Rich Input Component
## Description
The Rich Input component provides an enhanced text input field with advanced features like text selection, cursor positioning, and placeholder text. It extends the basic Input component to offer a more sophisticated text entry experience.
## Features
- Text input with cursor support
- Text selection capabilities
- Customizable placeholder text
- Maximum length restriction
- Input validation and filtering
- Events for text changes and interactions
- Support for multiline input
- Customizable visual feedback
## Basic Usage
```lua
-- Create a basic rich input
local rich_input = self.druid:new_rich_input("input_node", "input_text_node")
-- Set initial text
rich_input:set_text("Initial text")
-- Set placeholder text
rich_input:set_placeholder("Enter text here...")
```
### Parameters
- **node**: The node or node_id of the input background
- **text_node**: The node or node_id of the text component
- **keyboard_type**: (optional) The type of keyboard to show on mobile devices
## Methods
```lua
-- Set input text
rich_input:set_text("New text")
-- Get current text
local text = rich_input:get_text()
-- Clear input
rich_input:clear()
-- Set maximum text length
rich_input:set_max_length(50)
-- Set input validation pattern
rich_input:set_allowed_characters("[%w%s]") -- Only alphanumeric and spaces
-- Set placeholder text
rich_input:set_placeholder("Enter text here...")
-- Set placeholder color
rich_input:set_placeholder_color(vmath.vector4(0.5, 0.5, 0.5, 1))
-- Enable/disable multiline input
rich_input:set_multiline(true)
rich_input:set_multiline(false)
-- Enable/disable the input
rich_input:set_enabled(true)
rich_input:set_enabled(false)
-- Check if input is enabled
local is_enabled = rich_input:is_enabled()
-- Set input focus
rich_input:set_focus()
-- Remove input focus
rich_input:remove_focus()
-- Check if input has focus
local has_focus = rich_input:is_focused()
-- Select all text
rich_input:select_all()
-- Set cursor position
rich_input:set_cursor_position(5)
-- Set selection range
rich_input:set_selection(2, 5) -- Select characters from index 2 to 5
-- Get current selection
local selection_start, selection_end = rich_input:get_selection()
```
## Events
```lua
-- Subscribe to text change event
rich_input.on_input_text:subscribe(function(self, text)
print("Text changed to: " .. text)
end)
-- Subscribe to focus events
rich_input.on_focus:subscribe(function(self)
print("Input gained focus")
end)
rich_input.on_focus_lost:subscribe(function(self)
print("Input lost focus")
end)
-- Subscribe to input submit event (Enter key)
rich_input.on_submit:subscribe(function(self)
print("Input submitted with text: " .. self:get_text())
end)
-- Subscribe to input canceled event (Escape key)
rich_input.on_cancel:subscribe(function(self)
print("Input canceled")
end)
-- Subscribe to selection change event
rich_input.on_selection_change:subscribe(function(self, start, end_pos)
print("Selection changed: " .. start .. " to " .. end_pos)
end)
-- Subscribe to cursor position change event
rich_input.on_cursor_change:subscribe(function(self, position)
print("Cursor position: " .. position)
end)
```
## Examples
```lua
-- Create a username input with validation
local username_input = self.druid:new_rich_input("username_bg", "username_text")
username_input:set_placeholder("Username")
username_input:set_allowed_characters("[%w_]") -- Only alphanumeric and underscore
username_input:set_max_length(20)
-- Create a password input
local password_input = self.druid:new_rich_input("password_bg", "password_text")
password_input:set_placeholder("Password")
password_input:set_password(true)
password_input:set_password_char("•")
-- Create a multiline text area
local text_area = self.druid:new_rich_input("textarea_bg", "textarea_text")
text_area:set_multiline(true)
text_area:set_placeholder("Enter your message here...")
-- Create a search input with clear button
local search_input = self.druid:new_rich_input("search_bg", "search_text")
search_input:set_placeholder("Search...")
local clear_button = self.druid:new_button("clear_button", function()
search_input:clear()
search_input:set_focus()
end)
-- Create an input with selection handling
local editor_input = self.druid:new_rich_input("editor_bg", "editor_text")
editor_input.on_selection_change:subscribe(function(self, start, end_pos)
if start ~= end_pos then
-- Text is selected
show_formatting_toolbar()
else
-- No selection
hide_formatting_toolbar()
end
end)
-- Format selected text
function format_bold()
local start, end_pos = editor_input:get_selection()
if start ~= end_pos then
local text = editor_input:get_text()
local selected_text = text:sub(start, end_pos)
local new_text = text:sub(1, start-1) .. "**" .. selected_text .. "**" .. text:sub(end_pos+1)
editor_input:set_text(new_text)
editor_input:set_selection(start, end_pos + 4) -- Adjust selection to include formatting
end
end
```
## Notes
- The Rich Input component extends the basic Input component with enhanced selection and cursor capabilities
- The placeholder text is shown when the input is empty and doesn't have focus
- Text selection can be done via mouse/touch drag or programmatically
- The component handles cursor positioning and blinking
- Input validation can be used to restrict what characters users can enter
- For multiline input, the component supports line breaks and scrolling
- The component provides events for all major input interactions, allowing you to create responsive forms
- Selection and cursor position are reported in character indices, not pixel positions
- The component handles clipboard operations (copy, cut, paste) on supported platforms
- For best user experience, consider providing visual feedback for selection and cursor position

View File

@ -1,15 +0,0 @@
## Rich Text Quick API reference
```lua
rich_text:characters(word)
rich_text:clear()
rich_text:get_line_metric()
rich_text:get_text()
rich_text:get_words()
rich_text:init(text_node, [value])
rich_text:on_layout_change()
rich_text:on_remove()
rich_text:on_style_change(style)
rich_text:set_text([text])
rich_text:tagged(tag)
```

View File

@ -1,129 +0,0 @@
# Druid Rich Text Component
## Description
The Rich Text component extends the basic Text component to provide advanced text formatting capabilities. It allows you to display text with different styles, colors, and formatting within the same text node, using HTML-like markup tags.
## Features
- Inline text styling and formatting
- Support for different colors within text
- Font size variations within text
- Shadow and outline text effects
- Image insertion within text
- Line break control
- Custom tag support for advanced formatting
## Basic Usage
```lua
-- Create a basic rich text component
local rich_text = self.druid:new_rich_text("text_node")
-- Set text with formatting
rich_text:set_text("Hello <color=red>World</color>!")
```
### Parameters
- **node**: The node or node_id of the text node
## Rich Text Markup
The component uses HTML-like tags for formatting:
```l
<color=[#]HEX_VALUE>Colored text</color>
<color=COLOR_NAME>Colored text</color>
<shadow=[#]HEX_VALUE>Text with shadow</shadow>
<outline=[#]HEX_VALUE>Text with outline</outline>
<font=FONT_PATH>Text with custom font</font>
<size=NUMBER>Sized text</size>
<br/>Line break
<nobr>No line break zone</nobr>
<img=TEXTURE_ID[:ANIM_ID][,WIDTH][,HEIGHT]/>
```
## Methods
```lua
-- Set rich text content
rich_text:set_text("Hello <color=red>World</color>!")
-- Get current text (with markup)
local text = rich_text:get_text()
-- Get text without markup
local plain_text = rich_text:get_plain_text()
-- Set default text color
rich_text:set_default_color(vmath.vector4(1, 1, 1, 1))
-- Register a custom tag handler
rich_text:register_tag("shake", function(params, settings, style)
-- Custom tag implementation
-- Modify settings table based on params
end)
-- Clear all text
rich_text:clear()
```
## Events
```lua
-- Subscribe to text change event
rich_text.on_text_change:subscribe(function(self, text)
print("Rich text changed to: " .. text)
end)
```
## Examples
```lua
-- Create a rich text with multiple formatting styles
local rich_text = self.druid:new_rich_text("text_node")
rich_text:set_text("Welcome to Druid! This is a <color=red>rich</color> <color=green>text</color> <color=blue>component</color>.")
-- Create text with custom font and size
local title_text = self.druid:new_rich_text("title_node")
title_text:set_text("<font=fonts/title.font><size=2>GAME TITLE</size></font>")
-- Create text with shadow and outline effects
local effect_text = self.druid:new_rich_text("effect_node")
effect_text:set_text("<shadow=black><outline=white>Stylized Text</outline></shadow>")
-- Create text with embedded images
local info_text = self.druid:new_rich_text("info_text")
info_text:set_text("Your character: <img=hero_avatar,48,48/> Level <color=yellow>5</color><br/>HP: <color=red>75</color>/100<br/>MP: <color=blue>30</color>/50")
-- Create text with custom tag
local custom_text = self.druid:new_rich_text("custom_text")
custom_text:register_tag("pulse", function(params, settings, style)
-- Implementation of pulsing effect
settings.pulse = true
settings.pulse_speed = tonumber(params) or 1
end)
custom_text:set_text("This is a <pulse=1.5>pulsing</pulse> text!")
```
## Color Names
The component supports predefined color names that can be used instead of hex values:
```lua
-- Example of using named colors
rich_text:set_text("<color=aqua>Aqua</color> <color=red>Red</color> <color=lime>Lime</color>")
```
## Notes
- The Rich Text component is based on Britzl's defold-richtext library (version 5.19.0) with modifications
- The markup tags are processed at render time and converted to appropriate visual representations
- For complex formatting needs, you can register custom tags with specialized rendering logic
- When using images within text, you can specify width and height parameters
- The component supports nested tags for combined formatting effects
- For performance reasons, avoid extremely complex formatting in text that changes frequently
- The component handles tag escaping, so you can display tag-like syntax by escaping the brackets
- Rich text parsing may have a small performance impact compared to regular text rendering
- You can define custom colors in the style settings to use them by name in your markup

View File

@ -1,26 +0,0 @@
# Container Quick API reference
```lua
container:add_container(node_or_container, [mode], [on_resize_callback])
container:clear_draggable_corners()
container:fit_into_size(target_size)
container:fit_into_window()
container:get_position()
container:get_scale()
container:get_size()
container:init(node, [mode], [callback])
container:on_late_init()
container:on_remove()
container:on_style_change(style)
container:on_window_resized()
container:refresh()
container:refresh_origins()
container:set_draggable_corners([is_draggable])
container:set_min_size([min_size_x], [min_size_y])
container:set_node_fill([fill_x], [fill_y])
container:set_node_offset([offset])
container:set_parent_container([container])
container:set_pivot(pivot)
container:set_position(pos_x, pos_y)
container:set_size([width], [height], [anchor_pivot])
container:update_child_containers()

View File

@ -1,165 +0,0 @@
# Druid Container Component
## Description
The Container component provides a way to group and manage multiple UI elements as a single entity. It allows you to show, hide, enable, or disable a collection of nodes together, and provides events for container state changes.
## Features
- Group multiple nodes under a single container
- Show/hide all container nodes together
- Enable/disable all container nodes together
- Animation support for transitions
- Events for container state changes
- Optional animation callbacks
## Basic Usage
```lua
-- Create a container with a single node
local container = self.druid:new_container("container_node")
-- Create a container with multiple nodes
local container = self.druid:new_container({"node1", "node2", "node3"})
```
### Parameters
- **nodes**: A node, node_id, or array of nodes/node_ids to include in the container
## Methods
```lua
-- Add nodes to the container
container:add("new_node")
container:add({"node4", "node5"})
-- Remove nodes from the container
container:remove("node1")
container:remove({"node2", "node3"})
-- Show the container (all nodes)
container:show()
-- Hide the container (all nodes)
container:hide()
-- Show with animation
container:show(function(self)
-- Animation complete callback
print("Container shown")
end)
-- Hide with animation
container:hide(function(self)
-- Animation complete callback
print("Container hidden")
end)
-- Enable the container (all nodes)
container:set_enabled(true)
-- Disable the container (all nodes)
container:set_enabled(false)
-- Check if container is visible
local is_visible = container:is_visible()
-- Check if container is enabled
local is_enabled = container:is_enabled()
```
## Events
```lua
-- Subscribe to visibility change event
container.on_visibility_changed:subscribe(function(self, is_visible)
print("Container visibility changed to: " .. tostring(is_visible))
end)
-- Subscribe to enabled state change event
container.on_enabled_changed:subscribe(function(self, is_enabled)
print("Container enabled state changed to: " .. tostring(is_enabled))
end)
```
## Animation
The container component supports custom animations for show and hide operations:
```lua
-- Set custom show animation
container:set_show_animation(function(self, callback)
-- Animate container nodes
for _, node in ipairs(self.nodes) do
gui.animate(node, "color.w", 1, gui.EASING_OUTSINE, 0.5, 0, callback)
end
end)
-- Set custom hide animation
container:set_hide_animation(function(self, callback)
-- Animate container nodes
for _, node in ipairs(self.nodes) do
gui.animate(node, "color.w", 0, gui.EASING_OUTSINE, 0.5, 0, callback)
end
end)
```
## Examples
```lua
-- Create a panel container with multiple elements
local panel = self.druid:new_container({
"panel_bg",
"panel_title",
"panel_content",
"close_button"
})
-- Set custom show animation
panel:set_show_animation(function(self, callback)
local bg = gui.get_node("panel_bg")
local content = gui.get_node("panel_content")
-- Animate background
gui.set_scale(bg, vmath.vector3(0.8, 0.8, 1))
gui.animate(bg, "scale", vmath.vector3(1, 1, 1), gui.EASING_OUTBACK, 0.4)
-- Animate content
gui.set_alpha(content, 0)
gui.animate(content, "color.w", 1, gui.EASING_OUTSINE, 0.3, 0.1, callback)
end)
-- Show the panel with animation
panel:show(function()
print("Panel animation completed")
end)
-- Create a tab system with multiple containers
local tab1 = self.druid:new_container("tab1_content")
local tab2 = self.druid:new_container("tab2_content")
local tab3 = self.druid:new_container("tab3_content")
local function switch_to_tab(tab_index)
tab1:hide()
tab2:hide()
tab3:hide()
if tab_index == 1 then tab1:show() end
if tab_index == 2 then tab2:show() end
if tab_index == 3 then tab3:show() end
end
-- Switch to tab 1
switch_to_tab(1)
```
## Notes
- The container component does not create or delete nodes, it only manages their visibility and enabled state
- When a container is hidden, all its nodes are disabled by default to prevent input
- You can customize the show and hide animations to create smooth transitions
- Containers are useful for organizing UI elements into logical groups like panels, windows, or tabs
- The container component respects the node's initial state when it's added to the container
- You can nest containers to create complex UI hierarchies
- The container component is often used with other components like buttons, texts, and layouts to create complete UI panels

View File

@ -1,16 +0,0 @@
# Data List Quick API reference
```lua
data_list:add(data, [index], [shift_policy])
data_list:clear()
data_list:get_created_components()
data_list:get_created_nodes()
data_list:get_data()
data_list:get_index(data)
data_list:init(scroll, grid, create_function)
data_list:on_remove()
data_list:remove([index], [shift_policy])
data_list:remove_by_data(data, [shift_policy])
data_list:scroll_to_index(index)
data_list:set_data(data)
data_list:set_use_cache(is_use_cache)

View File

@ -1,148 +0,0 @@
# Druid Data List Component
## Description
The Data List component provides an efficient way to display and manage large collections of data in a scrollable list. It creates and reuses a limited number of visual items to represent potentially unlimited data, optimizing performance for large datasets.
## Features
- Efficient display of large data collections
- Item recycling for optimal performance
- Integration with Grid and Scroll components
- Support for different item visual representations
- Dynamic data updates
- Customizable item creation and binding
## Basic Usage
```lua
-- Create a data list with a grid
local grid = self.druid:new_grid("grid_node", "item_prefab", 1)
local scroll = self.druid:new_scroll("view_node", "content_node")
scroll:bind_grid(grid)
-- Create a data list with the grid
local data_list = self.druid:new_data_list(grid, function(self, data, index, node)
-- Bind data to visual item
local text_node = gui.get_node(node .. "/text")
gui.set_text(text_node, data.text)
end)
-- Set data to the list
local data = {
{ text = "Item 1" },
{ text = "Item 2" },
{ text = "Item 3" },
-- ... more items
}
data_list:set_data(data)
```
### Parameters
- **grid**: The grid component to use for item layout
- **bind_function**: Function to bind data to visual items with parameters (self, data, index, node)
## Methods
```lua
-- Set data to the list
data_list:set_data(data_array)
-- Get current data
local data = data_list:get_data()
-- Update specific data item
data_list:update_item(5, { text = "Updated Item 5" })
-- Add new items to the list
data_list:add(new_data_array)
-- Remove items from the list
data_list:remove(5) -- Remove item at index 5
data_list:remove(5, 3) -- Remove 3 items starting from index 5
-- Clear all data
data_list:clear()
-- Get visual item node by data index
local node = data_list:get_node_by_index(10)
-- Get data index by visual item node
local index = data_list:get_index_by_node(node)
-- Set in-flight items (number of items created beyond visible area)
data_list:set_in_flight(2)
```
## Events
```lua
-- Subscribe to data changes
data_list.on_data_changed:subscribe(function(self)
print("Data list data changed")
end)
-- Subscribe to item creation
data_list.on_create_item:subscribe(function(self, node, index, data)
print("Created item at index: " .. index)
end)
-- Subscribe to item removal
data_list.on_remove_item:subscribe(function(self, node, index)
print("Removed item at index: " .. index)
end)
-- Subscribe to item binding
data_list.on_bind_item:subscribe(function(self, node, index, data)
print("Bound data to item at index: " .. index)
end)
```
## Examples
```lua
-- Create a data list with custom item creation
local grid = self.druid:new_grid("grid_node", "item_prefab", 1)
local scroll = self.druid:new_scroll("view_node", "content_node")
scroll:bind_grid(grid)
local data_list = self.druid:new_data_list(grid, function(self, data, index, node)
-- Bind data to visual item
local text_node = gui.get_node(node .. "/text")
local icon_node = gui.get_node(node .. "/icon")
gui.set_text(text_node, data.title)
gui.set_texture(icon_node, data.icon_texture)
-- Set up item interaction
local button = self.druid:new_button(node, function()
print("Clicked on item: " .. data.title)
end)
end)
-- Set data with different item types
local data = {
{ title = "Item 1", icon_texture = "icon1" },
{ title = "Item 2", icon_texture = "icon2" },
{ title = "Item 3", icon_texture = "icon3" },
}
data_list:set_data(data)
-- Add new items dynamically
function add_new_item()
data_list:add({ { title = "New Item", icon_texture = "new_icon" } })
end
```
## Notes
- The Data List component requires a Grid component for layout and typically a Scroll component for scrolling
- It creates only enough visual items to fill the visible area plus a few extra for smooth scrolling
- As the user scrolls, the component reuses existing items and rebinds them with new data
- This approach is much more efficient than creating one visual item per data entry
- The bind function is called whenever an item needs to be updated with data
- You can customize the appearance and behavior of each item in the bind function
- The component supports dynamic data updates, allowing you to add, remove, or modify items at runtime
- For best performance, keep your bind function efficient and avoid expensive operations
- The in-flight parameter controls how many extra items are created beyond the visible area

View File

@ -1,10 +0,0 @@
# Hotkey Quick API reference
```lua
hotkey:add_hotkey(keys, [callback_argument])
hotkey:init(keys, callback, [callback_argument])
hotkey:is_processing()
hotkey:on_focus_gained()
hotkey:on_input([action_id], [action])
hotkey:on_style_change(style)
hotkey:set_repeat(is_enabled_repeated)

View File

@ -1,132 +0,0 @@
# Druid Hotkey Component
## Description
The Hotkey component provides a way to handle keyboard shortcuts in your UI. It allows you to define specific key combinations that trigger actions, making your UI more accessible and efficient for keyboard users.
## Features
- Support for single key and key combination shortcuts
- Customizable callback functions
- Optional key modifiers (shift, ctrl, alt)
- Ability to enable/disable hotkeys
- Events for hotkey triggers
## Basic Usage
```lua
-- Create a hotkey for the 'Enter' key
local hotkey = self.druid:new_hotkey("key_enter", function(self)
-- Handle Enter key press
print("Enter key pressed!")
end)
-- Create a hotkey with modifiers (Ctrl+S)
local save_hotkey = self.druid:new_hotkey({
key = "key_s",
modifier = "key_ctrl"
}, function(self)
-- Handle Ctrl+S key combination
print("Ctrl+S pressed - saving...")
end)
```
### Parameters
- **key_trigger**: The key or key combination to trigger the hotkey
- Can be a string for a single key (e.g., "key_enter")
- Can be a table for key combinations (e.g., {key = "key_s", modifier = "key_ctrl"})
- **callback**: (optional) Function to call when the hotkey is triggered
## Methods
```lua
-- Enable the hotkey
hotkey:set_enabled(true)
-- Disable the hotkey
hotkey:set_enabled(false)
-- Check if hotkey is enabled
local is_enabled = hotkey:is_enabled()
-- Trigger the hotkey programmatically
hotkey:trigger()
```
## Events
```lua
-- Subscribe to hotkey trigger event
hotkey.on_pressed:subscribe(function(self)
print("Hotkey was triggered")
end)
```
## Key Combinations
The component supports various key combinations:
```lua
-- Single key
local hotkey1 = self.druid:new_hotkey("key_space", callback)
-- Key with modifier
local hotkey2 = self.druid:new_hotkey({
key = "key_s",
modifier = "key_ctrl"
}, callback)
-- Key with multiple modifiers
local hotkey3 = self.druid:new_hotkey({
key = "key_s",
modifier = {"key_ctrl", "key_shift"}
}, callback)
```
## Examples
```lua
-- Create navigation hotkeys
local next_hotkey = self.druid:new_hotkey("key_right", function()
navigate_to_next_page()
end)
local prev_hotkey = self.druid:new_hotkey("key_left", function()
navigate_to_previous_page()
end)
-- Create application shortcuts
local save_hotkey = self.druid:new_hotkey({
key = "key_s",
modifier = "key_ctrl"
}, function()
save_document()
end)
local undo_hotkey = self.druid:new_hotkey({
key = "key_z",
modifier = "key_ctrl"
}, function()
undo_last_action()
end)
-- Create a help dialog hotkey
local help_hotkey = self.druid:new_hotkey("key_f1", function()
show_help_dialog()
end)
```
## Notes
- The Hotkey component requires proper key triggers setup in your `input.binding` file
- Hotkeys are global by default and will trigger regardless of UI focus
- You can enable/disable hotkeys based on context (e.g., disable certain hotkeys when a dialog is open)
- Key names should match the action IDs defined in your input bindings
- Common key names include:
- Navigation: "key_up", "key_down", "key_left", "key_right"
- Modifiers: "key_ctrl", "key_shift", "key_alt"
- Function keys: "key_f1", "key_f2", etc.
- Special keys: "key_enter", "key_space", "key_escape", "key_backspace"
- The component handles both key press and key release events
- Hotkeys are a great way to improve accessibility and user experience for keyboard users

View File

@ -1,23 +0,0 @@
# Input Quick API reference
```lua
input:get_text()
input:get_text_selected()
input:get_text_selected_replaced(text)
input:init(click_node, text_node, [keyboard_type])
input:is_empty()
input:is_full()
input:is_selected()
input:on_focus_lost()
input:on_input([action_id], [action])
input:on_input_interrupt()
input:on_style_change(style)
input:select()
input:select_cursor([index])
input:set_allowed_characters([pattern])
input:set_keyboard_type([keyboard_type])
input:set_marked_text([text])
input:set_max_length([length])
input:set_text([text])
input:unselect()
```

View File

@ -1,185 +0,0 @@
# Druid Input Component
## Description
The Input component provides a way to handle text input in your UI. It allows users to enter and edit text, with support for various input features like text selection, cursor positioning, and input validation.
## Features
- Text input handling with cursor support
- Text selection capabilities
- Input validation and filtering
- Maximum length restriction
- Password mode with character masking
- Events for text changes and interactions
- Support for multiline input
- Customizable visual feedback
## Basic Usage
```lua
-- Create a basic text input
local input = self.druid:new_input("input_node", "input_text_node")
-- Set initial text
input:set_text("Initial text")
```
### Parameters
- **node**: The node or node_id of the input background
- **text_node**: The node or node_id of the text component
- **keyboard_type**: (optional) The type of keyboard to show on mobile devices
## Methods
```lua
-- Set input text
input:set_text("New text")
-- Get current text
local text = input:get_text()
-- Clear input
input:clear()
-- Set maximum text length
input:set_max_length(50)
-- Set input validation pattern
input:set_allowed_characters("[%w%s]") -- Only alphanumeric and spaces
-- Enable/disable password mode
input:set_password(true) -- Enable password mode
input:set_password(false) -- Disable password mode
-- Set password character
input:set_password_char("*")
-- Set placeholder text (shown when input is empty)
input:set_placeholder("Enter text here...")
-- Set placeholder color
input:set_placeholder_color(vmath.vector4(0.5, 0.5, 0.5, 1))
-- Enable/disable multiline input
input:set_multiline(true)
input:set_multiline(false)
-- Enable/disable the input
input:set_enabled(true)
input:set_enabled(false)
-- Check if input is enabled
local is_enabled = input:is_enabled()
-- Set input focus
input:set_focus()
-- Remove input focus
input:remove_focus()
-- Check if input has focus
local has_focus = input:is_focused()
-- Select all text
input:select_all()
-- Set cursor position
input:set_cursor_position(5)
```
## Events
```lua
-- Subscribe to text change event
input.on_input_text:subscribe(function(self, text)
print("Text changed to: " .. text)
end)
-- Subscribe to focus events
input.on_focus:subscribe(function(self)
print("Input gained focus")
end)
input.on_focus_lost:subscribe(function(self)
print("Input lost focus")
end)
-- Subscribe to input submit event (Enter key)
input.on_submit:subscribe(function(self)
print("Input submitted with text: " .. self:get_text())
end)
-- Subscribe to input canceled event (Escape key)
input.on_cancel:subscribe(function(self)
print("Input canceled")
end)
```
## Examples
```lua
-- Create a username input with validation
local username_input = self.druid:new_input("username_bg", "username_text")
username_input:set_placeholder("Username")
username_input:set_allowed_characters("[%w_]") -- Only alphanumeric and underscore
username_input:set_max_length(20)
-- Create a password input
local password_input = self.druid:new_input("password_bg", "password_text")
password_input:set_placeholder("Password")
password_input:set_password(true)
password_input:set_password_char("•")
-- Create a multiline text area
local text_area = self.druid:new_input("textarea_bg", "textarea_text")
text_area:set_multiline(true)
text_area:set_placeholder("Enter your message here...")
-- Create a numeric input for age
local age_input = self.druid:new_input("age_bg", "age_text")
age_input:set_allowed_characters("%d") -- Only digits
age_input:set_max_length(3)
age_input:set_keyboard_type(gui.KEYBOARD_TYPE_NUMBER_PAD)
-- Create a form with multiple inputs and validation
local email_input = self.druid:new_input("email_bg", "email_text")
email_input:set_placeholder("Email")
local function validate_form()
local email = email_input:get_text()
local password = password_input:get_text()
-- Simple email validation
if not email:match("^[%w%.]+@[%w%.]+%.%w+$") then
print("Invalid email format")
return false
end
if #password < 8 then
print("Password must be at least 8 characters")
return false
end
return true
end
local submit_button = self.druid:new_button("submit_button", function()
if validate_form() then
print("Form submitted successfully")
end
end)
```
## Notes
- The Input component requires proper key triggers setup in your `input.binding` file
- On mobile platforms, the component will show the appropriate keyboard based on the keyboard_type parameter
- The component handles text selection, cursor positioning, and clipboard operations
- You can customize the visual appearance of the input, including text color, selection color, and cursor
- Input validation can be used to restrict what characters users can enter
- The placeholder text is shown when the input is empty and doesn't have focus
- For multiline input, the component supports line breaks and scrolling
- The component provides events for all major input interactions, allowing you to create responsive forms
- Password mode masks the entered text with the specified character for security

View File

@ -1,9 +0,0 @@
# Lang Text Quick API reference
```lua
lang_text:format(...)
lang_text:init(node, [locale_id], [adjust_type])
lang_text:on_language_change()
lang_text:set_text(text)
lang_text:set_to(text)
lang_text:translate(locale_id, ...)

View File

@ -1,127 +0,0 @@
# Druid Lang Text Component
## Description
The Lang Text component extends the basic Text component to provide localization support. It automatically updates the text when the game language changes, making it easy to create multilingual UIs.
## Features
- Automatic text localization
- Support for text parameters and formatting
- Updates automatically when language changes
- Inherits all Text component features
- Support for fallback languages
## Basic Usage
```lua
-- Create a basic localized text
local lang_text = self.druid:new_lang_text("text_node", "ui.welcome_message")
```
### Parameters
- **node**: The node or node_id of the text node
- **locale_id**: The localization key to use for this text
- **params**: (optional) Parameters to format into the localized string
## Methods
```lua
-- Set the localization key
lang_text:set_locale_id("ui.new_message")
-- Set parameters for text formatting
lang_text:set_params({name = "Player", score = 100})
-- Update the text with current locale and parameters
lang_text:update_text()
-- Get the current locale ID
local locale_id = lang_text:get_locale_id()
-- Get the current parameters
local params = lang_text:get_params()
-- Set a specific language for this text (overrides global language)
lang_text:set_language("en")
-- Reset to use the global language
lang_text:reset_language()
```
## Inheritance from Text Component
The Lang Text component inherits all methods and properties from the basic Text component, including:
```lua
-- Set text color
lang_text:set_color(vmath.vector4(1, 0, 0, 1))
-- Set text scale
lang_text:set_scale(1.5)
-- Set text pivot
lang_text:set_pivot(gui.PIVOT_CENTER)
-- Set text adjustment
lang_text:set_text_adjust(druid.const.TEXT_ADJUST.DOWNSCALE)
```
## Examples
```lua
-- Create a welcome message with player name
local welcome_text = self.druid:new_lang_text("welcome_text", "ui.welcome", {name = "Player"})
-- Update player name
function update_player_name(new_name)
welcome_text:set_params({name = new_name})
end
-- Create a score display with formatting
local score_text = self.druid:new_lang_text("score_text", "ui.score", {score = 0})
-- Update score
function update_score(new_score)
score_text:set_params({score = new_score})
end
-- Create a text with language override
local hint_text = self.druid:new_lang_text("hint_text", "ui.hint")
hint_text:set_language("en") -- Always show hint in English regardless of game language
```
## Localization Format
The Lang Text component works with the localization system to retrieve strings based on locale IDs. The localization format typically looks like:
```lua
-- In your localization files
local localization = {
en = {
ui = {
welcome = "Welcome, {name}!",
score = "Score: {score}",
hint = "Press Space to continue"
}
},
fr = {
ui = {
welcome = "Bienvenue, {name}!",
score = "Score: {score}",
hint = "Appuyez sur Espace pour continuer"
}
}
}
```
## Notes
- The Lang Text component requires a properly set up localization system
- The component automatically updates when the game language changes
- You can use parameters in your localized strings with {param_name} syntax
- The component inherits all features from the basic Text component
- You can override the language for specific texts, which is useful for debugging or for text that should always appear in a specific language
- The component works with the Druid localization system, which supports fallback languages
- For complex formatting, you can use custom format functions in your localization system

View File

@ -1,18 +0,0 @@
# Layout Quick API reference
```lua
layout:add(node_or_node_id)
layout:get_content_size()
layout:get_entities()
layout:get_size()
layout:init(node_or_node_id, layout_type)
layout:refresh_layout()
layout:remove(node_or_node_id)
layout:set_dirty()
layout:set_hug_content(is_hug_width, is_hug_height)
layout:set_justify(is_justify)
layout:set_margin([margin_x], [margin_y])
layout:set_node_index(node, index)
layout:set_padding([padding_x], [padding_y], [padding_z], [padding_w])
layout:set_type(type)
layout:update()

View File

@ -1,98 +0,0 @@
# Druid Layout Component
## Description
The Layout component provides automatic positioning and sizing of UI elements based on predefined layout rules. It helps create responsive UIs that adapt to different screen sizes and orientations.
## Features
- Automatic positioning of nodes based on layout rules
- Support for different layout types (static, dynamic, fixed)
- Anchoring nodes to different parts of the screen
- Automatic adjustment when screen size changes
- Pivot-based positioning
- Margin and padding support
## Basic Usage
```lua
local layout = self.druid:new_layout("layout_node")
```
### Parameters
- **node**: The node or node_id of the layout container
## Layout Types
The Layout component supports several layout types:
- **Static Layout**: Fixed position relative to parent
- **Dynamic Layout**: Position based on parent size and node anchor
- **Fixed Layout**: Position based on screen size and node anchor
## Methods
```lua
-- Set layout type
layout:set_static_layout() -- Fixed position relative to parent
layout:set_dynamic_layout() -- Position based on parent size
layout:set_fixed_layout() -- Position based on screen size
-- Update layout size
layout:set_size(width, height)
-- Set node anchor (position relative to parent)
layout:set_anchor(anchor_type)
-- Available anchor types: ANCHOR.CENTER, ANCHOR.TOP, ANCHOR.BOTTOM, etc.
-- Set node pivot (position relative to node itself)
layout:set_pivot(pivot_type)
-- Available pivot types: PIVOT.CENTER, PIVOT.N, PIVOT.S, etc.
-- Set margins (distance from anchor point)
layout:set_margin(left, top, right, bottom)
-- Set padding (internal spacing)
layout:set_padding(left, top, right, bottom)
-- Manually update layout
layout:update()
-- Reset to initial state
layout:reset()
```
## Events
```lua
-- Subscribe to layout changes
layout.on_layout_change:subscribe(function(self)
print("Layout changed")
end)
```
## Example
```lua
-- Create a layout that anchors to the top right of the screen
local layout = self.druid:new_layout("panel")
layout:set_fixed_layout()
layout:set_anchor(druid.const.ANCHOR.TOP_RIGHT)
layout:set_pivot(druid.const.PIVOT.NE)
layout:set_margin(0, 50, 50, 0) -- 50px from top, 50px from right
-- Create a dynamic layout that centers in its parent
local layout = self.druid:new_layout("content")
layout:set_dynamic_layout()
layout:set_anchor(druid.const.ANCHOR.CENTER)
layout:set_pivot(druid.const.PIVOT.CENTER)
```
## Notes
- The layout component automatically adjusts when the screen size changes
- You can nest layouts to create complex UI structures
- The layout component works well with other components like Grid and Scroll
- For responsive UIs, use fixed layouts for screen-anchored elements and dynamic layouts for elements that should adapt to their parent's size
- The layout component respects the node's initial position as an offset from the calculated position

View File

@ -1,16 +0,0 @@
# Progress Quick API reference
```lua
progress:empty()
progress:fill()
progress:get()
progress:init(node, key, [init_value])
progress:on_layout_change()
progress:on_remove()
progress:on_style_change(style)
progress:set_max_size(max_size)
progress:set_steps(steps, callback)
progress:set_to(to)
progress:to(to, [callback])
progress:update(dt)
```

View File

@ -1,111 +0,0 @@
# Druid Progress Component
## Description
The Progress component provides a way to visualize progress or completion status through various visual representations. It can be used to create progress bars, loading indicators, or any UI element that needs to display a value within a range.
## Features
- Visual representation of progress values
- Support for different visual styles (bar, radial, etc.)
- Customizable value range
- Smooth value transitions with animations
- Events for progress changes
- Support for fill nodes, size nodes, and slice nodes
## Basic Usage
```lua
-- Basic progress bar with a fill node
local progress = self.druid:new_progress("progress_node", druid.const.PROGRESS.FILL)
-- Set progress value (0 to 1)
progress:set_value(0.5) -- 50% progress
```
### Parameters
- **node**: The node or node_id of the progress container
- **mode**: (optional) The progress visualization mode (default: FILL)
- `druid.const.PROGRESS.FILL`: Changes the fill of the node
- `druid.const.PROGRESS.SIZE`: Changes the size of the node
- `druid.const.PROGRESS.SLICE`: Changes the slice of a pie node
## Methods
```lua
-- Set progress value (0 to 1)
progress:set_value(0.75) -- 75% progress
-- Set progress value with animation
progress:set_to(0.75, 0.5) -- Animate to 75% over 0.5 seconds
-- Get current progress value
local value = progress:get_value()
-- Set custom value range
progress:set_range(0, 100)
progress:set_value(50) -- 50% progress (value 50 in range 0-100)
-- Set key points for non-linear progress
progress:set_key_points({
{ value = 0, percent = 0 },
{ value = 50, percent = 0.25 }, -- 50 is 25% of visual progress
{ value = 100, percent = 1 }
})
-- Set fill target node (for FILL mode)
progress:set_fill_node("fill_node")
-- Set size target node (for SIZE mode)
progress:set_size_node("size_node")
-- Set slice target node (for SLICE mode)
progress:set_slice_node("slice_node")
-- Reset to initial state
progress:reset()
```
## Events
```lua
-- Subscribe to progress value changes
progress.on_change:subscribe(function(self, value)
print("Progress changed to: " .. value)
end)
-- Subscribe to progress completion
progress.on_complete:subscribe(function(self)
print("Progress completed!")
end)
```
## Examples
```lua
-- Create a horizontal progress bar
local progress = self.druid:new_progress("bar_node", druid.const.PROGRESS.SIZE)
progress:set_size_node("fill_node")
progress:set_value(0.5)
-- Create a radial progress indicator
local progress = self.druid:new_progress("pie_node", druid.const.PROGRESS.SLICE)
progress:set_slice_node("slice_node")
progress:set_value(0.75)
-- Create a progress bar with custom range
local progress = self.druid:new_progress("health_bar", druid.const.PROGRESS.FILL)
progress:set_range(0, 100)
progress:set_value(75) -- 75/100 = 75% progress
```
## Notes
- The progress component can be used with different visual representations based on the mode
- For FILL mode, the component changes the x or y fill of the target node
- For SIZE mode, the component changes the size of the target node
- For SLICE mode, the component changes the inner or outer bounds of a pie node
- You can create non-linear progress visualization using key points
- The progress component supports smooth animations between values
- The default value range is 0 to 1, but you can customize it for your specific needs

View File

@ -1,13 +0,0 @@
# Slider Quick API reference
```lua
slider:init(node, end_pos, [callback])
slider:is_enabled()
slider:on_input([action_id], [action])
slider:on_layout_change()
slider:on_remove()
slider:on_window_resized()
slider:set(value, [is_silent])
slider:set_enabled(is_enabled)
slider:set_input_node([input_node])
slider:set_steps(steps)

View File

@ -1,114 +0,0 @@
# Druid Slider Component
## Description
The Slider component provides an interactive way for users to select a value from a range by dragging a handle along a track. It's commonly used for settings like volume control, brightness adjustment, or any scenario where users need to select a value within a continuous range.
## Features
- Interactive value selection through dragging
- Customizable value range
- Support for horizontal and vertical orientations
- Smooth handle movement with animations
- Events for value changes and interactions
- Optional steps for discrete value selection
- Visual feedback through progress component integration
## Basic Usage
```lua
-- Basic horizontal slider
local slider = self.druid:new_slider("slider_node", "pin_node", vmath.vector3(1, 0, 0))
-- Set initial value (0 to 1)
slider:set_value(0.5) -- 50% of the slider range
```
### Parameters
- **node**: The node or node_id of the slider background/track
- **pin_node**: The node or node_id of the draggable handle/pin
- **axis**: The axis vector for the slider direction (e.g., vmath.vector3(1, 0, 0) for horizontal)
## Methods
```lua
-- Set slider value (0 to 1)
slider:set_value(0.75) -- 75% of the slider range
-- Set slider value with animation
slider:set_to(0.75, 0.5) -- Animate to 75% over 0.5 seconds
-- Get current slider value
local value = slider:get_value()
-- Set custom value range
slider:set_range(0, 100)
slider:set_value(50) -- 50% of the slider range (value 50 in range 0-100)
-- Set steps for discrete values
slider:set_steps(5) -- 5 steps: 0, 0.25, 0.5, 0.75, 1
-- Enable/disable the slider
slider:set_enabled(true)
slider:set_enabled(false)
-- Check if slider is enabled
local is_enabled = slider:is_enabled()
-- Set a progress component to visualize the slider value
local progress = self.druid:new_progress("progress_node")
slider:set_progress(progress)
-- Reset to initial state
slider:reset()
```
## Events
```lua
-- Subscribe to value changes
slider.on_change:subscribe(function(self, value)
print("Slider value changed to: " .. value)
end)
-- Subscribe to drag start event
slider.on_drag_start:subscribe(function(self)
print("Started dragging slider")
end)
-- Subscribe to drag end event
slider.on_drag_end:subscribe(function(self)
print("Stopped dragging slider")
end)
```
## Examples
```lua
-- Create a horizontal slider with steps
local slider = self.druid:new_slider("slider_bg", "slider_pin", vmath.vector3(1, 0, 0))
slider:set_steps(10) -- 10 discrete steps
slider:set_value(0.3)
-- Create a vertical slider with custom range
local slider = self.druid:new_slider("volume_bg", "volume_pin", vmath.vector3(0, 1, 0))
slider:set_range(0, 100)
slider:set_value(75) -- 75/100 = 75% of the slider
-- Create a slider with visual progress feedback
local slider = self.druid:new_slider("slider_bg", "slider_pin", vmath.vector3(1, 0, 0))
local progress = self.druid:new_progress("progress_fill")
slider:set_progress(progress)
slider:set_value(0.5)
```
## Notes
- The slider component calculates the handle position based on the background node size and the specified axis
- For horizontal sliders, use axis vector (1, 0, 0); for vertical sliders, use (0, 1, 0)
- The slider component automatically adjusts the handle position when the value changes
- When using steps, the slider will snap to the nearest step value
- You can integrate a progress component to provide visual feedback of the current value
- The slider's drag behavior respects the bounds of the background node
- The default value range is 0 to 1, but you can customize it for your specific needs

View File

@ -1,9 +0,0 @@
# Swipe Quick API reference
```lua
swipe:init(node_or_node_id, on_swipe_callback)
swipe:on_input([action_id], [action])
swipe:on_input_interrupt()
swipe:on_late_init()
swipe:on_style_change(style)
swipe:set_click_zone([zone])

View File

@ -1,136 +0,0 @@
# Druid Swipe Component
## Description
The Swipe component detects swipe gestures on a specified node or across the entire screen. It provides information about swipe direction, speed, and distance, allowing you to implement gesture-based interactions in your UI.
## Features
- Detection of swipe gestures in 8 directions
- Customizable swipe sensitivity and threshold
- Information about swipe speed and distance
- Support for both touch and mouse input
- Optional click zone restriction
- Events for swipe detection
## Basic Usage
```lua
-- Basic swipe detection across the entire screen
local swipe = self.druid:new_swipe(function(self, swipe_info)
-- Handle swipe action
print("Swipe detected in direction: " .. swipe_info.direction)
end)
-- Swipe detection on a specific node
local swipe = self.druid:new_swipe(function(self, swipe_info)
-- Handle swipe action
print("Swipe detected in direction: " .. swipe_info.direction)
end, "swipe_area_node")
```
### Parameters
- **callback**: (optional) Function to call when a swipe is detected
- **node**: (optional) The node or node_id to detect swipes on (default: entire screen)
## Swipe Info
The swipe callback provides a `swipe_info` table with the following information:
```lua
{
direction = druid.const.SWIPE.RIGHT, -- Direction constant
distance = 150, -- Distance in pixels
time = 0.2, -- Time taken for the swipe in seconds
speed = 750, -- Speed in pixels per second
x = 150, -- X distance
y = 0, -- Y distance
touch = hash("touch") -- Touch that triggered the swipe
}
```
## Methods
```lua
-- Set minimum swipe distance threshold
swipe:set_minimum_distance(50)
-- Set maximum swipe time threshold
swipe:set_maximum_time(0.5)
-- Set a click zone to restrict swipe area
swipe:set_click_zone("stencil_node")
-- Enable or disable swipe detection
swipe:set_enabled(true)
swipe:set_enabled(false)
-- Check if swipe detection is enabled
local is_enabled = swipe:is_enabled()
```
## Events
```lua
-- Subscribe to swipe event
swipe.on_swipe:subscribe(function(self, swipe_info)
print("Swipe detected in direction: " .. swipe_info.direction)
print("Swipe distance: " .. swipe_info.distance)
print("Swipe speed: " .. swipe_info.speed)
end)
```
## Swipe Directions
The component provides constants for swipe directions:
```lua
druid.const.SWIPE = {
UP = "up",
DOWN = "down",
LEFT = "left",
RIGHT = "right",
UP_LEFT = "up_left",
UP_RIGHT = "up_right",
DOWN_LEFT = "down_left",
DOWN_RIGHT = "down_right"
}
```
## Examples
```lua
-- Create a swipe detector with custom thresholds
local swipe = self.druid:new_swipe(function(self, swipe_info)
if swipe_info.direction == druid.const.SWIPE.LEFT then
-- Handle left swipe
print("Left swipe detected")
elseif swipe_info.direction == druid.const.SWIPE.RIGHT then
-- Handle right swipe
print("Right swipe detected")
end
end)
swipe:set_minimum_distance(100) -- Require at least 100px of movement
swipe:set_maximum_time(0.3) -- Must complete within 0.3 seconds
-- Create a swipe detector for a specific area
local swipe = self.druid:new_swipe(nil, "swipe_area")
swipe.on_swipe:subscribe(function(self, swipe_info)
if swipe_info.speed > 1000 then
print("Fast swipe detected!")
else
print("Slow swipe detected")
end
end)
```
## Notes
- The swipe component detects gestures based on both distance and time thresholds
- By default, a swipe must be at least 50 pixels in distance and completed within 0.4 seconds
- The component determines the direction based on the angle of the swipe
- You can restrict the swipe detection area by setting a click zone, which is useful for stencil nodes
- The swipe component automatically detects the closest stencil node and sets it as the click zone if none is specified
- Swipe detection works with both touch and mouse input
- The component provides detailed information about each swipe, allowing you to implement velocity-based interactions

View File

@ -1,10 +0,0 @@
# Timer Quick API reference
```lua
timer:init(node, [seconds_from], [seconds_to], [callback])
timer:on_layout_change()
timer:set_interval(from, to)
timer:set_state([is_on])
timer:set_to(set_to)
timer:update(dt)
```

View File

@ -1,125 +0,0 @@
# Druid Timer Component
## Description
The Timer component provides a way to create and manage countdown or countup timers in your UI. It can be used for game timers, cooldowns, or any feature that requires time tracking with visual feedback.
## Features
- Countdown and countup timer modes
- Customizable time format display
- Pause, resume, and reset functionality
- Events for timer updates and completion
- Optional text component integration for visual display
- Support for different time units (seconds, minutes, hours)
## Basic Usage
```lua
-- Basic countdown timer (10 seconds)
local timer = self.druid:new_timer(10, true)
-- Start the timer
timer:start()
```
### Parameters
- **time**: The initial time value in seconds
- **is_countdown**: (optional) Boolean indicating if this is a countdown timer (default: false)
## Methods
```lua
-- Start the timer
timer:start()
-- Pause the timer
timer:pause()
-- Resume a paused timer
timer:resume()
-- Reset the timer to its initial value
timer:reset()
-- Set a new time value
timer:set_time(30) -- Set to 30 seconds
-- Get current time value
local current_time = timer:get_time()
-- Check if timer is running
local is_running = timer:is_running()
-- Set a text component to display the timer
local text = self.druid:new_text("timer_text")
timer:set_text(text)
-- Set custom time format
timer:set_format(function(self, time)
local minutes = math.floor(time / 60)
local seconds = math.floor(time % 60)
return string.format("%02d:%02d", minutes, seconds)
end)
```
## Events
```lua
-- Subscribe to timer tick event (called every frame while timer is running)
timer.on_tick:subscribe(function(self, value)
print("Timer value: " .. value)
end)
-- Subscribe to timer completion event
timer.on_complete:subscribe(function(self)
print("Timer completed!")
end)
```
## Examples
```lua
-- Create a 5-minute countdown timer with text display
local timer = self.druid:new_timer(300, true) -- 300 seconds = 5 minutes
local text = self.druid:new_text("timer_text")
timer:set_text(text)
timer:set_format(function(self, time)
local minutes = math.floor(time / 60)
local seconds = math.floor(time % 60)
return string.format("%02d:%02d", minutes, seconds)
end)
timer:start()
-- Create a stopwatch (countup timer)
local stopwatch = self.druid:new_timer(0, false)
local text = self.druid:new_text("stopwatch_text")
stopwatch:set_text(text)
stopwatch:start()
-- Create a game round timer with events
local round_timer = self.druid:new_timer(60, true) -- 60 second round
round_timer.on_tick:subscribe(function(self, value)
if value <= 10 then
-- Last 10 seconds, show warning
print("Time is running out!")
end
end)
round_timer.on_complete:subscribe(function(self)
-- Round is over
print("Round completed!")
end)
round_timer:start()
```
## Notes
- The timer component updates every frame while running
- For countdown timers, the timer completes when it reaches 0
- For countup timers, you need to manually check for completion or set a target time
- The default time format is seconds with one decimal place (e.g., "10.0")
- You can customize the time format to display hours, minutes, seconds, or any other format
- The timer component can be paused, resumed, and reset at any time
- When using with a text component, the timer automatically updates the text display
- The timer value is in seconds, but you can convert it to other units in your format function

View File

@ -85,9 +85,9 @@ end
---Set normalized to control the color of the line
--- for index = 1, mini_graph:get_samples() do
--- mini_graph:set_line_value(index, math.random())
--- end
--- for index = 1, mini_graph:get_samples() do
--- mini_graph:set_line_value(index, math.random())
--- end
---@param index number
---@param value number The normalized value from 0 to 1
function M:set_line_value(index, value)