mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Start update docs
This commit is contained in:
parent
76ab3811fa
commit
99fc4ccc31
65
README.md
65
README.md
@ -96,14 +96,14 @@ Adjust **Druid** settings, if needed:
|
|||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
|
||||||
-- Used for button component and custom components
|
-- Used for button component and custom components
|
||||||
-- Callback should play sound by name
|
-- Callback should play sound by name: function(sound_id) ... end
|
||||||
druid.set_sound_function(callback)
|
druid.set_sound_function(callback)
|
||||||
|
|
||||||
-- Used for lang_text component
|
-- Used for lang_text component
|
||||||
-- Callback should return localized string by locale id
|
-- Callback should return localized string by locale id: function(locale_id) ... end
|
||||||
druid.set_text_function(callback)
|
druid.set_text_function(callback)
|
||||||
|
|
||||||
-- Used for change default druid style
|
-- Used for change default Druid style
|
||||||
druid.set_default_style(your_style)
|
druid.set_default_style(your_style)
|
||||||
|
|
||||||
-- Call this function on language changing in the game,
|
-- Call this function on language changing in the game,
|
||||||
@ -112,6 +112,7 @@ druid.on_language_change()
|
|||||||
|
|
||||||
-- Call this function inside window.set_listener
|
-- Call this function inside window.set_listener
|
||||||
-- to catch game focus lost/gained callbacks:
|
-- to catch game focus lost/gained callbacks:
|
||||||
|
-- window.set_listener(function(self, event, data) druid.on_window_callback(event, data) end))
|
||||||
druid.on_window_callback(event)
|
druid.on_window_callback(event)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -120,35 +121,41 @@ druid.on_window_callback(event)
|
|||||||
|
|
||||||
Here is full **Druid** components list:
|
Here is full **Druid** components list:
|
||||||
|
|
||||||
| Name | Description | API page | Example Link | Is Basic component[^1] | Preview |
|
### Basic Components
|
||||||
|------|-------------|----------|------------|-------------|---------|
|
|
||||||
| **[Button](docs_md/01-components.md#button)** | Basic input component. Handles all types of interactions: click, long click, hold click, double click, etc | [Button API](https://insality.github.io/druid/modules/Button.html) | [Button Example](https://insality.github.io/druid/druid/?example=general_buttons) | ✅ | <img src="media/preview/button.gif" width="200" height="100"> |
|
| Name | Description | API page | Example Link | Preview |
|
||||||
| **[Text](docs_md/01-components.md#text)** | Wrap on GUI text node, handle different text size adjusting, providing additional text API | [Text API](https://insality.github.io/druid/modules/Text.html) | [Text Example](https://insality.github.io/druid/druid/?example=texts_general) | ✅ | <img src="media/preview/text.gif" width="200" height="100"> |
|
|------|-------------|----------|--------------|---------|
|
||||||
| **[Scroll](docs_md/01-components.md#scroll)** | Scroll component | [Scroll API](https://insality.github.io/druid/modules/Scroll.html) | [Scroll Example](https://insality.github.io/druid/druid/?example=general_scroll) | ✅ | <img src="media/preview/scroll.gif" width="200" height="100"> |
|
| **[Button](docs_md/01-components.md#button)** | Basic input component. Handles all types of interactions: click, long click, hold click, double click, etc | [Button API](https://insality.github.io/druid/modules/Button.html) | [Button Example](https://insality.github.io/druid/druid/?example=general_buttons) | <img src="media/preview/button.gif" width="200" height="100"> |
|
||||||
| **[Blocker](docs_md/01-components.md#blocker)** | Block user input in node zone area | [Blocker API](https://insality.github.io/druid/modules/Blocker.html) | ❌ | ✅ | |
|
| **[Text](docs_md/01-components.md#text)** | Wrap on GUI text node, handle different text size adjusting, providing additional text API | [Text API](https://insality.github.io/druid/modules/Text.html) | [Text Example](https://insality.github.io/druid/druid/?example=texts_general) | <img src="media/preview/text.gif" width="200" height="100"> |
|
||||||
| **[Back Handler](docs_md/01-components.md#back-handler)** | Handle back button (Android back button, backspace key) | [Back Handler API](https://insality.github.io/druid/modules/BackHandler.html) | ❌ | ✅ | |
|
| **[Scroll](docs_md/01-components.md#scroll)** | Scroll component | [Scroll API](https://insality.github.io/druid/modules/Scroll.html) | [Scroll Example](https://insality.github.io/druid/druid/?example=general_scroll) | <img src="media/preview/scroll.gif" width="200" height="100"> |
|
||||||
| **[Static Grid](docs_md/01-components.md#static-grid)** | Component to manage node positions with equal sizes | [Static Grid API](https://insality.github.io/druid/modules/StaticGrid.html) | [Static Gid Example](https://insality.github.io/druid/druid/?example=general_grid) | ✅ | <img src="media/preview/static_grid.gif" width="200" height="100"> |
|
| **[Blocker](docs_md/01-components.md#blocker)** | Block user input in node zone area | [Blocker API](https://insality.github.io/druid/modules/Blocker.html) | ❌ | |
|
||||||
| **[Hover](docs_md/01-components.md#hover)** | Handle hover node state on node | [Hover API](https://insality.github.io/druid/modules/Hover.html) | ❌ | ✅ | <img src="media/preview/hover.gif" width="200" height="100"> |
|
| **[Back Handler](docs_md/01-components.md#back-handler)** | Handle back button (Android back button, backspace key) | [Back Handler API](https://insality.github.io/druid/modules/BackHandler.html) | ❌ | |
|
||||||
| **[Swipe](docs_md/01-components.md#swipe)** | Handle swipe gestures on node | [Swipe API](https://insality.github.io/druid/modules/Swipe.html) | [Swipe Example](https://insality.github.io/druid/druid/?example=general_swipe) | ✅ | <img src="media/preview/swipe.gif" width="200" height="100"> |
|
| **[Static Grid](docs_md/01-components.md#static-grid)** | Component to manage node positions with equal sizes | [Static Grid API](https://insality.github.io/druid/modules/StaticGrid.html) | [Static Gid Example](https://insality.github.io/druid/druid/?example=general_grid) | <img src="media/preview/static_grid.gif" width="200" height="100"> |
|
||||||
| **[Drag](docs_md/01-components.md#drag)** | Handle drag input on node | [Drag API](https://insality.github.io/druid/modules/Drag.html) | [Drag Example](https://insality.github.io/druid/druid/?example=general_drag) | ✅ | <img src="media/preview/drag.gif" width="200" height="100"> |
|
| **[Hover](docs_md/01-components.md#hover)** | Handle hover node state on node | [Hover API](https://insality.github.io/druid/modules/Hover.html) | ❌ | <img src="media/preview/hover.gif" width="200" height="100"> |
|
||||||
| **[Checkbox](docs_md/01-components.md#checkbox)** | Checkbox component | [Checkbox API](https://insality.github.io/druid/modules/Checkbox.html) | [Checkbox Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | ❌ | <img src="media/preview/checkbox.gif" width="200" height="100"> |
|
| **[Swipe](docs_md/01-components.md#swipe)** | Handle swipe gestures on node | [Swipe API](https://insality.github.io/druid/modules/Swipe.html) | [Swipe Example](https://insality.github.io/druid/druid/?example=general_swipe) | <img src="media/preview/swipe.gif" width="200" height="100"> |
|
||||||
| **[Checkbox group](docs_md/01-components.md#checkbox-group)** | Several checkboxes in one group | [Checkbox group API](https://insality.github.io/druid/modules/CheckboxGroup.html) | [Checkbox group Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | ❌ | <img src="media/preview/checkbox_group.gif" width="200" height="100"> |
|
| **[Drag](docs_md/01-components.md#drag)** | Handle drag input on node | [Drag API](https://insality.github.io/druid/modules/Drag.html) | [Drag Example](https://insality.github.io/druid/druid/?example=general_drag) | <img src="media/preview/drag.gif" width="200" height="100"> |
|
||||||
| **[Radio group](docs_md/01-components.md#radio-group)** | Several checkboxes in one group with a single choice | [Radio group API](https://insality.github.io/druid/modules/RadioGroup.html) | [Radio Group Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | ❌ | <img src="media/preview/radio_group.gif" width="200" height="100"> |
|
|
||||||
| **[Dynamic Grid](docs_md/01-components.md#dynamic-grid)** | Component to manage node positions with different sizes. Only in one row or column | [Dynamic Grid API](https://insality.github.io/druid/modules/DynamicGrid.html) | [Dynamic Grid Example](https://insality.github.io/druid/druid/?example=general_grid) | ❌ | <img src="media/preview/dynamic_grid.gif" width="200" height="100"> |
|
|
||||||
| **[Data List](docs_md/01-components.md#data-list)** | Component to manage data for huge datasets in scroll | [Data List API](https://insality.github.io/druid/modules/DataList.html) | [Data List Example](https://insality.github.io/druid/druid/?example=general_data_list) | ❌ | <img src="media/preview/data_list.gif" width="200" height="100"> |
|
### Extended components
|
||||||
| **[Input](docs_md/01-components.md#input)** | User text input component | [Input API](https://insality.github.io/druid/modules/Input.html) | [Input Example](https://insality.github.io/druid/druid/?example=general_input) | ❌ | <img src="media/preview/input.gif" width="200" height="100"> |
|
> Extended components before usage should be registered in **Druid** with `druid.register_component()` function.
|
||||||
| **[Lang text](docs_md/01-components.md#lang-text)** | Wrap on Text component to handle localization | [Lang Text API](https://insality.github.io/druid/modules/LangText.html) | ❌ | ❌ | <img src="media/preview/lang_text.gif" width="200" height="100"> |
|
|
||||||
| **[Progress](docs_md/01-components.md#progress)** | Progress bar component | [Progress API](https://insality.github.io/druid/modules/Progress.html) | [Progress Example](https://insality.github.io/druid/druid/?example=general_progress_bar) | ❌ | <img src="media/preview/progress.gif" width="200" height="100"> |
|
| Name | Description | API page | Example Link | Preview |
|
||||||
| **[Slider](docs_md/01-components.md#slider)** | Slider component | [Slider API](https://insality.github.io/druid/modules/Slider.html) | [Slider Example](https://insality.github.io/druid/druid/?example=general_sliders) | ❌ | <img src="media/preview/slider.gif" width="200" height="100"> |
|
|------|-------------|----------|--------------|---------|
|
||||||
| **[Timer](docs_md/01-components.md#timer)** | Handle timers on GUI text node | [Timer API](https://insality.github.io/druid/modules/Timer.html) | ❌ | ❌ | <img src="media/preview/timer.gif" width="200" height="100"> |
|
| **[Checkbox](docs_md/01-components.md#checkbox)** | Checkbox component | [Checkbox API](https://insality.github.io/druid/modules/Checkbox.html) | [Checkbox Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | <img src="media/preview/checkbox.gif" width="200" height="100"> |
|
||||||
| **[Hotkey](docs_md/01-components.md#hotkey)** | Handle keyboard hotkeys with key modificators | [Hotkey API](https://insality.github.io/druid/modules/Hotkey.html) | [Hotkey Example](https://insality.github.io/druid/druid/?example=general_hokey) | ❌ | <img src="media/preview/hotkey.gif" width="200" height="100"> |
|
| **[Checkbox group](docs_md/01-components.md#checkbox-group)** | Several checkboxes in one group | [Checkbox group API](https://insality.github.io/druid/modules/CheckboxGroup.html) | [Checkbox group Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | <img src="media/preview/checkbox_group.gif" width="200" height="100"> |
|
||||||
| **[Layout](docs_md/01-components.md#layout)** | Handle node size depends on layout mode and screen aspect ratio | [Layout API](https://insality.github.io/druid/modules/Layout.html) | [Layout Example](https://insality.github.io/druid/druid/?example=general_layout) | ❌ | <img src="media/preview/layout.gif" width="200" height="100"> |
|
| **[Radio group](docs_md/01-components.md#radio-group)** | Several checkboxes in one group with a single choice | [Radio group API](https://insality.github.io/druid/modules/RadioGroup.html) | [Radio Group Example](https://insality.github.io/druid/druid/?example=general_checkboxes) | <img src="media/preview/radio_group.gif" width="200" height="100"> |
|
||||||
|
| **[Dynamic Grid](docs_md/01-components.md#dynamic-grid)** | Component to manage node positions with different sizes. Only in one row or column | [Dynamic Grid API](https://insality.github.io/druid/modules/DynamicGrid.html) | [Dynamic Grid Example](https://insality.github.io/druid/druid/?example=general_grid) | <img src="media/preview/dynamic_grid.gif" width="200" height="100"> |
|
||||||
|
| **[Data List](docs_md/01-components.md#data-list)** | Component to manage data for huge datasets in scroll | [Data List API](https://insality.github.io/druid/modules/DataList.html) | [Data List Example](https://insality.github.io/druid/druid/?example=general_data_list) | <img src="media/preview/data_list.gif" width="200" height="100"> |
|
||||||
|
| **[Input](docs_md/01-components.md#input)** | User text input component | [Input API](https://insality.github.io/druid/modules/Input.html) | [Input Example](https://insality.github.io/druid/druid/?example=general_input) | <img src="media/preview/input.gif" width="200" height="100"> |
|
||||||
|
| **[Lang text](docs_md/01-components.md#lang-text)** | Wrap on Text component to handle localization | [Lang Text API](https://insality.github.io/druid/modules/LangText.html) | <img src="media/preview/lang_text.gif" width="200" height="100"> |
|
||||||
|
| **[Progress](docs_md/01-components.md#progress)** | Progress bar component | [Progress API](https://insality.github.io/druid/modules/Progress.html) | [Progress Example](https://insality.github.io/druid/druid/?example=general_progress_bar) | <img src="media/preview/progress.gif" width="200" height="100"> |
|
||||||
|
| **[Slider](docs_md/01-components.md#slider)** | Slider component | [Slider API](https://insality.github.io/druid/modules/Slider.html) | [Slider Example](https://insality.github.io/druid/druid/?example=general_sliders) | <img src="media/preview/slider.gif" width="200" height="100"> |
|
||||||
|
| **[Timer](docs_md/01-components.md#timer)** | Handle timers on GUI text node | [Timer API](https://insality.github.io/druid/modules/Timer.html) | <img src="media/preview/timer.gif" width="200" height="100"> |
|
||||||
|
| **[Hotkey](docs_md/01-components.md#hotkey)** | Handle keyboard hotkeys with key modificators | [Hotkey API](https://insality.github.io/druid/modules/Hotkey.html) | [Hotkey Example](https://insality.github.io/druid/druid/?example=general_hokey) | <img src="media/preview/hotkey.gif" width="200" height="100"> |
|
||||||
|
| **[Layout](docs_md/01-components.md#layout)** | Handle node size depends on layout mode and screen aspect ratio | [Layout API](https://insality.github.io/druid/modules/Layout.html) | [Layout Example](https://insality.github.io/druid/druid/?example=general_layout) | <img src="media/preview/layout.gif" width="200" height="100"> |
|
||||||
|
|
||||||
For a complete overview, see: **_[components.md](docs_md/01-components.md)_**.
|
For a complete overview, see: **_[components.md](docs_md/01-components.md)_**.
|
||||||
|
|
||||||
[^1]: Non basic components before use should be registered first to be included in build
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ file={"./druid",
|
|||||||
"./druid/system/middleclass.lua",
|
"./druid/system/middleclass.lua",
|
||||||
"./druid/templates/",
|
"./druid/templates/",
|
||||||
"./druid/annotations.lua",
|
"./druid/annotations.lua",
|
||||||
|
"./druid/custom/rich_text/module",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
package='druid'
|
package='druid'
|
||||||
|
@ -41,22 +41,10 @@ function druid.set_text_function(callback) end
|
|||||||
|
|
||||||
|
|
||||||
---@class druid.back_handler : druid.base_component
|
---@class druid.back_handler : druid.base_component
|
||||||
---@field on_back druid.event On back handler callback(self, params)
|
---@field on_back druid.event @{DruidEvent} function(self, [params]) .
|
||||||
---@field params any Params to back callback
|
---@field params any Params to pass in the callback
|
||||||
local druid__back_handler = {}
|
local druid__back_handler = {}
|
||||||
|
|
||||||
--- Component init function
|
|
||||||
---@param self druid.back_handler @{BackHandler}
|
|
||||||
---@param callback callback On back button
|
|
||||||
---@param params any Callback argument
|
|
||||||
function druid__back_handler.init(self, callback, params) end
|
|
||||||
|
|
||||||
--- Input handler for component
|
|
||||||
---@param self druid.back_handler @{BackHandler}
|
|
||||||
---@param action_id string on_input action id
|
|
||||||
---@param action table on_input action
|
|
||||||
function druid__back_handler.on_input(self, action_id, action) end
|
|
||||||
|
|
||||||
|
|
||||||
---@class druid.base_component
|
---@class druid.base_component
|
||||||
---@field ON_INPUT field Component Interests
|
---@field ON_INPUT field Component Interests
|
||||||
@ -179,12 +167,7 @@ function druid__base_component.set_template(self, template) end
|
|||||||
---@field node node Trigger node
|
---@field node node Trigger node
|
||||||
local druid__blocker = {}
|
local druid__blocker = {}
|
||||||
|
|
||||||
--- Component init function
|
--- Return blocker enabled state
|
||||||
---@param self druid.blocker @{Blocker}
|
|
||||||
---@param node node Gui node
|
|
||||||
function druid__blocker.init(self, node) end
|
|
||||||
|
|
||||||
--- Return blocked enabled state
|
|
||||||
---@param self druid.blocker @{Blocker}
|
---@param self druid.blocker @{Blocker}
|
||||||
---@return bool True, if blocker is enabled
|
---@return bool True, if blocker is enabled
|
||||||
function druid__blocker.is_enabled(self) end
|
function druid__blocker.is_enabled(self) end
|
||||||
@ -206,6 +189,7 @@ function druid__blocker.set_enabled(self, state) end
|
|||||||
---@field on_double_click druid.event On double tap button callback(self, params, button_instance, click_amount)
|
---@field on_double_click druid.event On double tap button callback(self, params, button_instance, click_amount)
|
||||||
---@field on_hold_callback druid.event On button hold before long_click callback(self, params, button_instance, time)
|
---@field on_hold_callback druid.event On button hold before long_click callback(self, params, button_instance, time)
|
||||||
---@field on_long_click druid.event On long tap button callback(self, params, button_instance, time)
|
---@field on_long_click druid.event On long tap button callback(self, params, button_instance, time)
|
||||||
|
---@field on_pressed druid.event On pressed button callback(self, params, button_instance)
|
||||||
---@field on_repeated_click druid.event On repeated action button callback(self, params, button_instance, click_amount)
|
---@field on_repeated_click druid.event On repeated action button callback(self, params, button_instance, click_amount)
|
||||||
---@field params any Params to click callbacks
|
---@field params any Params to click callbacks
|
||||||
---@field pos vector3 Initial pos of anim_node
|
---@field pos vector3 Initial pos of anim_node
|
||||||
@ -252,6 +236,13 @@ function druid__button.set_click_zone(self, zone) end
|
|||||||
---@return druid.button Current button instance
|
---@return druid.button Current button instance
|
||||||
function druid__button.set_enabled(self, state) end
|
function druid__button.set_enabled(self, state) end
|
||||||
|
|
||||||
|
--- Set buttom click mode to call itself inside html5 callback in user interaction event It required to do protected stuff like copy/paste text, show html keyboard, etc The HTML5 button don't call any events except on_click
|
||||||
|
---@protected
|
||||||
|
---@param self druid.button
|
||||||
|
---@param is_html_mode boolean If true - button will be called inside html5 callback
|
||||||
|
---@return druid.button Current button instance
|
||||||
|
function druid__button.set_html5_user_interaction(self, is_html_mode) end
|
||||||
|
|
||||||
--- Set key-code to trigger this button
|
--- Set key-code to trigger this button
|
||||||
---@param self druid.button @{Button}
|
---@param self druid.button @{Button}
|
||||||
---@param key hash The action_id of the key
|
---@param key hash The action_id of the key
|
||||||
@ -441,6 +432,7 @@ function druid__drag.set_enabled(self, is_enabled) end
|
|||||||
|
|
||||||
---@class druid.drag.style
|
---@class druid.drag.style
|
||||||
---@field DRAG_DEADZONE field Distance in pixels to start dragging
|
---@field DRAG_DEADZONE field Distance in pixels to start dragging
|
||||||
|
---@field NO_USE_SCREEN_KOEF field If screen aspect ratio affects on drag values
|
||||||
local druid__drag__style = {}
|
local druid__drag__style = {}
|
||||||
|
|
||||||
|
|
||||||
@ -573,6 +565,18 @@ function druid__event.unsubscribe(self, callback, context) end
|
|||||||
---@class druid.helper
|
---@class druid.helper
|
||||||
local druid__helper = {}
|
local druid__helper = {}
|
||||||
|
|
||||||
|
--- Get text metric from gui node.
|
||||||
|
--- Replacement of previous gui.get_text_metrics_from_node function
|
||||||
|
---@param text_node Node
|
||||||
|
---@return table {width, height, max_ascent, max_descent}
|
||||||
|
function druid__helper.get_text_metrics_from_node(text_node) end
|
||||||
|
|
||||||
|
--- Get text metric from gui node.
|
||||||
|
--- Replacement of previous gui.get_text_metrics_from_node function
|
||||||
|
---@param text_node Node
|
||||||
|
---@return table {width, height, max_ascent, max_descent}
|
||||||
|
function druid__helper.get_text_metrics_from_node(text_node) end
|
||||||
|
|
||||||
--- Transform table to oneline string
|
--- Transform table to oneline string
|
||||||
---@param t table
|
---@param t table
|
||||||
---@return string
|
---@return string
|
||||||
@ -607,8 +611,8 @@ local druid__hotkey__style = {}
|
|||||||
|
|
||||||
|
|
||||||
---@class druid.hover : druid.base_component
|
---@class druid.hover : druid.base_component
|
||||||
---@field on_hover druid.event On hover callback(self, state)
|
---@field on_hover druid.event On hover callback(self, state, hover_instance)
|
||||||
---@field on_mouse_hover druid.event On mouse hover callback(self, state)
|
---@field on_mouse_hover druid.event On mouse hover callback(self, state, hover_instance)
|
||||||
local druid__hover = {}
|
local druid__hover = {}
|
||||||
|
|
||||||
--- Component init function
|
--- Component init function
|
||||||
@ -622,6 +626,18 @@ function druid__hover.init(self, node, on_hover_callback) end
|
|||||||
---@return bool The hover enabled state
|
---@return bool The hover enabled state
|
||||||
function druid__hover.is_enabled(self) end
|
function druid__hover.is_enabled(self) end
|
||||||
|
|
||||||
|
--- Return current hover state.
|
||||||
|
--- True if touch action was on the node at current time
|
||||||
|
---@param self druid.hover @{Hover}
|
||||||
|
---@return bool The current hovered state
|
||||||
|
function druid__hover.is_hovered(self) end
|
||||||
|
|
||||||
|
--- Return current hover state.
|
||||||
|
--- True if nil action_id (usually desktop mouse) was on the node at current time
|
||||||
|
---@param self druid.hover @{Hover}
|
||||||
|
---@return bool The current hovered state
|
||||||
|
function druid__hover.is_mouse_hovered(self) end
|
||||||
|
|
||||||
--- Strict hover click area.
|
--- Strict hover click area.
|
||||||
--- Useful for no click events outside stencil node
|
--- Useful for no click events outside stencil node
|
||||||
---@param self druid.hover @{Hover}
|
---@param self druid.hover @{Hover}
|
||||||
@ -712,6 +728,7 @@ function druid__input.unselect(self) end
|
|||||||
---@field IS_LONGTAP_ERASE field Is long tap will erase current input data
|
---@field IS_LONGTAP_ERASE field Is long tap will erase current input data
|
||||||
---@field IS_UNSELECT_ON_RESELECT field If true, call unselect on select selected input
|
---@field IS_UNSELECT_ON_RESELECT field If true, call unselect on select selected input
|
||||||
---@field MASK_DEFAULT_CHAR field Default character mask for password input
|
---@field MASK_DEFAULT_CHAR field Default character mask for password input
|
||||||
|
---@field NO_CONSUME_INPUT_WHILE_SELECTED field If true, will not consume input while input is selected. It's allow to interact with other components while input is selected (text input still captured)
|
||||||
---@field button_style field Custom button style for input node
|
---@field button_style field Custom button style for input node
|
||||||
---@field on_input_wrong field (self, button_node) Callback on wrong user input
|
---@field on_input_wrong field (self, button_node) Callback on wrong user input
|
||||||
---@field on_select field (self, button_node) Callback on input field selecting
|
---@field on_select field (self, button_node) Callback on input field selecting
|
||||||
@ -794,6 +811,13 @@ function druid__layout.fit_into_window(self) end
|
|||||||
---@param on_size_changed_callback function The callback on window resize
|
---@param on_size_changed_callback function The callback on window resize
|
||||||
function druid__layout.init(self, node, mode, on_size_changed_callback) end
|
function druid__layout.init(self, node, mode, on_size_changed_callback) end
|
||||||
|
|
||||||
|
--- Set max gui upscale for FIT adjust mode (or side).
|
||||||
|
--- It happens on bigger render gui screen
|
||||||
|
---@param self druid.layout @{Layout}
|
||||||
|
---@param max_gui_upscale number
|
||||||
|
---@return druid.layout @{Layout}
|
||||||
|
function druid__layout.set_max_gui_upscale(self, max_gui_upscale) end
|
||||||
|
|
||||||
--- Set maximum size of layout node
|
--- Set maximum size of layout node
|
||||||
---@param self druid.layout @{Layout}
|
---@param self druid.layout @{Layout}
|
||||||
---@param max_size vector3
|
---@param max_size vector3
|
||||||
@ -952,6 +976,11 @@ function druid__rich_input.init(self, template, nodes) end
|
|||||||
function druid__rich_input.set_placeholder(self, placeholder_text) end
|
function druid__rich_input.set_placeholder(self, placeholder_text) end
|
||||||
|
|
||||||
|
|
||||||
|
---@class druid.rich_text : druid.base_component
|
||||||
|
---@field component field The component druid instance
|
||||||
|
local druid__rich_text = {}
|
||||||
|
|
||||||
|
|
||||||
---@class druid.scroll : druid.base_component
|
---@class druid.scroll : druid.base_component
|
||||||
---@field available_pos vector4 Available position for content node: (min_x, max_y, max_x, min_y)
|
---@field available_pos vector4 Available position for content node: (min_x, max_y, max_x, min_y)
|
||||||
---@field available_size vector3 Size of available positions: (width, height, 0)
|
---@field available_size vector3 Size of available positions: (width, height, 0)
|
||||||
@ -1272,7 +1301,7 @@ local druid__swipe__style = {}
|
|||||||
---@field node_id hash The node id of text node
|
---@field node_id hash The node id of text node
|
||||||
---@field on_set_pivot druid.event On change pivot callback(self, pivot)
|
---@field on_set_pivot druid.event On change pivot callback(self, pivot)
|
||||||
---@field on_set_text druid.event On set text callback(self, text)
|
---@field on_set_text druid.event On set text callback(self, text)
|
||||||
---@field on_update_text_scale druid.event On adjust text size callback(self, new_scale)
|
---@field on_update_text_scale druid.event On adjust text size callback(self, new_scale, text_metrics)
|
||||||
---@field pos vector3 Current text position
|
---@field pos vector3 Current text position
|
||||||
---@field scale vector3 Current text node scale
|
---@field scale vector3 Current text node scale
|
||||||
---@field start_scale vector3 Initial text node scale
|
---@field start_scale vector3 Initial text node scale
|
||||||
@ -1405,7 +1434,7 @@ local druid_instance = {}
|
|||||||
---@param self druid_instance
|
---@param self druid_instance
|
||||||
function druid_instance.final(self) end
|
function druid_instance.final(self) end
|
||||||
|
|
||||||
--- Druid late update function call after init and before udpate step
|
--- Druid late update function call after init and before update step
|
||||||
---@param self druid_instance
|
---@param self druid_instance
|
||||||
function druid_instance.late_init(self) end
|
function druid_instance.late_init(self) end
|
||||||
|
|
||||||
@ -1578,7 +1607,7 @@ function druid_instance.new_swipe(self, node, on_swipe_callback) end
|
|||||||
---@param node node Gui text node
|
---@param node node Gui text node
|
||||||
---@param value string Initial text. Default value is node text from GUI scene.
|
---@param value string Initial text. Default value is node text from GUI scene.
|
||||||
---@param no_adjust bool If true, text will be not auto-adjust size
|
---@param no_adjust bool If true, text will be not auto-adjust size
|
||||||
---@return Tet text component
|
---@return druid.text text component
|
||||||
function druid_instance.new_text(self, node, value, no_adjust) end
|
function druid_instance.new_text(self, node, value, no_adjust) end
|
||||||
|
|
||||||
--- Create timer component
|
--- Create timer component
|
||||||
@ -1700,6 +1729,12 @@ function helper.get_closest_stencil_node(node) end
|
|||||||
---@return vector3 Vector offset with [-1..1] values
|
---@return vector3 Vector offset with [-1..1] values
|
||||||
function helper.get_pivot_offset(pivot) end
|
function helper.get_pivot_offset(pivot) end
|
||||||
|
|
||||||
|
--- Get cumulative parent's node scale
|
||||||
|
---@param node node Gui node
|
||||||
|
---@param include_passed_node_scale bool True if add current node scale to result
|
||||||
|
---@return vector3 The scene node scale
|
||||||
|
function helper.get_scene_scale(node, include_passed_node_scale) end
|
||||||
|
|
||||||
--- Check if node is enabled in gui hierarchy.
|
--- Check if node is enabled in gui hierarchy.
|
||||||
--- Return false, if node or any his parent is disabled
|
--- Return false, if node or any his parent is disabled
|
||||||
---@param node node Gui node
|
---@param node node Gui node
|
||||||
|
@ -1,15 +1,40 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2023 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Component to handle back key (android, backspace)
|
--- Component with event on back or backspace button.
|
||||||
|
-- # Overview #
|
||||||
|
--
|
||||||
|
-- Back Handler is recommended to put in every game window to close it
|
||||||
|
-- or in main screen to call settings window.
|
||||||
|
--
|
||||||
|
-- # Tech Info #
|
||||||
|
--
|
||||||
|
-- Back Handler react on release action ACTION_BACK or ACTION_BACKSPACE
|
||||||
|
--
|
||||||
|
-- # Notes #
|
||||||
|
--
|
||||||
|
-- • Back Handler inheritance @{BaseComponent}, you can use all of its methods in addition to those described here.
|
||||||
|
-- @usage
|
||||||
|
-- local callback = function(self, params) ... end
|
||||||
|
--
|
||||||
|
-- local params = {}
|
||||||
|
-- local back_handler = self.druid:new_back_handler(callback, [params])
|
||||||
-- @module BackHandler
|
-- @module BackHandler
|
||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.back_handler
|
-- @alias druid.back_handler
|
||||||
|
|
||||||
--- On back handler callback(self, params)
|
--- @{DruidEvent} function(self, [params]) .
|
||||||
|
--
|
||||||
|
-- Trigger on input action ACTION_BACK or ACTION_BACKSPACE
|
||||||
|
-- @usage
|
||||||
|
-- -- Subscribe additional callbacks:
|
||||||
|
-- back_handler.on_back:subscribe(callback)
|
||||||
-- @tfield DruidEvent on_back @{DruidEvent}
|
-- @tfield DruidEvent on_back @{DruidEvent}
|
||||||
|
|
||||||
--- Params to back callback
|
--- Params to pass in the callback
|
||||||
-- @tfield any params
|
-- @usage
|
||||||
|
-- -- Replace params on runtime:
|
||||||
|
-- back_handler.params = { ... }
|
||||||
|
-- @tfield[opt] any params
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -20,20 +45,22 @@ local component = require("druid.component")
|
|||||||
local BackHandler = component.create("back_handler")
|
local BackHandler = component.create("back_handler")
|
||||||
|
|
||||||
|
|
||||||
--- Component init function
|
--- Component initialize function
|
||||||
-- @tparam BackHandler self @{BackHandler}
|
-- @tparam BackHandler self @{BackHandler}
|
||||||
-- @tparam callback callback On back button
|
-- @tparam callback callback On back button
|
||||||
-- @tparam[opt] any params Callback argument
|
-- @tparam[opt] any params Callback argument
|
||||||
|
-- @local
|
||||||
function BackHandler.init(self, callback, params)
|
function BackHandler.init(self, callback, params)
|
||||||
self.params = params
|
self.params = params
|
||||||
self.on_back = Event(callback)
|
self.on_back = Event(callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Input handler for component
|
--- Component input handler
|
||||||
-- @tparam BackHandler self @{BackHandler}
|
-- @tparam BackHandler self @{BackHandler}
|
||||||
-- @tparam string action_id on_input action id
|
-- @tparam string action_id on_input action id
|
||||||
-- @tparam table action on_input action
|
-- @tparam table action on_input action
|
||||||
|
-- @local
|
||||||
function BackHandler.on_input(self, action_id, action)
|
function BackHandler.on_input(self, action_id, action)
|
||||||
if not action[const.RELEASED] then
|
if not action[const.RELEASED] then
|
||||||
return false
|
return false
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Basic class for all Druid components.
|
--- Basic class for all Druid components.
|
||||||
-- To create you component, use `component.create`
|
-- To create you custom component, use `component.create`
|
||||||
|
-- @usage
|
||||||
|
-- -- Create your component:
|
||||||
|
-- local component = require("druid.component")
|
||||||
|
-- local AwesomeComponent = component.create("awesome_component")
|
||||||
-- @module BaseComponent
|
-- @module BaseComponent
|
||||||
-- @alias druid.base_component
|
-- @alias druid.base_component
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
-- Author: Britzl
|
-- Author: Britzl
|
||||||
-- Modified by: Insality
|
-- Modified by: Insality
|
||||||
|
|
||||||
|
--- RT
|
||||||
|
-- @module rich_text.rt
|
||||||
|
-- @local
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local parser = require("druid.custom.rich_text.module.rt_parse")
|
local parser = require("druid.custom.rich_text.module.rt_parse")
|
||||||
local utf8_lua = require("druid.system.utf8")
|
local utf8_lua = require("druid.system.utf8")
|
||||||
@ -203,6 +207,7 @@ function M._fill_properties(word, metrics, settings)
|
|||||||
word.position = vmath.vector3(0)
|
word.position = vmath.vector3(0)
|
||||||
|
|
||||||
if word.image then
|
if word.image then
|
||||||
|
-- Image properties
|
||||||
word.scale = gui.get_scale(settings.node_prefab) * word.relative_scale * settings.adjust_scale
|
word.scale = gui.get_scale(settings.node_prefab) * word.relative_scale * settings.adjust_scale
|
||||||
word.pivot = gui.get_pivot(settings.node_prefab)
|
word.pivot = gui.get_pivot(settings.node_prefab)
|
||||||
word.size = metrics.node_size
|
word.size = metrics.node_size
|
||||||
@ -212,6 +217,7 @@ function M._fill_properties(word, metrics, settings)
|
|||||||
word.size.x = word.image.width
|
word.size.x = word.image.width
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
-- Text properties
|
||||||
word.scale = gui.get_scale(settings.text_prefab) * word.relative_scale * settings.adjust_scale
|
word.scale = gui.get_scale(settings.text_prefab) * word.relative_scale * settings.adjust_scale
|
||||||
word.pivot = gui.get_pivot(settings.text_prefab)
|
word.pivot = gui.get_pivot(settings.text_prefab)
|
||||||
word.size = vmath.vector3(metrics.width, metrics.height, 0)
|
word.size = vmath.vector3(metrics.width, metrics.height, 0)
|
||||||
@ -510,32 +516,6 @@ function M.is_fit_info_area(lines, settings)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Detected click/touch events on words with an anchor tag
|
|
||||||
-- These words act as "hyperlinks" and will generate a message when clicked
|
|
||||||
-- @param words Words to search for anchor tags
|
|
||||||
-- @param action The action table from on_input
|
|
||||||
-- @return true if a word was clicked, otherwise false
|
|
||||||
function M.on_click(words, action)
|
|
||||||
for i = 1, #words do
|
|
||||||
local word = words[i]
|
|
||||||
if word.anchor and gui.pick_node(word.node, action.x, action.y) then
|
|
||||||
if word.tags and word.tags.a then
|
|
||||||
local message = {
|
|
||||||
node_id = gui.get_id(word.node),
|
|
||||||
text = word.text,
|
|
||||||
x = action.x, y = action.y,
|
|
||||||
screen_x = action.screen_x, screen_y = action.screen_y
|
|
||||||
}
|
|
||||||
msg.post("#", word.tags.a, message)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Get all words with a specific tag
|
--- Get all words with a specific tag
|
||||||
-- @param words The words to search (as received from richtext.create)
|
-- @param words The words to search (as received from richtext.create)
|
||||||
-- @param tag The tag to search for. Nil to search for words without a tag
|
-- @param tag The tag to search for. Nil to search for words without a tag
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
|
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
|
--- Druid Rich Text custom component.
|
||||||
|
-- It's wrapper on Input component with cursor and placeholder text
|
||||||
|
-- @module RichText
|
||||||
|
-- @within BaseComponent
|
||||||
|
-- @alias druid.rich_text
|
||||||
|
|
||||||
|
--- The component druid instance
|
||||||
|
-- @tfield DruidInstance druid @{DruidInstance}
|
||||||
|
|
||||||
|
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
local rich_text = require("druid.custom.rich_text.module.rt")
|
local rich_text = require("druid.custom.rich_text.module.rt")
|
||||||
|
|
||||||
---@class druid.rich_text
|
|
||||||
local RichText = component.create("rich_text")
|
local RichText = component.create("rich_text")
|
||||||
|
|
||||||
local SCHEME = {
|
local SCHEME = {
|
||||||
@ -14,9 +25,9 @@ local SCHEME = {
|
|||||||
function RichText:init(template, nodes)
|
function RichText:init(template, nodes)
|
||||||
self:set_template(template)
|
self:set_template(template)
|
||||||
self:set_nodes(nodes)
|
self:set_nodes(nodes)
|
||||||
|
|
||||||
self.root = self:get_node(SCHEME.ROOT)
|
self.root = self:get_node(SCHEME.ROOT)
|
||||||
self.druid = self:get_druid()
|
self.druid = self:get_druid()
|
||||||
self.root_size = gui.get_size(self.root)
|
|
||||||
|
|
||||||
self.text_prefab = self:get_node(SCHEME.TEXT_PREFAB)
|
self.text_prefab = self:get_node(SCHEME.TEXT_PREFAB)
|
||||||
self.icon_prefab = self:get_node(SCHEME.ICON_PREFAB)
|
self.icon_prefab = self:get_node(SCHEME.ICON_PREFAB)
|
||||||
@ -24,12 +35,10 @@ function RichText:init(template, nodes)
|
|||||||
gui.set_enabled(self.text_prefab, false)
|
gui.set_enabled(self.text_prefab, false)
|
||||||
gui.set_enabled(self.icon_prefab, false)
|
gui.set_enabled(self.icon_prefab, false)
|
||||||
|
|
||||||
self._settings = self:_get_settings()
|
self._settings = self:_create_settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param text string
|
|
||||||
---@return rich_text.word[], rich_text.lines_metrics
|
|
||||||
function RichText:set_text(text)
|
function RichText:set_text(text)
|
||||||
self:clean()
|
self:clean()
|
||||||
|
|
||||||
@ -57,24 +66,25 @@ function RichText:tagged(tag)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@return druid.rich_text_word[]
|
|
||||||
function RichText:get_words()
|
function RichText:get_words()
|
||||||
return self._words
|
return self._words
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function RichText:_get_settings()
|
function RichText:_create_settings()
|
||||||
|
local root_size = gui.get_size(self.root)
|
||||||
return {
|
return {
|
||||||
-- General settings
|
-- General settings
|
||||||
|
-- Adjust scale using to fit the text to the root node area
|
||||||
adjust_scale = 1,
|
adjust_scale = 1,
|
||||||
parent = self.root,
|
parent = self.root,
|
||||||
width = self.root_size.x,
|
width = root_size.x,
|
||||||
height = self.root_size.y,
|
height = root_size.y,
|
||||||
|
combine_words = false,
|
||||||
text_prefab = self.text_prefab,
|
text_prefab = self.text_prefab,
|
||||||
node_prefab = self.icon_prefab,
|
node_prefab = self.icon_prefab,
|
||||||
|
|
||||||
-- Text Settings
|
-- Text Settings
|
||||||
size = gui.get_scale(self.text_prefab).x,
|
|
||||||
shadow = gui.get_shadow(self.text_prefab),
|
shadow = gui.get_shadow(self.text_prefab),
|
||||||
outline = gui.get_outline(self.text_prefab),
|
outline = gui.get_outline(self.text_prefab),
|
||||||
text_scale = gui.get_scale(self.text_prefab),
|
text_scale = gui.get_scale(self.text_prefab),
|
||||||
@ -82,7 +92,6 @@ function RichText:_get_settings()
|
|||||||
is_multiline = gui.get_line_break(self.text_prefab),
|
is_multiline = gui.get_line_break(self.text_prefab),
|
||||||
|
|
||||||
-- Image settings
|
-- Image settings
|
||||||
combine_words = false,
|
|
||||||
image_pixel_grid_snap = false,
|
image_pixel_grid_snap = false,
|
||||||
node_scale = gui.get_scale(self.icon_prefab),
|
node_scale = gui.get_scale(self.icon_prefab),
|
||||||
image_scale = gui.get_scale(self.icon_prefab),
|
image_scale = gui.get_scale(self.icon_prefab),
|
||||||
|
@ -205,6 +205,8 @@ local function init_lobby(self)
|
|||||||
|
|
||||||
self.lobby_grid:add(get_title(self, "Rich Texts"))
|
self.lobby_grid:add(get_title(self, "Rich Texts"))
|
||||||
self.lobby_grid:add(get_button(self, "Rich Text Texts", "rich_text_texts", "/custom/rich_text_texts/rich_text_texts.gui_script"))
|
self.lobby_grid:add(get_button(self, "Rich Text Texts", "rich_text_texts", "/custom/rich_text_texts/rich_text_texts.gui_script"))
|
||||||
|
self.lobby_grid:add(get_button_disabled(self, "Rich Text Images"))--, "rich_text_images", "/custom/rich_text_texts/rich_text_texts.gui_script"))
|
||||||
|
self.lobby_grid:add(get_button_disabled(self, "Rich Text Tags"))--, "rich_text_images", "/custom/rich_text_texts/rich_text_texts.gui_script"))
|
||||||
|
|
||||||
self.lobby_grid:add(get_title(self, "System"))
|
self.lobby_grid:add(get_title(self, "System"))
|
||||||
self.lobby_grid:add(get_button_disabled(self, "Styles"))
|
self.lobby_grid:add(get_button_disabled(self, "Styles"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user