Update docs, config generations, fix linter

This commit is contained in:
Insality 2024-10-15 19:34:07 +03:00
parent 2f5336fa4f
commit 5848921cba
44 changed files with 1880 additions and 1336 deletions

View File

@ -27,6 +27,11 @@
"test/tests/*.lua", "test/tests/*.lua",
"utils/annotations_manual.lua" "utils/annotations_manual.lua"
], ],
"Lua.runtime.pathStrict": true,
"Lua.diagnostics.libraryFiles": "Enable", "Lua.diagnostics.libraryFiles": "Enable",
"Lua.runtime.version": "Lua 5.1" "Lua.runtime.version": "Lua 5.1",
"Lua.workspace.library": [
"~/Library/Application Support/Code/User/globalStorage/astronachos.defold",
"~/Library/Application Support/Code/User/workspaceStorage/72e25b7e0fdc873ee6f7baa61edbd6b1/astronachos.defold"
]
} }

View File

@ -17,9 +17,9 @@ Try the [**HTML5 version**](https://insality.github.io/druid/druid/) of the **Dr
To integrate the **Druid** extension into your own project, add this project as a [dependency](https://www.defold.com/manuals/libraries/) in your **Defold** game. Open your `game.project` file and add the following line to the dependencies field under the project section: To integrate the **Druid** extension into your own project, add this project as a [dependency](https://www.defold.com/manuals/libraries/) in your **Defold** game. Open your `game.project` file and add the following line to the dependencies field under the project section:
**Druid v0.11.0** **Druid v0.12.0**
> [https://github.com/Insality/druid/archive/refs/tags/0.11.0.zip](https://github.com/Insality/druid/archive/refs/tags/0.11.0.zip) > [https://github.com/Insality/druid/archive/refs/tags/0.12.0.zip](https://github.com/Insality/druid/archive/refs/tags/0.12.0.zip)
Here is a list of [all releases](https://github.com/Insality/druid/releases). Here is a list of [all releases](https://github.com/Insality/druid/releases).

View File

@ -4,7 +4,6 @@ description='Documentation for Druid Framework'
file={"./druid", file={"./druid",
exclude = { exclude = {
"./druid/styles/", "./druid/styles/",
"./druid/system/middleclass.lua",
"./druid/templates/", "./druid/templates/",
"./druid/annotations.lua", "./druid/annotations.lua",
"./druid/custom/rich_text/module", "./druid/custom/rich_text/module",

View File

@ -106,7 +106,7 @@ return AwesomeComponent
<td class="summary">Context used as first arg in all Druid events</td> <td class="summary">Context used as first arg in all Druid events</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_druid">get_druid(self)</a></td> <td class="name" nowrap><a href="#get_druid">get_druid(self, template, nodes)</a></td>
<td class="summary">Get Druid instance for inner component creation.</td> <td class="summary">Get Druid instance for inner component creation.</td>
</tr> </tr>
<tr> <tr>
@ -226,7 +226,7 @@ return AwesomeComponent
</dd> </dd>
<dt> <dt>
<a name = "get_druid"></a> <a name = "get_druid"></a>
<strong>get_druid(self)</strong> <strong>get_druid(self, template, nodes)</strong>
</dt> </dt>
<dd> <dd>
Get Druid instance for inner component creation. Get Druid instance for inner component creation.
@ -238,6 +238,14 @@ return AwesomeComponent
<span class="types"><span class="type">BaseComponent</span></span> <span class="types"><span class="type">BaseComponent</span></span>
<a href="../modules/BaseComponent.html#">BaseComponent</a> <a href="../modules/BaseComponent.html#">BaseComponent</a>
</li> </li>
<li><span class="parameter">template</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
The template name
</li>
<li><span class="parameter">nodes</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <span class="type">nil</span></span>
The nodes table
</li>
</ul> </ul>
<h3>Returns:</h3> <h3>Returns:</h3>

View File

@ -100,22 +100,10 @@
<td class="summary">Return current data from DataList component</td> <td class="summary">Return current data from DataList component</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_first_index">get_first_index(self)</a></td>
<td class="summary">Return first index from data.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_index">get_index(self, data)</a></td> <td class="name" nowrap><a href="#get_index">get_index(self, data)</a></td>
<td class="summary">Return index for data value</td> <td class="summary">Return index for data value</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_last_index">get_last_index(self)</a></td>
<td class="summary">Return last index from data</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_length">get_length(self)</a></td>
<td class="summary">Return amount of data</td>
</tr>
<tr>
<td class="name" nowrap><a href="#init">init(self, scroll, grid, create_function)</a></td> <td class="name" nowrap><a href="#init">init(self, scroll, grid, create_function)</a></td>
<td class="summary">The <a href="../modules/DataList.html#">DataList</a> constructor</td> <td class="summary">The <a href="../modules/DataList.html#">DataList</a> constructor</td>
</tr> </tr>
@ -131,6 +119,10 @@
<td class="name" nowrap><a href="#set_data">set_data(self, data)</a></td> <td class="name" nowrap><a href="#set_data">set_data(self, data)</a></td>
<td class="summary">Set new data set for DataList component</td> <td class="summary">Set new data set for DataList component</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#set_use_cache">set_use_cache(self, is_use_cache)</a></td>
<td class="summary">Set refresh function for DataList component</td>
</tr>
</table> </table>
<h2><a href="#Fields">Fields</a></h2> <h2><a href="#Fields">Fields</a></h2>
<table class="function_list"> <table class="function_list">
@ -140,7 +132,7 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#last_index">last_index</a></td> <td class="name" nowrap><a href="#last_index">last_index</a></td>
<td class="summary">The current visual last data index</td> <td class="summary">The current last index of visual elements</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_element_add">on_element_add</a></td> <td class="name" nowrap><a href="#on_element_add">on_element_add</a></td>
@ -164,7 +156,7 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#top_index">top_index</a></td> <td class="name" nowrap><a href="#top_index">top_index</a></td>
<td class="summary">The current visual top data index</td> <td class="summary">The current top index of visual elements</td>
</tr> </tr>
</table> </table>
@ -276,27 +268,6 @@
</dd>
<dt>
<a name = "get_first_index"></a>
<strong>get_first_index(self)</strong>
</dt>
<dd>
Return first index from data. It not always equals to 1
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DataList</span></span>
<a href="../modules/DataList.html#">DataList</a>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "get_index"></a> <a name = "get_index"></a>
@ -322,48 +293,6 @@
</dd>
<dt>
<a name = "get_last_index"></a>
<strong>get_last_index(self)</strong>
</dt>
<dd>
Return last index from data
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DataList</span></span>
<a href="../modules/DataList.html#">DataList</a>
</li>
</ul>
</dd>
<dt>
<a name = "get_length"></a>
<strong>get_length(self)</strong>
</dt>
<dd>
Return amount of data
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DataList</span></span>
<a href="../modules/DataList.html#">DataList</a>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "init"></a> <a name = "init"></a>
@ -474,6 +403,37 @@
</dd>
<dt>
<a name = "set_use_cache"></a>
<strong>set_use_cache(self, is_use_cache)</strong>
</dt>
<dd>
Set refresh function for DataList component
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DataList</span></span>
<a href="../modules/DataList.html#">DataList</a>
</li>
<li><span class="parameter">is_use_cache</span>
<span class="types"><span class="type">boolean</span></span>
Use cache version of DataList. Requires make setup of components in on_element_add callback and clean in on_element_remove
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.data_list</span></span>
Current DataList instance
</ol>
</dd> </dd>
</dl> </dl>
<h2 class="section-header "><a name="Fields"></a>Fields</h2> <h2 class="section-header "><a name="Fields"></a>Fields</h2>
@ -504,7 +464,7 @@
<strong>last_index</strong> <strong>last_index</strong>
</dt> </dt>
<dd> <dd>
The current visual last data index The current last index of visual elements
<ul> <ul>
@ -624,7 +584,7 @@
<strong>top_index</strong> <strong>top_index</strong>
</dt> </dt>
<dd> <dd>
The current visual top data index The current top index of visual elements
<ul> <ul>

View File

@ -134,11 +134,11 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_drag">on_drag</a></td> <td class="name" nowrap><a href="#on_drag">on_drag</a></td>
<td class="summary">on drag progress callback(self, dx, dy, total_x, total_y)</td> <td class="summary">on drag progress callback(self, dx, dy, total_x, total_y, touch)</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_drag_end">on_drag_end</a></td> <td class="name" nowrap><a href="#on_drag_end">on_drag_end</a></td>
<td class="summary">Event on drag end callback(self, total_x, total_y)</td> <td class="summary">Event on drag end callback(self, total_x, total_y, touch)</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_drag_start">on_drag_start</a></td> <td class="name" nowrap><a href="#on_drag_start">on_drag_start</a></td>
@ -428,7 +428,7 @@
<strong>on_drag</strong> <strong>on_drag</strong>
</dt> </dt>
<dd> <dd>
on drag progress callback(self, dx, dy, total_x, total_y) on drag progress callback(self, dx, dy, total_x, total_y, touch)
<ul> <ul>
@ -448,7 +448,7 @@
<strong>on_drag_end</strong> <strong>on_drag_end</strong>
</dt> </dt>
<dd> <dd>
Event on drag end callback(self, total_x, total_y) Event on drag end callback(self, total_x, total_y, touch)
<ul> <ul>

View File

@ -87,15 +87,23 @@
<td class="summary">Clear the all event handlers</td> <td class="summary">Clear the all event handlers</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#initialize">initialize(self, initial_callback)</a></td> <td class="name" nowrap><a href="#create">create(callback, callback_context)</a></td>
<td class="summary">DruidEvent constructor</td> <td class="summary">DruidEvent constructor</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#is_empty">is_empty(self)</a></td>
<td class="summary">Return true, if event not have handler</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_exist">is_exist(self)</a></td> <td class="name" nowrap><a href="#is_exist">is_exist(self)</a></td>
<td class="summary">Return true, if event have at lease one handler</td> <td class="summary">Return true, if event have at lease one handler</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#subscribe">subscribe(self, callback, context)</a></td> <td class="name" nowrap><a href="#is_subscribed">is_subscribed(self, callback, callback_context)</a></td>
<td class="summary">Check is event subscribed.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#subscribe">subscribe(self, callback, callback_context)</a></td>
<td class="summary">Subscribe callback on event</td> <td class="summary">Subscribe callback on event</td>
</tr> </tr>
<tr> <tr>
@ -103,7 +111,7 @@
<td class="summary">Trigger the event and call all subscribed callbacks</td> <td class="summary">Trigger the event and call all subscribed callbacks</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#unsubscribe">unsubscribe(self, callback, context)</a></td> <td class="name" nowrap><a href="#unsubscribe">unsubscribe(self, callback, callback_context)</a></td>
<td class="summary">Unsubscribe callback on event</td> <td class="summary">Unsubscribe callback on event</td>
</tr> </tr>
</table> </table>
@ -141,8 +149,8 @@
</dd> </dd>
<dt> <dt>
<a name = "initialize"></a> <a name = "create"></a>
<strong>initialize(self, initial_callback)</strong> <strong>create(callback, callback_context)</strong>
</dt> </dt>
<dd> <dd>
DruidEvent constructor DruidEvent constructor
@ -150,14 +158,14 @@
<h3>Parameters:</h3> <h3>Parameters:</h3>
<ul> <ul>
<li><span class="parameter">self</span> <li><span class="parameter">callback</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">initial_callback</span>
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span> <span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
Subscribe the callback on new event, if callback exist Subscribe the callback on new event, if callback exist
</li> </li>
<li><span class="parameter">callback_context</span>
<span class="types"><span class="type">any</span> or <span class="type">nil</span></span>
Additional context as first param to callback call
</li>
</ul> </ul>
@ -167,7 +175,38 @@
<ul> <ul>
<pre class="example"><span class="keyword">local</span> Event = <span class="global">require</span>(<span class="string">"druid.event"</span>) <pre class="example"><span class="keyword">local</span> Event = <span class="global">require</span>(<span class="string">"druid.event"</span>)
... ...
<span class="keyword">local</span> event = Event(initial_callback)</pre> <span class="keyword">local</span> event = Event(callback)</pre>
</ul>
</dd>
<dt>
<a name = "is_empty"></a>
<strong>is_empty(self)</strong>
</dt>
<dd>
Return true, if event not have handler
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
True if event not have handlers
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> is_long_click_handler_not_exists = button.on_long_click:is_empty()</pre>
</ul> </ul>
</dd> </dd>
@ -201,10 +240,45 @@
<pre class="example"><span class="keyword">local</span> is_long_click_handler_exists = button.on_long_click:is_exist()</pre> <pre class="example"><span class="keyword">local</span> is_long_click_handler_exists = button.on_long_click:is_exist()</pre>
</ul> </ul>
</dd>
<dt>
<a name = "is_subscribed"></a>
<strong>is_subscribed(self, callback, callback_context)</strong>
</dt>
<dd>
Check is event subscribed.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">callback</span>
<span class="types"><span class="type">function</span></span>
Callback itself
</li>
<li><span class="parameter">callback_context</span>
<span class="types"><span class="type">any</span> or <span class="type">nil</span></span>
Additional context as first param to callback call
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean,</span></span>
number|nil @Is event subscribed, return index of callback in event as second param
</ol>
</dd> </dd>
<dt> <dt>
<a name = "subscribe"></a> <a name = "subscribe"></a>
<strong>subscribe(self, callback, context)</strong> <strong>subscribe(self, callback, callback_context)</strong>
</dt> </dt>
<dd> <dd>
Subscribe callback on event Subscribe callback on event
@ -220,12 +294,18 @@
<span class="types"><span class="type">function</span></span> <span class="types"><span class="type">function</span></span>
Callback itself Callback itself
</li> </li>
<li><span class="parameter">context</span> <li><span class="parameter">callback_context</span>
<span class="types"><span class="type">any</span> or <span class="type">nil</span></span> <span class="types"><span class="type">any</span> or <span class="type">nil</span></span>
Additional context as first param to callback call, usually it's self Additional context as first param to callback call, usually it's self
</li> </li>
</ul> </ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
True if callback was subscribed
</ol>
@ -274,7 +354,7 @@ event:trigger(<span class="string">"Param1"</span>, <span class="string">"Param2
</dd> </dd>
<dt> <dt>
<a name = "unsubscribe"></a> <a name = "unsubscribe"></a>
<strong>unsubscribe(self, callback, context)</strong> <strong>unsubscribe(self, callback, callback_context)</strong>
</dt> </dt>
<dd> <dd>
Unsubscribe callback on event Unsubscribe callback on event
@ -290,7 +370,7 @@ event:trigger(<span class="string">"Param1"</span>, <span class="string">"Param2
<span class="types"><span class="type">function</span></span> <span class="types"><span class="type">function</span></span>
Callback itself Callback itself
</li> </li>
<li><span class="parameter">context</span> <li><span class="parameter">callback_context</span>
<span class="types"><span class="type">any</span> or <span class="type">nil</span></span> <span class="types"><span class="type">any</span> or <span class="type">nil</span></span>
Additional context as first param to callback call Additional context as first param to callback call
</li> </li>

View File

@ -142,10 +142,6 @@ end
<td class="summary">Call this in gui_script final function.</td> <td class="summary">Call this in gui_script final function.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#new">new(self, component, ...)</a></td>
<td class="summary">Create new component.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#new_back_handler">new_back_handler(self, callback, params)</a></td> <td class="name" nowrap><a href="#new_back_handler">new_back_handler(self, callback, params)</a></td>
<td class="summary">Create <a href="../modules/BackHandler.html#">BackHandler</a> component</td> <td class="summary">Create <a href="../modules/BackHandler.html#">BackHandler</a> component</td>
</tr> </tr>
@ -182,7 +178,7 @@ end
<td class="summary">Create <a href="../modules/Hotkey.html#">Hotkey</a> component</td> <td class="summary">Create <a href="../modules/Hotkey.html#">Hotkey</a> component</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#new_hover">new_hover(self, node, on_hover_callback)</a></td> <td class="name" nowrap><a href="#new_hover">new_hover(self, node, on_hover_callback, on_mouse_hover_callback)</a></td>
<td class="summary">Create <a href="../modules/Hover.html#">Hover</a> component</td> <td class="summary">Create <a href="../modules/Hover.html#">Hover</a> component</td>
</tr> </tr>
<tr> <tr>
@ -194,7 +190,7 @@ end
<td class="summary">Create <a href="../modules/LangText.html#">LangText</a> component</td> <td class="summary">Create <a href="../modules/LangText.html#">LangText</a> component</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#new_layout">new_layout(self, node, mode, on_size_changed_callback)</a></td> <td class="name" nowrap><a href="#new_layout">new_layout(self, node, mode)</a></td>
<td class="summary">Create <a href="../modules/Layout.html#">Layout</a> component</td> <td class="summary">Create <a href="../modules/Layout.html#">Layout</a> component</td>
</tr> </tr>
<tr> <tr>
@ -286,41 +282,6 @@ end
</dd>
<dt>
<a name = "new"></a>
<strong>new(self, component, ...)</strong>
</dt>
<dd>
Create new component.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidInstance</span></span>
</li>
<li><span class="parameter">component</span>
<span class="types"><span class="type">BaseComponent</span></span>
Component module
</li>
<li><span class="parameter">...</span>
<span class="types"><span class="type">any</span></span>
Other component params to pass it to component:init function
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">BaseComponent</span></span>
Component instance
</ol>
</dd> </dd>
<dt> <dt>
<a name = "new_back_handler"></a> <a name = "new_back_handler"></a>
@ -411,7 +372,7 @@ end
Button callback Button callback
</li> </li>
<li><span class="parameter">params</span> <li><span class="parameter">params</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <span class="type">nil</span></span> <span class="types"><span class="type">any</span> or <span class="type">nil</span></span>
Button callback params Button callback params
</li> </li>
<li><span class="parameter">anim_node</span> <li><span class="parameter">anim_node</span>
@ -659,7 +620,7 @@ end
</dd> </dd>
<dt> <dt>
<a name = "new_hover"></a> <a name = "new_hover"></a>
<strong>new_hover(self, node, on_hover_callback)</strong> <strong>new_hover(self, node, on_hover_callback, on_mouse_hover_callback)</strong>
</dt> </dt>
<dd> <dd>
Create <a href="../modules/Hover.html#">Hover</a> component Create <a href="../modules/Hover.html#">Hover</a> component
@ -679,6 +640,10 @@ end
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span> <span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
Hover callback Hover callback
</li> </li>
<li><span class="parameter">on_mouse_hover_callback</span>
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
Mouse hover callback
</li>
</ul> </ul>
<h3>Returns:</h3> <h3>Returns:</h3>
@ -772,7 +737,7 @@ end
</dd> </dd>
<dt> <dt>
<a name = "new_layout"></a> <a name = "new_layout"></a>
<strong>new_layout(self, node, mode, on_size_changed_callback)</strong> <strong>new_layout(self, node, mode)</strong>
</dt> </dt>
<dd> <dd>
Create <a href="../modules/Layout.html#">Layout</a> component Create <a href="../modules/Layout.html#">Layout</a> component
@ -792,10 +757,6 @@ end
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The layout mode The layout mode
</li> </li>
<li><span class="parameter">on_size_changed_callback</span>
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
The callback on window resize
</li>
</ul> </ul>
<h3>Returns:</h3> <h3>Returns:</h3>
@ -1244,6 +1205,12 @@ end
</li> </li>
</ul> </ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
True if component was removed
</ol>

View File

@ -151,10 +151,18 @@ helper.centrate_nodes(0, node_1, node_2)
<td class="summary">Check if device is native mobile (Android or iOS)</td> <td class="summary">Check if device is native mobile (Android or iOS)</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#helper.is_multitouch_supported">helper.is_multitouch_supported()</a></td>
<td class="summary">Check if device is mobile and can support multitouch</td>
</tr>
<tr>
<td class="name" nowrap><a href="#helper.is_web">helper.is_web()</a></td> <td class="name" nowrap><a href="#helper.is_web">helper.is_web()</a></td>
<td class="summary">Check if device is HTML5</td> <td class="summary">Check if device is HTML5</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#helper.is_web_mobile">helper.is_web_mobile()</a></td>
<td class="summary">Check if device is HTML5 mobile</td>
</tr>
<tr>
<td class="name" nowrap><a href="#helper.lerp">helper.lerp(a, b, t)</a></td> <td class="name" nowrap><a href="#helper.lerp">helper.lerp(a, b, t)</a></td>
<td class="summary">Lerp between two values</td> <td class="summary">Lerp between two values</td>
</tr> </tr>
@ -658,6 +666,26 @@ helper.centrate_nodes(0, node_1, node_2)
</dd>
<dt>
<a name = "helper.is_multitouch_supported"></a>
<strong>helper.is_multitouch_supported()</strong>
</dt>
<dd>
Check if device is mobile and can support multitouch
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
Is multitouch supported
</ol>
</dd> </dd>
<dt> <dt>
<a name = "helper.is_web"></a> <a name = "helper.is_web"></a>
@ -678,6 +706,26 @@ helper.centrate_nodes(0, node_1, node_2)
</dd>
<dt>
<a name = "helper.is_web_mobile"></a>
<strong>helper.is_web_mobile()</strong>
</dt>
<dd>
Check if device is HTML5 mobile
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
Is web mobile
</ol>
</dd> </dd>
<dt> <dt>
<a name = "helper.lerp"></a> <a name = "helper.lerp"></a>

View File

@ -117,8 +117,12 @@
<td class="summary">Visual node</td> <td class="summary">Visual node</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_change_state">on_change_state</a></td> <td class="name" nowrap><a href="#on_hotkey_pressed">on_hotkey_pressed</a></td>
<td class="summary">On change state callback(self, state)</td> <td class="summary">On hotkey released callback(self, argument)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#on_hotkey_released">on_hotkey_released</a></td>
<td class="summary">On hotkey released callback(self, argument)</td>
</tr> </tr>
</table> </table>
@ -320,15 +324,35 @@
</dd> </dd>
<dt> <dt>
<a name = "on_change_state"></a> <a name = "on_hotkey_pressed"></a>
<strong>on_change_state</strong> <strong>on_hotkey_pressed</strong>
</dt> </dt>
<dd> <dd>
On change state callback(self, state) On hotkey released callback(self, argument)
<ul> <ul>
<li><span class="parameter">on_change_state</span> <li><span class="parameter">on_hotkey_pressed</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
</dd>
<dt>
<a name = "on_hotkey_released"></a>
<strong>on_hotkey_released</strong>
</dt>
<dd>
On hotkey released callback(self, argument)
<ul>
<li><span class="parameter">on_hotkey_released</span>
<span class="types"><span class="type">DruidEvent</span></span> <span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a> <a href="../modules/DruidEvent.html#">DruidEvent</a>
</li> </li>

View File

@ -33,6 +33,7 @@
<h2>Contents</h2> <h2>Contents</h2>
<ul> <ul>
<li><a href="#Functions">Functions</a></li> <li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Fields">Fields</a></li> <li><a href="#Fields">Fields</a></li>
</ul> </ul>
@ -82,7 +83,7 @@
<h2><a href="#Functions">Functions</a></h2> <h2><a href="#Functions">Functions</a></h2>
<table class="function_list"> <table class="function_list">
<tr> <tr>
<td class="name" nowrap><a href="#init">init(self, node, on_hover_callback)</a></td> <td class="name" nowrap><a href="#init">init(self, node, on_hover_callback, on_mouse_hover)</a></td>
<td class="summary">The <a href="../modules/Hover.html#">Hover</a> constructor</td> <td class="summary">The <a href="../modules/Hover.html#">Hover</a> constructor</td>
</tr> </tr>
<tr> <tr>
@ -114,8 +115,19 @@
<td class="summary">Set mouse hover state</td> <td class="summary">Set mouse hover state</td>
</tr> </tr>
</table> </table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#style">style</a></td>
<td class="summary">Component style params.</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2> <h2><a href="#Fields">Fields</a></h2>
<table class="function_list"> <table class="function_list">
<tr>
<td class="name" nowrap><a href="#node">node</a></td>
<td class="summary">Hover node</td>
</tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_hover">on_hover</a></td> <td class="name" nowrap><a href="#on_hover">on_hover</a></td>
<td class="summary">On hover callback(self, state, hover_instance)</td> <td class="summary">On hover callback(self, state, hover_instance)</td>
@ -135,7 +147,7 @@
<dl class="function"> <dl class="function">
<dt> <dt>
<a name = "init"></a> <a name = "init"></a>
<strong>init(self, node, on_hover_callback)</strong> <strong>init(self, node, on_hover_callback, on_mouse_hover)</strong>
</dt> </dt>
<dd> <dd>
The <a href="../modules/Hover.html#">Hover</a> constructor The <a href="../modules/Hover.html#">Hover</a> constructor
@ -148,13 +160,17 @@
<a href="../modules/Hover.html#">Hover</a> <a href="../modules/Hover.html#">Hover</a>
</li> </li>
<li><span class="parameter">node</span> <li><span class="parameter">node</span>
<span class="types"><span class="type">node</span></span> <span class="types"><a class="type" href="../modules/Hover.html#node">node</a></span>
Gui node Gui node
</li> </li>
<li><span class="parameter">on_hover_callback</span> <li><span class="parameter">on_hover_callback</span>
<span class="types"><span class="type">function</span></span> <span class="types"><span class="type">function</span></span>
Hover callback Hover callback
</li> </li>
<li><span class="parameter">on_mouse_hover</span>
<span class="types"><span class="type">function</span></span>
On mouse hover callback
</li>
</ul> </ul>
@ -259,7 +275,7 @@
<a href="../modules/Hover.html#">Hover</a> <a href="../modules/Hover.html#">Hover</a>
</li> </li>
<li><span class="parameter">zone</span> <li><span class="parameter">zone</span>
<span class="types"><span class="type">node</span>, <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="../modules/Hover.html#node">node</a>, <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Gui node Gui node
</li> </li>
</ul> </ul>
@ -345,11 +361,64 @@
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "style"></a>
<strong>style</strong>
</dt>
<dd>
Component style params.
You can override this component styles params in druid styles table
or create your own style
<h3>Fields:</h3>
<ul>
<li><span class="parameter">ON_HOVER_CURSOR</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Mouse hover style on node hover
(<em>optional</em>)
</li>
<li><span class="parameter">ON_MOUSE_HOVER_CURSOR</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Mouse hover style on node mouse hover
(<em>optional</em>)
</li>
</ul>
</dd> </dd>
</dl> </dl>
<h2 class="section-header "><a name="Fields"></a>Fields</h2> <h2 class="section-header "><a name="Fields"></a>Fields</h2>
<dl class="function"> <dl class="function">
<dt>
<a name = "node"></a>
<strong>node</strong>
</dt>
<dd>
Hover node
<ul>
<li><span class="parameter">node</span>
<span class="types"><a class="type" href="../modules/Hover.html#node">node</a></span>
</li>
</ul>
</dd>
<dt> <dt>
<a name = "on_hover"></a> <a name = "on_hover"></a>
<strong>on_hover</strong> <strong>on_hover</strong>

View File

@ -93,10 +93,18 @@
<td class="summary">Return current input field text</td> <td class="summary">Return current input field text</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_text_selected_replaced">get_text_selected_replaced(self, text)</a></td>
<td class="summary">Replace selected text with new text</td>
</tr>
<tr>
<td class="name" nowrap><a href="#init">init(self, click_node, text_node, keyboard_type)</a></td> <td class="name" nowrap><a href="#init">init(self, click_node, text_node, keyboard_type)</a></td>
<td class="summary">The <a href="../modules/Input.html#">Input</a> constructor</td> <td class="summary">The <a href="../modules/Input.html#">Input</a> constructor</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#move_selection">move_selection(self, delta, is_add_to_selection, is_move_to_end)</a></td>
<td class="summary">Change cursor position by delta</td>
</tr>
<tr>
<td class="name" nowrap><a href="#reset_changes">reset_changes(self)</a></td> <td class="name" nowrap><a href="#reset_changes">reset_changes(self)</a></td>
<td class="summary">Reset current input selection and return previous value</td> <td class="summary">Reset current input selection and return previous value</td>
</tr> </tr>
@ -105,6 +113,10 @@
<td class="summary">Select input field.</td> <td class="summary">Select input field.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#select_cursor">select_cursor(self, cursor_index, start_index, end_index)</a></td>
<td class="summary">Set cursor position in input field</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_allowed_characters">set_allowed_characters(self, characters)</a></td> <td class="name" nowrap><a href="#set_allowed_characters">set_allowed_characters(self, characters)</a></td>
<td class="summary">Set allowed charaters for input field.</td> <td class="summary">Set allowed charaters for input field.</td>
</tr> </tr>
@ -139,6 +151,18 @@
<td class="summary">Button component</td> <td class="summary">Button component</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#current_value">current_value</a></td>
<td class="summary">Current input value with marked text</td>
</tr>
<tr>
<td class="name" nowrap><a href="#cursor_index">cursor_index</a></td>
<td class="summary">The cursor index.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#end_index">end_index</a></td>
<td class="summary">Theselection end index.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_empty">is_empty</a></td> <td class="name" nowrap><a href="#is_empty">is_empty</a></td>
<td class="summary">Is current input is empty now</td> <td class="summary">Is current input is empty now</td>
</tr> </tr>
@ -151,6 +175,14 @@
<td class="summary">Gui keyboard type for input field</td> <td class="summary">Gui keyboard type for input field</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#marked_text_width">marked_text_width</a></td>
<td class="summary">Marked text width</td>
</tr>
<tr>
<td class="name" nowrap><a href="#marked_value">marked_value</a></td>
<td class="summary">Marked text for input field.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#max_length">max_length</a></td> <td class="name" nowrap><a href="#max_length">max_length</a></td>
<td class="summary">Max length for input text</td> <td class="summary">Max length for input text</td>
</tr> </tr>
@ -164,7 +196,7 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_input_select">on_input_select</a></td> <td class="name" nowrap><a href="#on_input_select">on_input_select</a></td>
<td class="summary">On input field select callback(self, button_node)</td> <td class="summary">On input field select callback(self, input_instance)</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_input_text">on_input_text</a></td> <td class="name" nowrap><a href="#on_input_text">on_input_text</a></td>
@ -172,16 +204,36 @@
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_input_unselect">on_input_unselect</a></td> <td class="name" nowrap><a href="#on_input_unselect">on_input_unselect</a></td>
<td class="summary">On input field unselect callback(self, input_text)</td> <td class="summary">On input field unselect callback(self, input_text, input_instance)</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#on_input_wrong">on_input_wrong</a></td> <td class="name" nowrap><a href="#on_input_wrong">on_input_wrong</a></td>
<td class="summary">On trying user input with not allowed character callback(self, params, button_instance)</td> <td class="summary">On trying user input with not allowed character callback(self, params, input_text)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#on_select_cursor_change">on_select_cursor_change</a></td>
<td class="summary">On cursor position change callback(self, cursor_index, start_index, end_index)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#previous_value">previous_value</a></td>
<td class="summary">Previous input value</td>
</tr>
<tr>
<td class="name" nowrap><a href="#start_index">start_index</a></td>
<td class="summary">The selection start index.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#text">text</a></td> <td class="name" nowrap><a href="#text">text</a></td>
<td class="summary">Text component</td> <td class="summary">Text component</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#text_width">text_width</a></td>
<td class="summary">Text width</td>
</tr>
<tr>
<td class="name" nowrap><a href="#value">value</a></td>
<td class="summary">Current input value</td>
</tr>
</table> </table>
<br/> <br/>
@ -217,6 +269,37 @@
</dd>
<dt>
<a name = "get_text_selected_replaced"></a>
<strong>get_text_selected_replaced(self, text)</strong>
</dt>
<dd>
Replace selected text with new text
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Input</span></span>
<a href="../modules/Input.html#">Input</a>
</li>
<li><span class="parameter">text</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The text to replace selected text
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
New input text
</ol>
</dd> </dd>
<dt> <dt>
<a name = "init"></a> <a name = "init"></a>
@ -250,6 +333,39 @@
</dd>
<dt>
<a name = "move_selection"></a>
<strong>move_selection(self, delta, is_add_to_selection, is_move_to_end)</strong>
</dt>
<dd>
Change cursor position by delta
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Input</span></span>
<a href="../modules/Input.html#">Input</a>
</li>
<li><span class="parameter">delta</span>
<span class="types"><span class="type">number</span></span>
side for cursor position, -1 for left, 1 for right
</li>
<li><span class="parameter">is_add_to_selection</span>
<span class="types"><span class="type">boolean</span></span>
(Shift key)
</li>
<li><span class="parameter">is_move_to_end</span>
<span class="types"><span class="type">boolean</span></span>
(Ctrl key)
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "reset_changes"></a> <a name = "reset_changes"></a>
@ -267,6 +383,12 @@
</li> </li>
</ul> </ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.input</span></span>
Current input instance
</ol>
@ -292,6 +414,45 @@
</dd>
<dt>
<a name = "select_cursor"></a>
<strong>select_cursor(self, cursor_index, start_index, end_index)</strong>
</dt>
<dd>
Set cursor position in input field
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Input</span></span>
<a href="../modules/Input.html#">Input</a>
</li>
<li><span class="parameter">cursor_index</span>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
Cursor index for cursor position, if nil - will be set to the end of the text
</li>
<li><span class="parameter">start_index</span>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
Start index for cursor position, if nil - will be set to the end of the text
</li>
<li><span class="parameter">end_index</span>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
End index for cursor position, if nil - will be set to the start_index
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.input</span></span>
Current input instance
</ol>
</dd> </dd>
<dt> <dt>
<a name = "set_allowed_characters"></a> <a name = "set_allowed_characters"></a>
@ -432,10 +593,6 @@
<span class="types"><span class="type">boolean</span></span> <span class="types"><span class="type">boolean</span></span>
If true, call unselect on select selected input. Default: false If true, call unselect on select selected input. Default: false
</li> </li>
<li><span class="parameter">NO_CONSUME_INPUT_WHILE_SELECTED</span>
<span class="types"><span class="type">boolean</span></span>
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). Default: false
</li>
<li><span class="parameter">on_select</span> <li><span class="parameter">on_select</span>
<span class="types"><span class="type">function</span></span> <span class="types"><span class="type">function</span></span>
(self, button_node) Callback on input field selecting (self, button_node) Callback on input field selecting
@ -502,6 +659,66 @@
</dd>
<dt>
<a name = "current_value"></a>
<strong>current_value</strong>
</dt>
<dd>
Current input value with marked text
<ul>
<li><span class="parameter">current_value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
</dd>
<dt>
<a name = "cursor_index"></a>
<strong>cursor_index</strong>
</dt>
<dd>
The cursor index. The index of letter cursor after. Leftmost cursor - 0
<ul>
<li><span class="parameter">cursor_index</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "end_index"></a>
<strong>end_index</strong>
</dt>
<dd>
Theselection end index. The index of letter cursor before. Rightmost selection - #text
<ul>
<li><span class="parameter">end_index</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "is_empty"></a> <a name = "is_empty"></a>
@ -562,6 +779,46 @@
</dd>
<dt>
<a name = "marked_text_width"></a>
<strong>marked_text_width</strong>
</dt>
<dd>
Marked text width
<ul>
<li><span class="parameter">marked_text_width</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "marked_value"></a>
<strong>marked_value</strong>
</dt>
<dd>
Marked text for input field. Info: https://defold.com/manuals/input-key-and-text/#marked-text
<ul>
<li><span class="parameter">marked_value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "max_length"></a> <a name = "max_length"></a>
@ -628,7 +885,7 @@
<strong>on_input_select</strong> <strong>on_input_select</strong>
</dt> </dt>
<dd> <dd>
On input field select callback(self, button_node) On input field select callback(self, input_instance)
<ul> <ul>
@ -668,7 +925,7 @@
<strong>on_input_unselect</strong> <strong>on_input_unselect</strong>
</dt> </dt>
<dd> <dd>
On input field unselect callback(self, input_text) On input field unselect callback(self, input_text, input_instance)
<ul> <ul>
@ -688,7 +945,7 @@
<strong>on_input_wrong</strong> <strong>on_input_wrong</strong>
</dt> </dt>
<dd> <dd>
On trying user input with not allowed character callback(self, params, button_instance) On trying user input with not allowed character callback(self, params, input_text)
<ul> <ul>
@ -702,6 +959,66 @@
</dd>
<dt>
<a name = "on_select_cursor_change"></a>
<strong>on_select_cursor_change</strong>
</dt>
<dd>
On cursor position change callback(self, cursor_index, start_index, end_index)
<ul>
<li><span class="parameter">on_select_cursor_change</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
</dd>
<dt>
<a name = "previous_value"></a>
<strong>previous_value</strong>
</dt>
<dd>
Previous input value
<ul>
<li><span class="parameter">previous_value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
</dd>
<dt>
<a name = "start_index"></a>
<strong>start_index</strong>
</dt>
<dd>
The selection start index. The index of letter cursor after. Leftmost selection - 0
<ul>
<li><span class="parameter">start_index</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "text"></a> <a name = "text"></a>
@ -722,6 +1039,46 @@
</dd>
<dt>
<a name = "text_width"></a>
<strong>text_width</strong>
</dt>
<dd>
Text width
<ul>
<li><span class="parameter">text_width</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "value"></a>
<strong>value</strong>
</dt>
<dd>
Current input value
<ul>
<li><span class="parameter">value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
</dd> </dd>
</dl> </dl>

View File

@ -32,7 +32,6 @@
<h2>Contents</h2> <h2>Contents</h2>
<ul> <ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Fields">Fields</a></li> <li><a href="#Fields">Fields</a></li>
</ul> </ul>
@ -79,45 +78,6 @@
<p> <a href="https://insality.github.io/druid/druid/index.html?example=general_layout" target="_blank"><b>Example Link</b></a></p> <p> <a href="https://insality.github.io/druid/druid/index.html?example=general_layout" target="_blank"><b>Example Link</b></a></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#fit_into_node">fit_into_node(self, node)</a></td>
<td class="summary">Set node for layout node to fit inside it.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#fit_into_size">fit_into_size(self, target_size)</a></td>
<td class="summary">Set size for layout node to fit inside it</td>
</tr>
<tr>
<td class="name" nowrap><a href="#fit_into_window">fit_into_window(self)</a></td>
<td class="summary">Set current size for layout node to fit inside it</td>
</tr>
<tr>
<td class="name" nowrap><a href="#init">init(self, node, mode, on_size_changed_callback)</a></td>
<td class="summary">The <a href="../modules/Layout.html#">Layout</a> constructor</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_max_gui_upscale">set_max_gui_upscale(self, max_gui_upscale)</a></td>
<td class="summary">Set max gui upscale for FIT adjust mode (or side).</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_max_size">set_max_size(self, max_size)</a></td>
<td class="summary">Set maximum size of layout node</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_min_size">set_min_size(self, min_size)</a></td>
<td class="summary">Set minimal size of layout node</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_origin_position">set_origin_position(self, new_origin_position)</a></td>
<td class="summary">Set new origin position of layout node.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_origin_size">set_origin_size(self, new_origin_size)</a></td>
<td class="summary">Set new origin size of layout node.</td>
</tr>
</table>
<h2><a href="#Fields">Fields</a></h2> <h2><a href="#Fields">Fields</a></h2>
<table class="function_list"> <table class="function_list">
<tr> <tr>
@ -128,297 +88,12 @@
<td class="name" nowrap><a href="#node">node</a></td> <td class="name" nowrap><a href="#node">node</a></td>
<td class="summary">Layout node</td> <td class="summary">Layout node</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#on_size_changed">on_size_changed</a></td>
<td class="summary">On window resize callback(self, new_size)</td>
</tr>
</table> </table>
<br/> <br/>
<br/> <br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "fit_into_node"></a>
<strong>fit_into_node(self, node)</strong>
</dt>
<dd>
Set node for layout node to fit inside it. Pass nil to reset
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">node</span>
<span class="types"><a class="type" href="../modules/Layout.html#node">node</a> or <span class="type">nil</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "fit_into_size"></a>
<strong>fit_into_size(self, target_size)</strong>
</dt>
<dd>
Set size for layout node to fit inside it
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">target_size</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "fit_into_window"></a>
<strong>fit_into_window(self)</strong>
</dt>
<dd>
Set current size for layout node to fit inside it
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "init"></a>
<strong>init(self, node, mode, on_size_changed_callback)</strong>
</dt>
<dd>
The <a href="../modules/Layout.html#">Layout</a> constructor
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">node</span>
<span class="types"><a class="type" href="../modules/Layout.html#node">node</a></span>
Gui node
</li>
<li><span class="parameter">mode</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The layout mode (from const.LAYOUT_MODE)
</li>
<li><span class="parameter">on_size_changed_callback</span>
<span class="types"><span class="type">function</span> or <span class="type">nil</span></span>
The callback on window resize
</li>
</ul>
</dd>
<dt>
<a name = "set_max_gui_upscale"></a>
<strong>set_max_gui_upscale(self, max_gui_upscale)</strong>
</dt>
<dd>
Set max gui upscale for FIT adjust mode (or side). It happens on bigger render gui screen
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">max_gui_upscale</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "set_max_size"></a>
<strong>set_max_size(self, max_size)</strong>
</dt>
<dd>
Set maximum size of layout node
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">max_size</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "set_min_size"></a>
<strong>set_min_size(self, min_size)</strong>
</dt>
<dd>
Set minimal size of layout node
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">min_size</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "set_origin_position"></a>
<strong>set_origin_position(self, new_origin_position)</strong>
</dt>
<dd>
Set new origin position of layout node. You should apply this on node movement
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">new_origin_position</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
<dt>
<a name = "set_origin_size"></a>
<strong>set_origin_size(self, new_origin_size)</strong>
</dt>
<dd>
Set new origin size of layout node. You should apply this on node manual size change
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</li>
<li><span class="parameter">new_origin_size</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Layout</span></span>
<a href="../modules/Layout.html#">Layout</a>
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Fields"></a>Fields</h2> <h2 class="section-header "><a name="Fields"></a>Fields</h2>
<dl class="function"> <dl class="function">
@ -461,26 +136,6 @@
</dd>
<dt>
<a name = "on_size_changed"></a>
<strong>on_size_changed</strong>
</dt>
<dd>
On window resize callback(self, new_size)
<ul>
<li><span class="parameter">on_size_changed</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
</dd> </dd>
</dl> </dl>

View File

@ -84,20 +84,32 @@
<table class="function_list"> <table class="function_list">
<tr> <tr>
<td class="name" nowrap><a href="#get_text">get_text(self)</a></td> <td class="name" nowrap><a href="#get_text">get_text(self)</a></td>
<td class="summary">GSet input field text</td> <td class="summary">Set input field text</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#init">init(self, template, nodes)</a></td> <td class="name" nowrap><a href="#init">init(self, template, nodes)</a></td>
<td class="summary">The <a href="../modules/RichInput.html#">RichInput</a> constructor</td> <td class="summary">The <a href="../modules/RichInput.html#">RichInput</a> constructor</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#select">select(self)</a></td>
<td class="summary">Select input field</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_allowed_characters">set_allowed_characters(self, characters)</a></td> <td class="name" nowrap><a href="#set_allowed_characters">set_allowed_characters(self, characters)</a></td>
<td class="summary">Set allowed charaters for input field.</td> <td class="summary">Set allowed charaters for input field.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#set_font">set_font(self, font)</a></td>
<td class="summary">Set input field font</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_placeholder">set_placeholder(self, placeholder_text)</a></td> <td class="name" nowrap><a href="#set_placeholder">set_placeholder(self, placeholder_text)</a></td>
<td class="summary">Set placeholder text</td> <td class="summary">Set placeholder text</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#set_text">set_text(self, text)</a></td>
<td class="summary">Set input field text</td>
</tr>
</table> </table>
<h2><a href="#Fields">Fields</a></h2> <h2><a href="#Fields">Fields</a></h2>
<table class="function_list"> <table class="function_list">
@ -135,7 +147,7 @@
<strong>get_text(self)</strong> <strong>get_text(self)</strong>
</dt> </dt>
<dd> <dd>
GSet input field text Set input field text
<h3>Parameters:</h3> <h3>Parameters:</h3>
@ -146,12 +158,6 @@
</li> </li>
</ul> </ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Current input text
</ol>
@ -185,6 +191,27 @@
</dd>
<dt>
<a name = "select"></a>
<strong>select(self)</strong>
</dt>
<dd>
Select input field
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichInput</span></span>
<a href="../modules/RichInput.html#">RichInput</a>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "set_allowed_characters"></a> <a name = "set_allowed_characters"></a>
@ -218,6 +245,37 @@
</dd>
<dt>
<a name = "set_font"></a>
<strong>set_font(self, font)</strong>
</dt>
<dd>
Set input field font
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichInput</span></span>
<a href="../modules/RichInput.html#">RichInput</a>
</li>
<li><span class="parameter">font</span>
<span class="types"><span class="type">hash</span></span>
The font hash
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.input</span></span>
Current input instance
</ol>
</dd> </dd>
<dt> <dt>
<a name = "set_placeholder"></a> <a name = "set_placeholder"></a>
@ -234,16 +292,41 @@
<a href="../modules/RichInput.html#">RichInput</a> <a href="../modules/RichInput.html#">RichInput</a>
</li> </li>
<li><span class="parameter">placeholder_text</span> <li><span class="parameter">placeholder_text</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The placeholder text The placeholder text
</li> </li>
</ul> </ul>
</dd>
<dt>
<a name = "set_text"></a>
<strong>set_text(self, text)</strong>
</dt>
<dd>
Set input field text
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichInput</span></span>
<a href="../modules/RichInput.html#">RichInput</a>
</li>
<li><span class="parameter">text</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The input text
</li>
</ul>
<h3>Returns:</h3> <h3>Returns:</h3>
<ol> <ol>
<span class="types"><span class="type">RichInput</span></span> <span class="types"><span class="type">druid.input</span></span>
Current instance Current input instance
</ol> </ol>

View File

@ -150,6 +150,10 @@ type druid.rich_text.metrics = {
<h2><a href="#Functions">Functions</a></h2> <h2><a href="#Functions">Functions</a></h2>
<table class="function_list"> <table class="function_list">
<tr>
<td class="name" nowrap><a href="#characters">characters(self, word)</a></td>
<td class="summary">Split a word into it's characters</td>
</tr>
<tr> <tr>
<td class="name" nowrap><a href="#clear">clear()</a></td> <td class="name" nowrap><a href="#clear">clear()</a></td>
<td class="summary">Clear all created words.</td> <td class="summary">Clear all created words.</td>
@ -159,11 +163,15 @@ type druid.rich_text.metrics = {
<td class="summary">Get current line metrics</td> <td class="summary">Get current line metrics</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_text">get_text(self)</a></td>
<td class="summary">Get current text</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_words">get_words()</a></td> <td class="name" nowrap><a href="#get_words">get_words()</a></td>
<td class="summary">Get all current words.</td> <td class="summary">Get all current words.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#init">init(self, template, nodes)</a></td> <td class="name" nowrap><a href="#init">init(self, text_node, value)</a></td>
<td class="summary">The <a href="../modules/RichText.html#">RichText</a> constructor</td> <td class="summary">The <a href="../modules/RichText.html#">RichText</a> constructor</td>
</tr> </tr>
<tr> <tr>
@ -171,7 +179,7 @@ type druid.rich_text.metrics = {
<td class="summary">Set text for Rich Text</td> <td class="summary">Set text for Rich Text</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#tagged">tagged(tag)</a></td> <td class="name" nowrap><a href="#tagged">tagged(self, tag)</a></td>
<td class="summary">Get all words, which has a passed tag.</td> <td class="summary">Get all words, which has a passed tag.</td>
</tr> </tr>
</table> </table>
@ -188,6 +196,18 @@ type druid.rich_text.metrics = {
<td class="name" nowrap><a href="#druid">druid</a></td> <td class="name" nowrap><a href="#druid">druid</a></td>
<td class="summary">The component druid instance</td> <td class="summary">The component druid instance</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#icon_prefab">icon_prefab</a></td>
<td class="summary">The icon prefab node</td>
</tr>
<tr>
<td class="name" nowrap><a href="#root">root</a></td>
<td class="summary">The root node of the Rich Text</td>
</tr>
<tr>
<td class="name" nowrap><a href="#text_prefab">text_prefab</a></td>
<td class="summary">The text prefab node</td>
</tr>
</table> </table>
<br/> <br/>
@ -197,6 +217,37 @@ type druid.rich_text.metrics = {
<h2 class="section-header "><a name="Functions"></a>Functions</h2> <h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function"> <dl class="function">
<dt>
<a name = "characters"></a>
<strong>characters(self, word)</strong>
</dt>
<dd>
Split a word into it's characters
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichText</span></span>
<a href="../modules/RichText.html#">RichText</a>
</li>
<li><span class="parameter">word</span>
<span class="types"><span class="type">druid.rich_text.word</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.rich_text.word[]</span></span>
characters
</ol>
</dd>
<dt> <dt>
<a name = "clear"></a> <a name = "clear"></a>
<strong>clear()</strong> <strong>clear()</strong>
@ -230,6 +281,33 @@ type druid.rich_text.metrics = {
</dd>
<dt>
<a name = "get_text"></a>
<strong>get_text(self)</strong>
</dt>
<dd>
Get current text
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichText</span></span>
<a href="../modules/RichText.html#">RichText</a>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
text
</ol>
</dd> </dd>
<dt> <dt>
<a name = "get_words"></a> <a name = "get_words"></a>
@ -253,7 +331,7 @@ type druid.rich_text.metrics = {
</dd> </dd>
<dt> <dt>
<a name = "init"></a> <a name = "init"></a>
<strong>init(self, template, nodes)</strong> <strong>init(self, text_node, value)</strong>
</dt> </dt>
<dd> <dd>
The <a href="../modules/RichText.html#">RichText</a> constructor The <a href="../modules/RichText.html#">RichText</a> constructor
@ -265,13 +343,13 @@ type druid.rich_text.metrics = {
<span class="types"><span class="type">RichText</span></span> <span class="types"><span class="type">RichText</span></span>
<a href="../modules/RichText.html#">RichText</a> <a href="../modules/RichText.html#">RichText</a>
</li> </li>
<li><span class="parameter">template</span> <li><span class="parameter">text_node</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> <span class="types"><span class="type">node</span> or <a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
The Rich Text template name The text node to make Rich Text
</li> </li>
<li><span class="parameter">nodes</span> <li><span class="parameter">value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
The node table, if prefab was copied by gui.clone_tree() The initial text value. Default will be gui.get_text(text_node)
</li> </li>
</ul> </ul>
@ -295,7 +373,7 @@ type druid.rich_text.metrics = {
<a href="../modules/RichText.html#">RichText</a> <a href="../modules/RichText.html#">RichText</a>
</li> </li>
<li><span class="parameter">text</span> <li><span class="parameter">text</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
The text to set The text to set
</li> </li>
</ul> </ul>
@ -361,7 +439,7 @@ Words &lt;nobr&gt;inside tag&lt;/nobr&gt; won't <span class="keyword">break</spa
</dd> </dd>
<dt> <dt>
<a name = "tagged"></a> <a name = "tagged"></a>
<strong>tagged(tag)</strong> <strong>tagged(self, tag)</strong>
</dt> </dt>
<dd> <dd>
Get all words, which has a passed tag. Get all words, which has a passed tag.
@ -369,6 +447,10 @@ Words &lt;nobr&gt;inside tag&lt;/nobr&gt; won't <span class="keyword">break</spa
<h3>Parameters:</h3> <h3>Parameters:</h3>
<ul> <ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">RichText</span></span>
<a href="../modules/RichText.html#">RichText</a>
</li>
<li><span class="parameter">tag</span> <li><span class="parameter">tag</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
@ -444,6 +526,66 @@ Words &lt;nobr&gt;inside tag&lt;/nobr&gt; won't <span class="keyword">break</spa
</dd>
<dt>
<a name = "icon_prefab"></a>
<strong>icon_prefab</strong>
</dt>
<dd>
The icon prefab node
<ul>
<li><span class="parameter">icon_prefab</span>
<span class="types"><span class="type">node</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "root"></a>
<strong>root</strong>
</dt>
<dd>
The root node of the Rich Text
<ul>
<li><span class="parameter">root</span>
<span class="types"><span class="type">node</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "text_prefab"></a>
<strong>text_prefab</strong>
</dt>
<dd>
The text prefab node
<ul>
<li><span class="parameter">text_prefab</span>
<span class="types"><span class="type">node</span></span>
</li>
</ul>
</dd> </dd>
</dl> </dl>

View File

@ -167,6 +167,14 @@
<td class="name" nowrap><a href="#set_vertical_scroll">set_vertical_scroll(self, state)</a></td> <td class="name" nowrap><a href="#set_vertical_scroll">set_vertical_scroll(self, state)</a></td>
<td class="summary">Lock or unlock vertical scroll</td> <td class="summary">Lock or unlock vertical scroll</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#set_view_size">set_view_size(self, size)</a></td>
<td class="summary">Set new scroll view size in case the node size was changed.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#update_view_size">update_view_size(self)</a></td>
<td class="summary">Refresh scroll view size</td>
</tr>
</table> </table>
<h2><a href="#Tables">Tables</a></h2> <h2><a href="#Tables">Tables</a></h2>
<table class="function_list"> <table class="function_list">
@ -233,6 +241,10 @@
<td class="name" nowrap><a href="#view_node">view_node</a></td> <td class="name" nowrap><a href="#view_node">view_node</a></td>
<td class="summary">Scroll view node</td> <td class="summary">Scroll view node</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#view_size">view_size</a></td>
<td class="summary">Scroll view size</td>
</tr>
</table> </table>
<br/> <br/>
@ -733,6 +745,58 @@
</dd>
<dt>
<a name = "set_view_size"></a>
<strong>set_view_size(self, size)</strong>
</dt>
<dd>
Set new scroll view size in case the node size was changed.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Scroll</span></span>
<a href="../modules/Scroll.html#">Scroll</a>
</li>
<li><span class="parameter">size</span>
<span class="types"><span class="type">vector3</span></span>
The new size for view node
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.scroll</span></span>
Current scroll instance
</ol>
</dd>
<dt>
<a name = "update_view_size"></a>
<strong>update_view_size(self)</strong>
</dt>
<dd>
Refresh scroll view size
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Scroll</span></span>
<a href="../modules/Scroll.html#">Scroll</a>
</li>
</ul>
</dd> </dd>
</dl> </dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2> <h2 class="section-header "><a name="Tables"></a>Tables</h2>
@ -819,7 +883,7 @@
<ul> <ul>
<li><span class="parameter">_is_inert</span> <li><span class="parameter">_is_inert</span>
<span class="types"><span class="type">bool</span></span> <span class="types"><span class="type">boolean</span></span>
</li> </li>
</ul> </ul>
@ -1088,6 +1152,26 @@
</dd>
<dt>
<a name = "view_size"></a>
<strong>view_size</strong>
</dt>
<dd>
Scroll view size
<ul>
<li><span class="parameter">view_size</span>
<span class="types"><span class="type">vector3</span></span>
</li>
</ul>
</dd> </dd>
</dl> </dl>

View File

@ -86,10 +86,18 @@
<td class="summary">The <a href="../modules/Slider.html#">Slider</a> constructor</td> <td class="summary">The <a href="../modules/Slider.html#">Slider</a> constructor</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#is_enabled">is_enabled(self)</a></td>
<td class="summary">Check if Slider component is enabled</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set">set(self, value, is_silent)</a></td> <td class="name" nowrap><a href="#set">set(self, value, is_silent)</a></td>
<td class="summary">Set value for slider</td> <td class="summary">Set value for slider</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#set_enabled">set_enabled(self, is_enabled)</a></td>
<td class="summary">Set Slider input enabled or disabled</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_input_node">set_input_node(self, input_node)</a></td> <td class="name" nowrap><a href="#set_input_node">set_input_node(self, input_node)</a></td>
<td class="summary">Set input zone for slider.</td> <td class="summary">Set input zone for slider.</td>
</tr> </tr>
@ -177,6 +185,33 @@
</dd>
<dt>
<a name = "is_enabled"></a>
<strong>is_enabled(self)</strong>
</dt>
<dd>
Check if Slider component is enabled
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Slider</span></span>
<a href="../modules/Slider.html#">Slider</a>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
</ol>
</dd> </dd>
<dt> <dt>
<a name = "set"></a> <a name = "set"></a>
@ -206,6 +241,31 @@
</dd>
<dt>
<a name = "set_enabled"></a>
<strong>set_enabled(self, is_enabled)</strong>
</dt>
<dd>
Set Slider input enabled or disabled
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Slider</span></span>
<a href="../modules/Slider.html#">Slider</a>
</li>
<li><span class="parameter">is_enabled</span>
<span class="types"><span class="type">boolean</span></span>
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "set_input_node"></a> <a name = "set_input_node"></a>
@ -291,7 +351,7 @@
<ul> <ul>
<li><span class="parameter">dist</span> <li><span class="parameter">dist</span>
<span class="types"><span class="type">number</span></span> <span class="types"><span class="type">vector3</span></span>
</li> </li>
</ul> </ul>

View File

@ -154,9 +154,21 @@
<td class="summary">Set new in_row elements for grid</td> <td class="summary">Set new in_row elements for grid</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#set_item_size">set_item_size(self[, width[, height]])</a></td>
<td class="summary">Set new node size for grid</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_items">set_items(self, nodes[, is_instant=false])</a></td>
<td class="summary">Set new items to the grid.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#set_position_function">set_position_function(self, callback)</a></td> <td class="name" nowrap><a href="#set_position_function">set_position_function(self, callback)</a></td>
<td class="summary">Change set position function for grid nodes.</td> <td class="summary">Change set position function for grid nodes.</td>
</tr> </tr>
<tr>
<td class="name" nowrap><a href="#sort_nodes">sort_nodes(self, comparator)</a></td>
<td class="summary">Sort grid nodes by custom comparator function</td>
</tr>
</table> </table>
<h2><a href="#Tables">Tables</a></h2> <h2><a href="#Tables">Tables</a></h2>
<table class="function_list"> <table class="function_list">
@ -621,6 +633,73 @@
</dd>
<dt>
<a name = "set_item_size"></a>
<strong>set_item_size(self[, width[, height]])</strong>
</dt>
<dd>
Set new node size for grid
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">StaticGrid</span></span>
<a href="../modules/StaticGrid.html#">StaticGrid</a>
</li>
<li><span class="parameter">width</span>
<span class="types"><span class="type">number</span></span>
The new node width
(<em>optional</em>)
</li>
<li><span class="parameter">height</span>
<span class="types"><span class="type">number</span></span>
The new node height
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.static_grid</span></span>
Current grid instance
</ol>
</dd>
<dt>
<a name = "set_items"></a>
<strong>set_items(self, nodes[, is_instant=false])</strong>
</dt>
<dd>
Set new items to the grid. All previous items will be removed
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">StaticGrid</span></span>
<a href="../modules/StaticGrid.html#">StaticGrid</a>
</li>
<li><span class="parameter">nodes</span>
<span class="types"><span class="type">node[]</span></span>
The new grid nodes
</li>
<li><span class="parameter">is_instant</span>
<span class="types"><span class="type">boolean</span></span>
If true, update node positions instantly
(<em>default</em> false)
</li>
</ul>
</dd> </dd>
<dt> <dt>
<a name = "set_position_function"></a> <a name = "set_position_function"></a>
@ -653,6 +732,37 @@
</dd>
<dt>
<a name = "sort_nodes"></a>
<strong>sort_nodes(self, comparator)</strong>
</dt>
<dd>
Sort grid nodes by custom comparator function
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">StaticGrid</span></span>
<a href="../modules/StaticGrid.html#">StaticGrid</a>
</li>
<li><span class="parameter">comparator</span>
<span class="types"><span class="type">function</span></span>
The comparator function. (a, b) -> boolean
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">druid.static_grid</span></span>
Current grid instance
</ol>
</dd> </dd>
</dl> </dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2> <h2 class="section-header "><a name="Tables"></a>Tables</h2>

View File

@ -105,6 +105,10 @@
<td class="summary">Return current text adjust type</td> <td class="summary">Return current text adjust type</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="#get_text_index_by_width">get_text_index_by_width(self, width)</a></td>
<td class="summary">Get chars count by width</td>
</tr>
<tr>
<td class="name" nowrap><a href="#get_text_size">get_text_size(self, text)</a></td> <td class="name" nowrap><a href="#get_text_size">get_text_size(self, text)</a></td>
<td class="summary">Calculate text width with font with respect to trailing space</td> <td class="summary">Calculate text width with font with respect to trailing space</td>
</tr> </tr>
@ -247,6 +251,37 @@
</dd>
<dt>
<a name = "get_text_index_by_width"></a>
<strong>get_text_index_by_width(self, width)</strong>
</dt>
<dd>
Get chars count by width
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">Text</span></span>
<a href="../modules/Text.html#">Text</a>
</li>
<li><span class="parameter">width</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">number</span></span>
Chars count
</ol>
</dd> </dd>
<dt> <dt>
<a name = "get_text_size"></a> <a name = "get_text_size"></a>
@ -263,8 +298,8 @@
<a href="../modules/Text.html#">Text</a> <a href="../modules/Text.html#">Text</a>
</li> </li>
<li><span class="parameter">text</span> <li><span class="parameter">text</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
|nil
</li> </li>
</ul> </ul>
@ -302,11 +337,11 @@
</li> </li>
<li><span class="parameter">value</span> <li><span class="parameter">value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Initial text. Default value is node text from GUI scene. Initial text. Default value is node text from GUI scene. Default: nil
</li> </li>
<li><span class="parameter">adjust_type</span> <li><span class="parameter">adjust_type</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: downscale Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
</li> </li>
</ul> </ul>
@ -618,6 +653,14 @@
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span> <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
The default adjust type for any text component. Default: DOWNSCALE The default adjust type for any text component. Default: DOWNSCALE
</li> </li>
<li><span class="parameter">ADJUST_STEPS</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Amount of iterations for text adjust by height. Default: 20
</li>
<li><span class="parameter">ADJUST_SCALE_DELTA</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Scale step on each height adjust step. Default: 0.02
</li>
</ul> </ul>

View File

@ -158,7 +158,7 @@
Gui text node Gui text node
</li> </li>
<li><span class="parameter">seconds_from</span> <li><span class="parameter">seconds_from</span>
<span class="types"><span class="type">number</span></span> <span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
Start timer value in seconds Start timer value in seconds
</li> </li>
<li><span class="parameter">seconds_to</span> <li><span class="parameter">seconds_to</span>

View File

@ -0,0 +1,95 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Defold Druid UI Framework</title>
<link rel="stylesheet" href="../ldoc_fixed.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Druid</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/BackHandler.html">BackHandler</a></li>
<li><a href="../modules/BaseComponent.html">BaseComponent</a></li>
<li><a href="../modules/Blocker.html">Blocker</a></li>
<li><a href="../modules/Button.html">Button</a></li>
<li><a href="../modules/Checkbox.html">Checkbox</a></li>
<li><a href="../modules/CheckboxGroup.html">CheckboxGroup</a></li>
<li><a href="../modules/DataList.html">DataList</a></li>
<li><a href="../modules/Drag.html">Drag</a></li>
<li><a href="../modules/Druid.html">Druid</a></li>
<li><a href="../modules/DruidEvent.html">DruidEvent</a></li>
<li><a href="../modules/DruidInstance.html">DruidInstance</a></li>
<li><a href="../modules/DynamicGrid.html">DynamicGrid</a></li>
<li><a href="../modules/Helper.html">Helper</a></li>
<li><a href="../modules/Hotkey.html">Hotkey</a></li>
<li><a href="../modules/Hover.html">Hover</a></li>
<li><a href="../modules/Input.html">Input</a></li>
<li><a href="../modules/LangText.html">LangText</a></li>
<li><a href="../modules/PinKnob.html">PinKnob</a></li>
<li><a href="../modules/Progress.html">Progress</a></li>
<li><a href="../modules/RadioGroup.html">RadioGroup</a></li>
<li><a href="../modules/RichInput.html">RichInput</a></li>
<li><a href="../modules/RichText.html">RichText</a></li>
<li><a href="../modules/Scroll.html">Scroll</a></li>
<li><a href="../modules/Slider.html">Slider</a></li>
<li><a href="../modules/StaticGrid.html">StaticGrid</a></li>
<li><a href="../modules/Swipe.html">Swipe</a></li>
<li><a href="../modules/Text.html">Text</a></li>
<li><a href="../modules/Timer.html">Timer</a></li>
<li><strong>druid.extended.layout</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>druid.extended.layout</code></h1>
<p>Druid layout module
<p> <b># Overview #</b>
<p> Layout component works like Dynamic Grid before - for aligning elements in a row or column.</p>
<p> Works like a Figma layout.
<p> <b># Notes</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc TESTING</a></i>
<i style="float:right;">Last updated 2015-01-01 12:00:00 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@ -0,0 +1,93 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Defold Druid UI Framework</title>
<link rel="stylesheet" href="../ldoc_fixed.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Druid</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/BackHandler.html">BackHandler</a></li>
<li><a href="../modules/BaseComponent.html">BaseComponent</a></li>
<li><a href="../modules/Blocker.html">Blocker</a></li>
<li><a href="../modules/Button.html">Button</a></li>
<li><a href="../modules/Checkbox.html">Checkbox</a></li>
<li><a href="../modules/CheckboxGroup.html">CheckboxGroup</a></li>
<li><a href="../modules/DataList.html">DataList</a></li>
<li><a href="../modules/Drag.html">Drag</a></li>
<li><a href="../modules/Druid.html">Druid</a></li>
<li><a href="../modules/DruidEvent.html">DruidEvent</a></li>
<li><a href="../modules/DruidInstance.html">DruidInstance</a></li>
<li><a href="../modules/DynamicGrid.html">DynamicGrid</a></li>
<li><a href="../modules/Helper.html">Helper</a></li>
<li><a href="../modules/Hotkey.html">Hotkey</a></li>
<li><a href="../modules/Hover.html">Hover</a></li>
<li><a href="../modules/Input.html">Input</a></li>
<li><a href="../modules/LangText.html">LangText</a></li>
<li><a href="../modules/Layout.html">Layout</a></li>
<li><a href="../modules/PinKnob.html">PinKnob</a></li>
<li><a href="../modules/Progress.html">Progress</a></li>
<li><a href="../modules/RadioGroup.html">RadioGroup</a></li>
<li><a href="../modules/RichInput.html">RichInput</a></li>
<li><a href="../modules/RichText.html">RichText</a></li>
<li><a href="../modules/Scroll.html">Scroll</a></li>
<li><a href="../modules/Slider.html">Slider</a></li>
<li><a href="../modules/StaticGrid.html">StaticGrid</a></li>
<li><a href="../modules/Swipe.html">Swipe</a></li>
<li><a href="../modules/Text.html">Text</a></li>
<li><a href="../modules/Timer.html">Timer</a></li>
<li><strong>druid.system.utf8</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>druid.system.utf8</code></h1>
<p></p>
<p></p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc TESTING</a></i>
<i style="float:right;">Last updated 2015-01-01 12:00:00 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@ -17,18 +17,11 @@ local component = require("druid.component")
---@class component_name: druid.base_component ---@class component_name: druid.base_component
local Component = component.create("component_name") local Component = component.create("component_name")
local SCHEME = {
ROOT = "root",
BUTTON = "button",
}
function Component:init(template, nodes) function Component:init(template, nodes)
self:set_template(template) self.druid = self:get_druid(template, nodes)
self:set_nodes(nodes) self.root = self:get_node("root")
self.root = self:get_node(SCHEME.ROOT)
self.druid = self:get_druid()
self.button = self.druid:new_button(SCHEME.BUTTON, function() end) self.button = self.druid:new_button("button", function() end)
end end
function Component:on_remove() end function Component:on_remove() end
@ -45,16 +38,10 @@ local component = require("druid.component")
---@class component_name: druid.base_component ---@class component_name: druid.base_component
local Component = component.create("component_name") local Component = component.create("component_name")
local SCHEME = {
ROOT = "root",
BUTTON = "button",
}
function Component:init(template, nodes) function Component:init(template, nodes)
self:set_template(template) self.druid = self:get_druid(template, nodes)
self:set_nodes(nodes) self.root = self:get_node("root")
self.root = self:get_node(SCHEME.ROOT)
self.druid = self:get_druid()
end end
function Component:update(dt) end function Component:update(dt) end
@ -92,7 +79,7 @@ local my_component = require("my.amazing.component")
function init(self) function init(self)
self.druid = druid.new(self) self.druid = druid.new(self)
self.druid:new(my_component, "template_name", nodes) self.druid:new(my_component, "template_name")
end end
``` ```
@ -107,6 +94,7 @@ local druid = require("druid.druid")
local my_component = require("my.amazing.component") local my_component = require("my.amazing.component")
function init(self) function init(self)
-- Register makes a "druid:new_{component_name}" function available
druid.register("my_component", my_component) druid.register("my_component", my_component)
end end
``` ```
@ -149,33 +137,6 @@ Available keywords:
uid Timer](01-components.md#timer) component. uid Timer](01-components.md#timer) component.
## Best Practices for Custom Components
When working with each component, it's recommended to describe the component scheme in the following way:
```lua
-- Component module
local component = require("druid.component")
local M = component.create("your_component")
local SCHEME = {
ROOT = "root",
ITEM = "item",
TITLE = "title"
}
function M.init(self, template_name, node_table)
self:set_template(template_name)
self:set_nodes(node_table)
local root = self:get_node(SCHEME.ROOT)
local druid = self:get_druid()
-- Create components inside this component using the inner druid instance
end
```
## The Power of Using Templates ## The Power of Using Templates
With Druid, you can use a single component but create and customize templates for it. Templates only need to match the component scheme. For example, you can have a component named `player_panel` and two GUI templates named `player_panel` and `enemy_panel` with different layouts. The same component script can be used for both templates. With Druid, you can use a single component but create and customize templates for it. Templates only need to match the component scheme. For example, you can have a component named `player_panel` and two GUI templates named `player_panel` and `enemy_panel` with different layouts. The same component script can be used for both templates.

View File

@ -367,6 +367,12 @@ function druid__data_list.scroll_to_index(self, index) end
---@return druid.data_list Current DataList instance ---@return druid.data_list Current DataList instance
function druid__data_list.set_data(self, data) end function druid__data_list.set_data(self, data) end
--- Set refresh function for DataList component
---@param self druid.data_list @{DataList}
---@param 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
---@return druid.data_list Current DataList instance
function druid__data_list.set_use_cache(self, is_use_cache) end
---@class druid.drag : druid.base_component ---@class druid.drag : druid.base_component
---@field can_x boolean Is drag component process vertical dragging. ---@field can_x boolean Is drag component process vertical dragging.
@ -374,8 +380,8 @@ function druid__data_list.set_data(self, data) end
---@field is_drag boolean Is component now dragging ---@field is_drag boolean Is component now dragging
---@field is_touch boolean Is component now touching ---@field is_touch boolean Is component now touching
---@field node node Drag node ---@field node node Drag node
---@field on_drag druid.event on drag progress callback(self, dx, dy, total_x, total_y) ---@field on_drag druid.event on drag progress callback(self, dx, dy, total_x, total_y, touch)
---@field on_drag_end druid.event Event on drag end callback(self, total_x, total_y) ---@field on_drag_end druid.event Event on drag end callback(self, total_x, total_y, touch)
---@field on_drag_start druid.event Event on drag start callback(self, touch) ---@field on_drag_start druid.event Event on drag start callback(self, touch)
---@field on_touch_end druid.event Event on touch end callback(self) ---@field on_touch_end druid.event Event on touch end callback(self)
---@field on_touch_start druid.event Event on touch start callback(self) ---@field on_touch_start druid.event Event on touch start callback(self)
@ -559,7 +565,8 @@ function druid__event.unsubscribe(self, callback, callback_context) end
---@field button druid.button Button component from click_node ---@field button druid.button Button component from click_node
---@field click_node node|nil Button trigger node ---@field click_node node|nil Button trigger node
---@field node node Visual node ---@field node node Visual node
---@field on_change_state druid.event On change state callback(self, state) ---@field on_hotkey_pressed druid.event On hotkey released callback(self, argument)
---@field on_hotkey_released druid.event On hotkey released callback(self, argument)
---@field style druid.hotkey.style Component style params. ---@field style druid.hotkey.style Component style params.
local druid__hotkey = {} local druid__hotkey = {}
@ -803,67 +810,8 @@ function druid__lang_text.translate(self, locale_id, a, b, c, d, e, f, g) end
---@class druid.layout : druid.base_component ---@class druid.layout : druid.base_component
---@field mode string Current layout mode ---@field mode string Current layout mode
---@field node node Layout node ---@field node node Layout node
---@field on_size_changed druid.event On window resize callback(self, new_size)
local druid__layout = {} local druid__layout = {}
--- Set node for layout node to fit inside it.
--- Pass nil to reset
---@param self druid.layout @{Layout}
---@param node node|nil
---@return druid.layout @{Layout}
function druid__layout.fit_into_node(self, node) end
--- Set size for layout node to fit inside it
---@param self druid.layout @{Layout}
---@param target_size vector3
---@return druid.layout @{Layout}
function druid__layout.fit_into_size(self, target_size) end
--- Set current size for layout node to fit inside it
---@param self druid.layout @{Layout}
---@return druid.layout @{Layout}
function druid__layout.fit_into_window(self) end
--- The @{Layout} constructor
---@param self druid.layout @{Layout}
---@param node node Gui node
---@param mode string The layout mode (from const.LAYOUT_MODE)
---@param on_size_changed_callback function|nil The callback on window resize
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
---@param self druid.layout @{Layout}
---@param max_size vector3
---@return druid.layout @{Layout}
function druid__layout.set_max_size(self, max_size) end
--- Set minimal size of layout node
---@param self druid.layout @{Layout}
---@param min_size vector3
---@return druid.layout @{Layout}
function druid__layout.set_min_size(self, min_size) end
--- Set new origin position of layout node.
--- You should apply this on node movement
---@param self druid.layout @{Layout}
---@param new_origin_position vector3
---@return druid.layout @{Layout}
function druid__layout.set_origin_position(self, new_origin_position) end
--- Set new origin size of layout node.
--- You should apply this on node manual size change
---@param self druid.layout @{Layout}
---@param new_origin_size vector3
---@return druid.layout @{Layout}
function druid__layout.set_origin_size(self, new_origin_size) end
---@class druid.pin_knob : druid.base_component ---@class druid.pin_knob : druid.base_component
---@field druid druid_instance The component druid instance ---@field druid druid_instance The component druid instance
@ -1056,9 +1004,9 @@ function druid__rich_text.get_words() end
--- The @{RichText} constructor --- The @{RichText} constructor
---@param self druid.rich_text @{RichText} ---@param self druid.rich_text @{RichText}
---@param template string The Rich Text template name ---@param text_node node|string The text node to make Rich Text
---@param nodes table The node table, if prefab was copied by gui.clone_tree() ---@param value string|nil The initial text value. Default will be gui.get_text(text_node)
function druid__rich_text.init(self, template, nodes) end function druid__rich_text.init(self, text_node, value) end
--- Set text for Rich Text --- Set text for Rich Text
---@param self druid.rich_text @{RichText} ---@param self druid.rich_text @{RichText}
@ -1097,6 +1045,7 @@ local druid__rich_text__style = {}
---@field style druid.scroll.style Component style params. ---@field style druid.scroll.style Component style params.
---@field target_position vector3 Current scroll target position ---@field target_position vector3 Current scroll target position
---@field view_node node Scroll view node ---@field view_node node Scroll view node
---@field view_size vector3 Scroll view size
local druid__scroll = {} local druid__scroll = {}
--- Bind the grid component (Static or Dynamic) to recalculate scroll size on grid changes --- Bind the grid component (Static or Dynamic) to recalculate scroll size on grid changes
@ -1205,6 +1154,10 @@ function druid__scroll.set_vertical_scroll(self, state) end
---@return druid.scroll Current scroll instance ---@return druid.scroll Current scroll instance
function druid__scroll.set_view_size(self, size) end function druid__scroll.set_view_size(self, size) end
--- Refresh scroll view size
---@param self druid.scroll @{Scroll}
function druid__scroll.update_view_size(self) end
---@class druid.scroll.style ---@class druid.scroll.style
---@field ANIM_SPEED number|nil Scroll gui.animation speed for scroll_to function. Default: 2 ---@field ANIM_SPEED number|nil Scroll gui.animation speed for scroll_to function. Default: 2
@ -1550,7 +1503,7 @@ local druid__timer = {}
--- The @{Timer} constructor --- The @{Timer} constructor
---@param self druid.timer @{Timer} ---@param self druid.timer @{Timer}
---@param node node Gui text node ---@param node node Gui text node
---@param seconds_from number Start timer value in seconds ---@param seconds_from number|nil Start timer value in seconds
---@param seconds_to number|nil End timer value in seconds ---@param seconds_to number|nil End timer value in seconds
---@param callback function|nil Function on timer end ---@param callback function|nil Function on timer end
function druid__timer.init(self, node, seconds_from, seconds_to, callback) end function druid__timer.init(self, node, seconds_from, seconds_to, callback) end
@ -1579,14 +1532,6 @@ local druid_instance = {}
---@param self druid_instance ---@param self druid_instance
function druid_instance.final(self) end function druid_instance.final(self) end
--- Create new component.
---@generic T
---@param self druid_instance
---@param component T Component module
---@param ... any Other component params to pass it to component:init function
---@return T Component instance
function druid_instance.new(self, component, ...) end
--- Create @{BackHandler} component --- Create @{BackHandler} component
---@param self druid_instance ---@param self druid_instance
---@param callback function|nil @The callback(self, custom_args) to call on back event ---@param callback function|nil @The callback(self, custom_args) to call on back event
@ -1683,9 +1628,8 @@ function druid_instance.new_lang_text(self, node, locale_id, adjust_type) end
---@param self druid_instance ---@param self druid_instance
---@param node string|node The_node id or gui.get_node(node_id). ---@param node string|node The_node id or gui.get_node(node_id).
---@param mode string The layout mode ---@param mode string The layout mode
---@param on_size_changed_callback function|nil The callback on window resize
---@return druid.layout @{Layout} component ---@return druid.layout @{Layout} component
function druid_instance.new_layout(self, node, mode, on_size_changed_callback) end function druid_instance.new_layout(self, node, mode) end
--- Create @{Progress} component --- Create @{Progress} component
---@param self druid_instance ---@param self druid_instance
@ -1752,7 +1696,7 @@ function druid_instance.new_text(self, node, value, no_adjust) end
--- Create @{Timer} component --- Create @{Timer} component
---@param self druid_instance ---@param self druid_instance
---@param node string|node Gui text node ---@param node string|node Gui text node
---@param seconds_from number|nil Start timer value in seconds ---@param seconds_from number Start timer value in seconds
---@param seconds_to number|nil End timer value in seconds ---@param seconds_to number|nil End timer value in seconds
---@param callback function|nil Function on timer end ---@param callback function|nil Function on timer end
---@return druid.timer @{Timer} component ---@return druid.timer @{Timer} component
@ -2021,3 +1965,22 @@ function helper.table_to_string(t) end
---@field height number ---@field height number
---@field max_ascent number ---@field max_ascent number
---@field max_descent number ---@field max_descent number
---@class utf8
---@field len fun(string: string): number
---@field sub fun(string: string, i: number, j: number): string
---@field gmatch fun(string: string, pattern: string): fun(): string
---@field gsub fun(string: string, pattern: string, repl: string, n: number): string
---@field char fun(...: number): string
---@field byte fun(string: string, i: number, j: number): number
---Add generics to some functions.
---Create new component.
---@generic T: druid.base_component
---@param self druid_instance
---@param component T Component module
---@param ... any Other component params to pass it to component:init function
---@return T Component instance
function druid_instance.new(self, component, ...) end

View File

@ -344,10 +344,6 @@ function Button.on_input(self, action_id, action)
return false return false
end end
if not self:is_enabled() then
return false
end
local is_consume = true local is_consume = true
local is_pick = true local is_pick = true
local is_key_trigger = (action_id == self.key_trigger) local is_key_trigger = (action_id == self.key_trigger)

View File

@ -22,10 +22,10 @@
--- Event on drag start callback(self, touch) --- Event on drag start callback(self, touch)
-- @tfield DruidEvent on_drag_start @{DruidEvent} -- @tfield DruidEvent on_drag_start @{DruidEvent}
--- on drag progress callback(self, dx, dy, total_x, total_y) --- on drag progress callback(self, dx, dy, total_x, total_y, touch)
-- @tfield DruidEvent on_drag Event @{DruidEvent} -- @tfield DruidEvent on_drag Event @{DruidEvent}
--- Event on drag end callback(self, total_x, total_y) --- Event on drag end callback(self, total_x, total_y, touch)
-- @tfield DruidEvent on_drag_end @{DruidEvent} -- @tfield DruidEvent on_drag_end @{DruidEvent}
--- Is component now touching --- Is component now touching

View File

@ -50,6 +50,9 @@
--- Scroll view node --- Scroll view node
-- @tfield node view_node -- @tfield node view_node
--- Scroll view size
-- @tfield vector3 view_size
--- Scroll content node --- Scroll content node
-- @tfield node content_node -- @tfield node content_node

View File

@ -211,6 +211,9 @@ local function update_text_with_trim(self, trim_postfix)
text_length = text_length - 1 text_length = text_length - 1
new_text = utf8.sub(self.last_value, 1, text_length) new_text = utf8.sub(self.last_value, 1, text_length)
text_width = self:get_text_size(new_text .. trim_postfix) text_width = self:get_text_size(new_text .. trim_postfix)
if text_length == 0 then
break
end
end end
gui.set_text(self.node, new_text .. trim_postfix) gui.set_text(self.node, new_text .. trim_postfix)

View File

@ -227,7 +227,7 @@ function M._fill_properties(word, metrics, settings)
else else
-- Text properties -- Text properties
word.scale = settings.scale * word.relative_scale * settings.adjust_scale word.scale = settings.scale * word.relative_scale * settings.adjust_scale
word.pivot = gui.PIVOT_W -- With this pivot adjustments works correctly, but with another some misalignment word.pivot = gui.PIVOT_SW -- With this pivot adjustments works more correctly than with other pivots
word.size = vmath.vector3(metrics.width, metrics.height, 0) word.size = vmath.vector3(metrics.width, metrics.height, 0)
word.offset = vmath.vector3(metrics.offset_x, metrics.offset_y, 0) word.offset = vmath.vector3(metrics.offset_x, metrics.offset_y, 0)
end end

View File

@ -1,45 +0,0 @@
fonts {
name: "game"
font: "/example/assets/fonts/game.font"
}
textures {
name: "items"
texture: "/example/assets/images/kenney.atlas"
}
nodes {
size {
x: 400.0
y: 100.0
}
type: TYPE_BOX
id: "root"
inherit_alpha: true
visible: false
}
nodes {
position {
x: -200.0
}
size {
x: 400.0
y: 100.0
}
type: TYPE_TEXT
text: "Rich text"
font: "game"
id: "text_prefab"
pivot: PIVOT_W
parent: "root"
inherit_alpha: true
outline_alpha: 0.0
shadow_alpha: 0.0
}
nodes {
type: TYPE_BOX
id: "icon_prefab"
parent: "root"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

View File

@ -109,8 +109,8 @@ local RichText = component.create("rich_text")
--- The @{RichText} constructor --- The @{RichText} constructor
-- @tparam RichText self @{RichText} -- @tparam RichText self @{RichText}
-- @tparam string template The Rich Text template name -- @tparam node|string text_node The text node to make Rich Text
-- @tparam table nodes The node table, if prefab was copied by gui.clone_tree() -- @tparam string|nil value The initial text value. Default will be gui.get_text(text_node)
function RichText.init(self, text_node, value) function RichText.init(self, text_node, value)
self.root = self:get_node(text_node) self.root = self:get_node(text_node)
self.text_prefab = self.root self.text_prefab = self.root

View File

@ -25,35 +25,6 @@ end
function M.get_commands() function M.get_commands()
return { return {
{
label = "Print GUI Scheme",
locations = { "Outline" },
query = {
selection = {type = "outline", cardinality = "many"}
},
active = function(opts)
return true
end,
run = function(opts)
print("local SCHEME = {")
for i = 1, #opts.selection do
local file = opts.selection[i]
if editor.can_get(file, "id") then
local id = editor.get(file, "id")
print("\t" .. string.upper(id) .. " = \"" .. id .. "\",")
end
end
print("}")
print("")
end
},
{ {
label = "Assign layers", label = "Assign layers",

View File

@ -84,6 +84,8 @@ end
--- Set refresh function for DataList component --- Set refresh function for DataList component
-- @tparam DataList self @{DataList} -- @tparam DataList self @{DataList}
-- @tparam boolean is_use_cache Use cache version of DataList. Requires make setup of components in on_element_add callback and clean in on_element_remove
-- @treturn druid.data_list Current DataList instance
function DataList.set_use_cache(self, is_use_cache) function DataList.set_use_cache(self, is_use_cache)
self._is_use_cache = is_use_cache self._is_use_cache = is_use_cache
return self return self
@ -280,7 +282,7 @@ end
function DataList._refresh(self) function DataList._refresh(self)
self.scroll:set_size(self.grid:get_size_for(#self._data)) self.scroll:set_size(self.grid:get_size_for(#self._data))
local start_pos = -self.scroll.position local start_pos = -self.scroll.position --[[@as vector3]]
local start_index = self.grid:get_index(start_pos) local start_index = self.grid:get_index(start_pos)
start_index = math.max(1, start_index) start_index = math.max(1, start_index)

View File

@ -1,392 +0,0 @@
local helper = require("druid.helper")
local component = require("druid.component")
---@class druid.figma_layout.row_data
---@field width number
---@field height number
---@field count number
---@class druid.figma_layout.rows_data
---@field total_width number
---@field total_height number
---@field nodes_width table<node, number>
---@field nodes_height table<node, number>
---@field rows druid.figma_layout.row_data[]>
---@class druid.figma_layout: druid.base_component
local M = component.create("layout")
--- The @{Layout} constructor
-- @tparam Layout self @{Layout}
-- @tparam node node Gui node
-- @tparam string layout_type The layout mode (from const.LAYOUT_MODE)
-- @tparam function|nil on_size_changed_callback The callback on window resize
function M:init(node, layout_type)
self.node = self:get_node(node)
print(self.node)
self.is_dirty = true
self.entities = {}
self.margin = { x = 0, y = 0 }
self.padding = gui.get_slice9(self.node)
self.type = layout_type or "horizontal"
self.is_resize_width = false
self.is_resize_height = false
self.is_justify = false
end
function M:update()
if not self.is_dirty then
return
end
self:refresh_layout()
end
---@param margin_x number|nil
---@param margin_y number|nil
---@return druid.figma_layout
function M:set_margin(margin_x, margin_y)
self.margin.x = margin_x or self.margin.x
self.margin.y = margin_y or self.margin.y
self.is_dirty = true
return self
end
---@param padding vector4 The vector4 with padding values, where x - left, y - top, z - right, w - bottom
function M:set_padding(padding)
self.padding = padding
self.is_dirty = true
return self
end
function M:set_dirty()
self.is_dirty = true
return self
end
---@param is_justify boolean
---@return druid.figma_layout
function M:set_justify(is_justify)
self.is_justify = is_justify
self.is_dirty = true
return self
end
---@param type string The layout type: "horizontal", "vertical", "horizontal_wrap"
function M:set_type(type)
self.type = type
self.is_dirty = true
return self
end
---@param is_hug_width boolean
---@param is_hug_height boolean
---@return druid.figma_layout
function M:set_hug_content(is_hug_width, is_hug_height)
self.is_resize_width = is_hug_width or false
self.is_resize_height = is_hug_height or false
self.is_dirty = true
return self
end
---@param node_or_node_id string|node
---@return druid.figma_layout
function M:add(node_or_node_id)
-- Acquire node from entity or by id
local node = node_or_node_id
if type(node_or_node_id) == "table" then
assert(node_or_node_id.node, "The entity should have a node")
node = node_or_node_id.node
else
---@cast node_or_node_id string|node
node = self:get_node(node_or_node_id)
end
---@cast node node
table.insert(self.entities, node)
gui.set_parent(node, self.node)
self.is_dirty = true
return self
end
---@return druid.figma_layout
function M:refresh_layout()
local layout_node = self.node
local entities = self.entities
local type = self.type -- vertical, horizontal, horizontal_wrap
local margin = self.margin -- {x: horizontal, y: vertical} in pixels, between elements
local padding = self.padding -- {x: left, y: top, z: right, w: bottom} in pixels
local is_justify = self.is_justify
local size = gui.get_size(layout_node)
local max_width = size.x - padding.x - padding.z
local max_height = size.y - padding.y - padding.w
local layout_pivot_offset = helper.get_pivot_offset(gui.get_pivot(layout_node)) -- {x: -0.5, y: -0.5} - is left bot, {x: 0.5, y: 0.5} - is right top
local rows_data = self:calculate_rows_data()
local rows = rows_data.rows
local row_index = 1
local row = rows[row_index]
-- Current x and Current y is a top left corner of the node
local current_x = -row.width * (0.5 + layout_pivot_offset.x)
local current_y = rows_data.total_height * (0.5 - layout_pivot_offset.y)
if is_justify then
if (type == "horizontal" or type == "horizontal_wrap") and row.count > 1 then
current_x = -max_width * (0.5 + layout_pivot_offset.x)
end
if type == "vertical" then
current_y = max_height * (0.5 - layout_pivot_offset.y)
end
end
for index = 1, #entities do
local node = entities[index]
local node_width = rows_data.nodes_width[node]
local node_height = rows_data.nodes_height[node]
local pivot_offset = helper.get_pivot_offset(gui.get_pivot(node))
if node_width > 0 and node_height > 0 then
-- Calculate position for current node
local position_x, position_y
if type == "horizontal" then
position_x = current_x + node_width * (0.5 + pivot_offset.x)
position_y = current_y - row.height * (0.5 - pivot_offset.y)
local node_margin = margin.x
if is_justify and row.count > 1 then
node_margin = (max_width - row.width) / (row.count - 1) + margin.x
end
current_x = current_x + node_width + node_margin
end
if type == "vertical" then
position_x = current_x + row.width * (0.5 - pivot_offset.x)
position_y = current_y - node_height * (0.5 + pivot_offset.y)
local node_margin = margin.y
if is_justify then
node_margin = (max_height - rows_data.total_height) / (#rows - 1) + margin.y
end
current_y = current_y - node_height - node_margin
end
if type == "horizontal_wrap" then
local width = row.width
if is_justify and row.count > 0 then
width = math.max(row.width, max_width)
end
local new_row_width = width * (0.5 - layout_pivot_offset.x)
-- Compare with eps due the float loss and element flickering
if current_x + node_width - new_row_width > 0.0001 then
if row_index < #rows then
row_index = row_index + 1
row = rows[row_index]
end
current_x = -row.width * (0.5 + layout_pivot_offset.x)
current_y = current_y - row.height - margin.y
if is_justify and row.count > 1 then
current_x = -max_width * (0.5 + layout_pivot_offset.x)
end
end
position_x = current_x + node_width * (0.5 + pivot_offset.x)
position_y = current_y - row.height * (0.5 - pivot_offset.y)
local node_margin = margin.x
if is_justify and row.count > 1 then
node_margin = (max_width - row.width) / (row.count - 1) + margin.x
end
current_x = current_x + node_width + node_margin
end
do -- Padding offset
if layout_pivot_offset.x == -0.5 then
position_x = position_x + padding.x
end
if layout_pivot_offset.y == 0.5 then
position_y = position_y - padding.y
end
if layout_pivot_offset.x == 0.5 then
position_x = position_x - padding.z
end
if layout_pivot_offset.y == -0.5 then
position_y = position_y + padding.w
end
end
self:set_node_position(node, position_x, position_y)
end
end
if self.is_resize_width or self.is_resize_height then
if self.is_resize_width then
size.x = rows_data.total_width + padding.x + padding.z
end
if self.is_resize_height then
size.y = rows_data.total_height + padding.y + padding.w
end
gui.set_size(layout_node, size)
end
self.is_dirty = false
return self
end
---@return druid.figma_layout
function M:clear_layout()
for index = #self.entities, 1, -1 do
self.entities[index] = nil
end
self.is_dirty = true
return self
end
---@param node node
---@return number, number
function M.get_node_size(node)
if not gui.is_enabled(node, false) then
return 0, 0
end
local scale = gui.get_scale(node)
-- If node has text - get text size instead of node size
if gui.get_text(node) then
local text_metrics = helper.get_text_metrics_from_node(node)
return text_metrics.width * scale.x, text_metrics.height * scale.y
end
local size = gui.get_size(node)
return size.x * scale.x, size.y * scale.y
end
---Calculate rows data for layout. Contains total width, height and rows info (width, height, count of elements in row)
---@private
---@return druid.figma_layout.rows_data
function M:calculate_rows_data()
local entities = self.entities
local margin = self.margin
local type = self.type
local padding = self.padding
local size = gui.get_size(self.node)
local max_width = size.x - padding.x - padding.z
-- Collect rows info about width, height and count of elements in row
local current_row = { width = 0, height = 0, count = 0 }
local rows_data = {
total_width = 0,
total_height = 0,
nodes_width = {},
nodes_height = {},
rows = { current_row }
}
for index = 1, #entities do
local node = entities[index]
local node_width = rows_data.nodes_width[node]
local node_height = rows_data.nodes_height[node]
-- Get node size if it's not calculated yet
if not node_width or not node_height then
node_width, node_height = M.get_node_size(node)
rows_data.nodes_width[node] = node_width
rows_data.nodes_height[node] = node_height
end
if node_width > 0 and node_height > 0 then
if type == "horizontal" then
current_row.width = current_row.width + node_width + margin.x
current_row.height = math.max(current_row.height, node_height)
current_row.count = current_row.count + 1
end
if type == "vertical" then
if current_row.count > 0 then
current_row = { width = 0, height = 0, count = 0 }
table.insert(rows_data.rows, current_row)
end
current_row.width = math.max(current_row.width, node_width + margin.x)
current_row.height = node_height
current_row.count = current_row.count + 1
end
if type == "horizontal_wrap" then
if current_row.width + node_width > max_width and current_row.count > 0 then
current_row = { width = 0, height = 0, count = 0 }
table.insert(rows_data.rows, current_row)
end
current_row.width = current_row.width + node_width + margin.x
current_row.height = math.max(current_row.height, node_height)
current_row.count = current_row.count + 1
end
end
end
-- Remove last margin of each row
-- Calculate total width and height
local rows_count = #rows_data.rows
for index = 1, rows_count do
local row = rows_data.rows[index]
if row.width > 0 then
row.width = row.width - margin.x
end
rows_data.total_width = math.max(rows_data.total_width, row.width)
rows_data.total_height = rows_data.total_height + row.height
end
rows_data.total_height = rows_data.total_height + margin.y * (rows_count - 1)
return rows_data
end
---@private
---@param node node
---@param x number
---@param y number
---@return node
function M:set_node_position(node, x, y)
local position = gui.get_position(node)
position.x = x
position.y = y
gui.set_position(node, position)
return node
end
return M

View File

@ -27,7 +27,6 @@
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.component") local component = require("druid.component")
local Event = require("druid.event") local Event = require("druid.event")
local const = require("druid.const")
local Hotkey = component.create("hotkey") local Hotkey = component.create("hotkey")

View File

@ -1,4 +1,4 @@
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license -- Copyright (c) 2024 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
--- Layout management on node --- Layout management on node
-- --
@ -13,205 +13,406 @@
--- Current layout mode --- Current layout mode
-- @tfield string mode -- @tfield string mode
---On window resize callback(self, new_size)
-- @tfield DruidEvent on_size_changed @{DruidEvent}
--- ---
local const = require("druid.const")
local helper = require("druid.helper") local helper = require("druid.helper")
local component = require("druid.component") local component = require("druid.component")
local Event = require("druid.event")
-- @class druid.layout.row_data
-- @tfield width number
-- @tfield height number
-- @tfield count number
local Layout = component.create("layout") -- @class druid.layout.rows_data
-- @tfield total_width number
-- @tfield total_height number
-- @tfield nodes_width table<node, number>
-- @tfield nodes_height table<node, number>
-- @tfield rows druid.layout.row_data[]>
-- @class druid.layout: druid.base_component
local M = component.create("layout")
--- The @{Layout} constructor -- The @{Layout} constructor
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam node node Gui node -- @tparam node node Gui node
-- @tparam string mode The layout mode (from const.LAYOUT_MODE) -- @tparam string layout_type The layout mode (from const.LAYOUT_MODE)
-- @tparam function|nil on_size_changed_callback The callback on window resize -- @tparam function|nil on_size_changed_callback The callback on window resize
function Layout.init(self, node, mode, on_size_changed_callback) function M.init(self, node, layout_type)
self.node = self:get_node(node) self.node = self:get_node(node)
self._min_size = nil self.is_dirty = true
self._max_size = nil self.entities = {}
self._current_size = vmath.vector3(0) self.margin = { x = 0, y = 0 }
self._inited = false self.padding = gui.get_slice9(self.node)
self._max_gui_upscale = nil self.type = layout_type or "horizontal"
self._fit_node = nil self.is_resize_width = false
self.is_resize_height = false
self._anchors = {} self.is_justify = false
self.mode = mode or const.LAYOUT_MODE.FIT
self.on_size_changed = Event(on_size_changed_callback)
end end
function M:update()
function Layout.on_late_init(self) if not self.is_dirty then
self._inited = true
self.origin_size = self.origin_size or gui.get_size(self.node)
self.fit_size = self.fit_size or vmath.vector3(self.origin_size)
self.pivot = helper.get_pivot_offset(gui.get_pivot(self.node))
self.origin_position = gui.get_position(self.node)
self.position = vmath.vector3(self.origin_position)
gui.set_size_mode(self.node, gui.SIZE_MODE_MANUAL)
gui.set_adjust_mode(self.node, gui.ADJUST_FIT)
self:on_window_resized()
end
function Layout.on_window_resized(self)
if not self._inited then
return return
end end
local x_koef, y_koef = helper.get_screen_aspect_koef() self:refresh_layout()
local revert_scale = 1
if self._max_gui_upscale then
revert_scale = self._max_gui_upscale / helper.get_gui_scale()
revert_scale = math.min(revert_scale, 1)
end
gui.set_scale(self.node, vmath.vector3(revert_scale))
if self._fit_node then
self.fit_size = gui.get_size(self._fit_node)
self.fit_size.x = self.fit_size.x / x_koef
self.fit_size.y = self.fit_size.y / y_koef
end
x_koef = self.fit_size.x / self.origin_size.x * x_koef
y_koef = self.fit_size.y / self.origin_size.y * y_koef
local new_size = vmath.vector3(self.origin_size)
if self.mode == const.LAYOUT_MODE.STRETCH then
new_size.x = new_size.x * x_koef / revert_scale
new_size.y = new_size.y * y_koef / revert_scale
end
if self.mode == const.LAYOUT_MODE.STRETCH_X then
new_size.x = new_size.x * x_koef / revert_scale
end
if self.mode == const.LAYOUT_MODE.STRETCH_Y then
new_size.y = new_size.y * y_koef / revert_scale
end
-- Fit to the stretched container (node size or other defined)
if self.mode == const.LAYOUT_MODE.ZOOM_MIN then
new_size = new_size * math.min(x_koef, y_koef)
end
if self.mode == const.LAYOUT_MODE.ZOOM_MAX then
new_size = new_size * math.max(x_koef, y_koef)
end
if self._min_size then
new_size.x = math.max(new_size.x, self._min_size.x)
new_size.y = math.max(new_size.y, self._min_size.y)
end
if self._max_size then
new_size.x = math.min(new_size.x, self._max_size.x)
new_size.y = math.min(new_size.y, self._max_size.y)
end
self._current_size = new_size
gui.set_size(self.node, new_size)
self.position.x = self.origin_position.x + self.origin_position.x * (x_koef - 1)
self.position.y = self.origin_position.y + self.origin_position.y * (y_koef - 1)
gui.set_position(self.node, self.position)
self.on_size_changed:trigger(self:get_context(), new_size)
end end
--- Set minimal size of layout node
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam vector3 min_size -- @tparam number|nil margin_x
-- @treturn Layout @{Layout} -- @tparam number|nil margin_y
function Layout.set_min_size(self, min_size) -- @treturn druid.layout @{Layout}
self._min_size = min_size function M.set_margin(self, margin_x, margin_y)
self.margin.x = margin_x or self.margin.x
self.margin.y = margin_y or self.margin.y
self.is_dirty = true
return self return self
end end
--- Set maximum size of layout node
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam vector3 max_size -- @tparam vector4 padding The vector4 with padding values, where x - left, y - top, z - right, w - bottom
-- @treturn Layout @{Layout} -- @treturn druid.layout @{Layout}
function Layout.set_max_size(self, max_size) function M.set_padding(self, padding)
self._max_size = max_size self.padding = padding
self.is_dirty = true
return self return self
end end
--- Set new origin position of layout node. You should apply this on node movement
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam vector3 new_origin_position -- @treturn druid.layout @{Layout}
-- @treturn Layout @{Layout} function M.set_dirty(self)
function Layout.set_origin_position(self, new_origin_position) self.is_dirty = true
self.origin_position = new_origin_position or self.origin_position
self:on_window_resized()
return self return self
end end
--- Set new origin size of layout node. You should apply this on node manual size change
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam vector3 new_origin_size -- @tparam boolean is_justify
-- @treturn Layout @{Layout} -- @treturn druid.layout @{Layout}
function Layout.set_origin_size(self, new_origin_size) function M.set_justify(self, is_justify)
self.origin_size = new_origin_size or self.origin_size self.is_justify = is_justify
self:on_window_resized() self.is_dirty = true
return self return self
end end
--- Set max gui upscale for FIT adjust mode (or side). It happens on bigger render gui screen
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam number max_gui_upscale -- @tparam string type The layout type: "horizontal", "vertical", "horizontal_wrap"
-- @treturn Layout @{Layout} -- @treturn druid.layout @{Layout}
function Layout.set_max_gui_upscale(self, max_gui_upscale) function M.set_type(self, type)
self._max_gui_upscale = max_gui_upscale self.type = type
self:on_window_resized() self.is_dirty = true
end
--- Set size for layout node to fit inside it
-- @tparam Layout self @{Layout}
-- @tparam vector3 target_size
-- @treturn Layout @{Layout}
function Layout.fit_into_size(self, target_size)
self.fit_size = target_size
self:on_window_resized()
return self return self
end end
--- Set node for layout node to fit inside it. Pass nil to reset
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @tparam node|nil node -- @tparam boolean is_hug_width
-- @treturn Layout @{Layout} -- @tparam boolean is_hug_height
function Layout.fit_into_node(self, node) -- @treturn druid.layout @{Layout}
self._fit_node = node function M.set_hug_content(self, is_hug_width, is_hug_height)
self:on_window_resized() self.is_resize_width = is_hug_width or false
self.is_resize_height = is_hug_height or false
self.is_dirty = true
return self return self
end end
--- Set current size for layout node to fit inside it
-- @tparam Layout self @{Layout} -- @tparam Layout self @{Layout}
-- @treturn Layout @{Layout} -- @tparam string|node node_or_node_id
function Layout.fit_into_window(self) -- @treturn druid.layout @{Layout}
return self:fit_into_size(vmath.vector3( function M.add(self, node_or_node_id)
gui.get_width(), -- Acquire node from entity or by id
gui.get_height(), local node = node_or_node_id
0)) if type(node_or_node_id) == "table" then
assert(node_or_node_id.node, "The entity should have a node")
node = node_or_node_id.node
else
-- @cast node_or_node_id string|node
node = self:get_node(node_or_node_id)
end
-- @cast node node
table.insert(self.entities, node)
gui.set_parent(node, self.node)
self.is_dirty = true
return self
end end
return Layout -- @tparam Layout self @{Layout}
-- @treturn druid.layout @{Layout}
function M.refresh_layout(self)
local layout_node = self.node
local entities = self.entities
local type = self.type -- vertical, horizontal, horizontal_wrap
local margin = self.margin -- {x: horizontal, y: vertical} in pixels, between elements
local padding = self.padding -- {x: left, y: top, z: right, w: bottom} in pixels
local is_justify = self.is_justify
local size = gui.get_size(layout_node)
local max_width = size.x - padding.x - padding.z
local max_height = size.y - padding.y - padding.w
local layout_pivot_offset = helper.get_pivot_offset(gui.get_pivot(layout_node)) -- {x: -0.5, y: -0.5} - is left bot, {x: 0.5, y: 0.5} - is right top
local rows_data = self:calculate_rows_data()
local rows = rows_data.rows
local row_index = 1
local row = rows[row_index]
-- Current x and Current y is a top left corner of the node
local current_x = -row.width * (0.5 + layout_pivot_offset.x)
local current_y = rows_data.total_height * (0.5 - layout_pivot_offset.y)
if is_justify then
if (type == "horizontal" or type == "horizontal_wrap") and row.count > 1 then
current_x = -max_width * (0.5 + layout_pivot_offset.x)
end
if type == "vertical" then
current_y = max_height * (0.5 - layout_pivot_offset.y)
end
end
for index = 1, #entities do
local node = entities[index]
local node_width = rows_data.nodes_width[node]
local node_height = rows_data.nodes_height[node]
local pivot_offset = helper.get_pivot_offset(gui.get_pivot(node))
if node_width > 0 and node_height > 0 then
-- Calculate position for current node
local position_x, position_y
if type == "horizontal" then
position_x = current_x + node_width * (0.5 + pivot_offset.x)
position_y = current_y - row.height * (0.5 - pivot_offset.y)
local node_margin = margin.x
if is_justify and row.count > 1 then
node_margin = (max_width - row.width) / (row.count - 1) + margin.x
end
current_x = current_x + node_width + node_margin
end
if type == "vertical" then
position_x = current_x + row.width * (0.5 - pivot_offset.x)
position_y = current_y - node_height * (0.5 + pivot_offset.y)
local node_margin = margin.y
if is_justify then
node_margin = (max_height - rows_data.total_height) / (#rows - 1) + margin.y
end
current_y = current_y - node_height - node_margin
end
if type == "horizontal_wrap" then
local width = row.width
if is_justify and row.count > 0 then
width = math.max(row.width, max_width)
end
local new_row_width = width * (0.5 - layout_pivot_offset.x)
-- Compare with eps due the float loss and element flickering
if current_x + node_width - new_row_width > 0.0001 then
if row_index < #rows then
row_index = row_index + 1
row = rows[row_index]
end
current_x = -row.width * (0.5 + layout_pivot_offset.x)
current_y = current_y - row.height - margin.y
if is_justify and row.count > 1 then
current_x = -max_width * (0.5 + layout_pivot_offset.x)
end
end
position_x = current_x + node_width * (0.5 + pivot_offset.x)
position_y = current_y - row.height * (0.5 - pivot_offset.y)
local node_margin = margin.x
if is_justify and row.count > 1 then
node_margin = (max_width - row.width) / (row.count - 1) + margin.x
end
current_x = current_x + node_width + node_margin
end
do -- Padding offset
if layout_pivot_offset.x == -0.5 then
position_x = position_x + padding.x
end
if layout_pivot_offset.y == 0.5 then
position_y = position_y - padding.y
end
if layout_pivot_offset.x == 0.5 then
position_x = position_x - padding.z
end
if layout_pivot_offset.y == -0.5 then
position_y = position_y + padding.w
end
end
self:set_node_position(node, position_x, position_y)
end
end
if self.is_resize_width or self.is_resize_height then
if self.is_resize_width then
size.x = rows_data.total_width + padding.x + padding.z
end
if self.is_resize_height then
size.y = rows_data.total_height + padding.y + padding.w
end
gui.set_size(layout_node, size)
end
self.is_dirty = false
return self
end
-- @tparam Layout self @{Layout}
-- @treturn druid.layout @{Layout}
function M.clear_layout(self)
for index = #self.entities, 1, -1 do
self.entities[index] = nil
end
self.is_dirty = true
return self
end
-- @private
-- @tparam node node
-- @treturn number, number
function M.get_node_size(node)
if not gui.is_enabled(node, false) then
return 0, 0
end
local scale = gui.get_scale(node)
-- If node has text - get text size instead of node size
if gui.get_text(node) then
local text_metrics = helper.get_text_metrics_from_node(node)
return text_metrics.width * scale.x, text_metrics.height * scale.y
end
local size = gui.get_size(node)
return size.x * scale.x, size.y * scale.y
end
-- @private
-- @tparam Layout self @{Layout}
-- Calculate rows data for layout. Contains total width, height and rows info (width, height, count of elements in row)
-- @treturn druid.layout.rows_data
function M.calculate_rows_data(self)
local entities = self.entities
local margin = self.margin
local type = self.type
local padding = self.padding
local size = gui.get_size(self.node)
local max_width = size.x - padding.x - padding.z
-- Collect rows info about width, height and count of elements in row
local current_row = { width = 0, height = 0, count = 0 }
local rows_data = {
total_width = 0,
total_height = 0,
nodes_width = {},
nodes_height = {},
rows = { current_row }
}
for index = 1, #entities do
local node = entities[index]
local node_width = rows_data.nodes_width[node]
local node_height = rows_data.nodes_height[node]
-- Get node size if it's not calculated yet
if not node_width or not node_height then
node_width, node_height = M.get_node_size(node)
rows_data.nodes_width[node] = node_width
rows_data.nodes_height[node] = node_height
end
if node_width > 0 and node_height > 0 then
if type == "horizontal" then
current_row.width = current_row.width + node_width + margin.x
current_row.height = math.max(current_row.height, node_height)
current_row.count = current_row.count + 1
end
if type == "vertical" then
if current_row.count > 0 then
current_row = { width = 0, height = 0, count = 0 }
table.insert(rows_data.rows, current_row)
end
current_row.width = math.max(current_row.width, node_width + margin.x)
current_row.height = node_height
current_row.count = current_row.count + 1
end
if type == "horizontal_wrap" then
if current_row.width + node_width > max_width and current_row.count > 0 then
current_row = { width = 0, height = 0, count = 0 }
table.insert(rows_data.rows, current_row)
end
current_row.width = current_row.width + node_width + margin.x
current_row.height = math.max(current_row.height, node_height)
current_row.count = current_row.count + 1
end
end
end
-- Remove last margin of each row
-- Calculate total width and height
local rows_count = #rows_data.rows
for index = 1, rows_count do
local row = rows_data.rows[index]
if row.width > 0 then
row.width = row.width - margin.x
end
rows_data.total_width = math.max(rows_data.total_width, row.width)
rows_data.total_height = rows_data.total_height + row.height
end
rows_data.total_height = rows_data.total_height + margin.y * (rows_count - 1)
return rows_data
end
-- @private
-- @tparam node node
-- @tparam number x
-- @tparam number y
-- @treturn node
function M:set_node_position(node, x, y)
local position = gui.get_position(node)
position.x = x
position.y = y
gui.set_position(node, position)
return node
end
return M

View File

@ -151,6 +151,8 @@ function Slider.on_input(self, action_id, action)
self.value = (self.target_pos.y - self.start_pos.y) / self.dist.y self.value = (self.target_pos.y - self.start_pos.y) / self.dist.y
end end
self.value = math.abs(self.value)
if self.steps then if self.steps then
local closest_dist = 1000 local closest_dist = 1000
local closest = nil local closest = nil

View File

@ -42,15 +42,15 @@ M["button"] = {
end, end,
on_click_disabled = function(self, node) on_click_disabled = function(self, node)
settings.play_sound(M.button.BTN_SOUND_DISABLED) local start_pos = self.start_pos
gui.animate(node, "position.x", start_pos.x - 3, gui.EASING_OUTSINE, 0.05, 0, function()
gui.animate(node, "position.x", start_pos.x + 3, gui.EASING_OUTSINE, 0.1, 0, function()
gui.animate(node, "position.x", start_pos.x, gui.EASING_OUTSINE, 0.05)
end)
end)
end, end,
on_set_enabled = function(self, node, state) on_set_enabled = function(self, node, state)
if state then
gui.set_color(node, M.button.ENABLED_COLOR)
else
gui.set_color(node, M.button.DISABLED_COLOR)
end
end end
} }

View File

@ -247,7 +247,7 @@ function DruidInstance.initialize(self, context, style)
end end
--- Create new component. -- Create new component.
-- @tparam DruidInstance self -- @tparam DruidInstance self
-- @tparam BaseComponent component Component module -- @tparam BaseComponent component Component module
-- @tparam any ... Other component params to pass it to component:init function -- @tparam any ... Other component params to pass it to component:init function
@ -776,9 +776,8 @@ end
-- @tparam DruidInstance self -- @tparam DruidInstance self
-- @tparam string|node node The_node id or gui.get_node(node_id). -- @tparam string|node node The_node id or gui.get_node(node_id).
-- @tparam string mode The layout mode -- @tparam string mode The layout mode
-- @tparam function|nil on_size_changed_callback The callback on window resize
-- @treturn Layout @{Layout} component -- @treturn Layout @{Layout} component
function DruidInstance.new_layout(self, node, mode, on_size_changed_callback) function DruidInstance.new_layout(self, node, mode)
return helper.require_component_message("layout") return helper.require_component_message("layout")
end end

View File

@ -688,7 +688,8 @@ local function matcherGenerator(regex, plain)
local sum = 0 local sum = 0
local bc, ec = utf8sub(str, 1, 1), utf8sub(str, 2, 2) local bc, ec = utf8sub(str, 1, 1), utf8sub(str, 2, 2)
local skip = len(bc) + len(ec) local skip = len(bc) + len(ec)
bc, ec = utf8unicode(bc), utf8unicode(ec) bc = utf8unicode(bc) --[[@as string]]
ec = utf8unicode(ec) --[[@as string]]
return function(cC) return function(cC)
if cC == ec and sum > 0 then if cC == ec and sum > 0 then
sum = sum - 1 sum = sum - 1

View File

@ -3,18 +3,13 @@ local component = require("druid.component")
---@class component_name : druid.base_component ---@class component_name : druid.base_component
local Component = component.create("component_name") local Component = component.create("component_name")
local SCHEME = {
ROOT = "root",
BUTTON = "button",
}
-- Component constructor. Template name and nodes are optional. Pass it if you use it in your component -- Component constructor. Template name and nodes are optional. Pass it if you use it in your component
function Component:init(template, nodes) function Component:init(template, nodes)
self.druid = self:get_druid(template, nodes) self.druid = self:get_druid(template, nodes)
self.root = self:get_node(SCHEME.ROOT) self.root = self:get_node("root")
self.button = self.druid:new_button(SCHEME.BUTTON, function() end) self.button = self.druid:new_button("button", function() end)
end end

View File

@ -3,13 +3,6 @@ local component = require("druid.component")
---@class component_name : druid.base_component ---@class component_name : druid.base_component
local Component = component.create("component_name") local Component = component.create("component_name")
-- Scheme of component gui nodes
local SCHEME = {
ROOT = "root",
BUTTON = "button",
}
-- Component constructor. Template name and nodes are optional. Pass it if you use it in your component -- Component constructor. Template name and nodes are optional. Pass it if you use it in your component
function Component:init(template, nodes) function Component:init(template, nodes)
-- If your component is gui template, pass the template name and set it -- If your component is gui template, pass the template name and set it
@ -18,7 +11,7 @@ function Component:init(template, nodes)
self.druid = self:get_druid(template, nodes) self.druid = self:get_druid(template, nodes)
-- self:get_node will auto process component template and nodes -- self:get_node will auto process component template and nodes
self.root = self:get_node(SCHEME.ROOT) self.root = self:get_node("root")
end end

View File

@ -14,24 +14,15 @@ local component = require("druid.component")
---@field druid druid_instance ---@field druid druid_instance
local ButtonComponent = component.create("button_component") local ButtonComponent = component.create("button_component")
local SCHEME = {
ROOT = "root",
TEXT = "text",
ICON = "icon",
CHECKBOX = "checkbox"
}
---@param template string ---@param template string
---@param nodes table<hash, node> ---@param nodes table<hash, node>
function ButtonComponent:init(template, nodes) function ButtonComponent:init(template, nodes)
self:set_template(template) self.druid = self:get_druid(template, nodes)
self:set_nodes(nodes)
self.druid = self:get_druid()
self.root = self:get_node(SCHEME.ROOT) self.root = self:get_node("root")
self.text = self.druid:new_text(SCHEME.TEXT) self.text = self.druid:new_text("text")
self.checkbox = self:get_node(SCHEME.CHECKBOX) self.checkbox = self:get_node("checkbox")
self.button = self.druid:new_button(self.root, self._on_click) self.button = self.druid:new_button(self.root, self._on_click)

View File

@ -7,6 +7,8 @@
---@field height number ---@field height number
---@field offset_x number|nil ---@field offset_x number|nil
---@field offset_y number|nil ---@field offset_y number|nil
---@field max_ascent number
---@field max_descent number
---@field node_size vector3|nil @For images only ---@field node_size vector3|nil @For images only
---@class druid.rich_text.lines_metrics ---@class druid.rich_text.lines_metrics
@ -47,6 +49,7 @@
---@field parent node ---@field parent node
---@field size number ---@field size number
---@field fonts table<string, string> ---@field fonts table<string, string>
---@field scale vector3
---@field color vector4 ---@field color vector4
---@field shadow vector4 ---@field shadow vector4
---@field outline vector4 ---@field outline vector4
@ -54,12 +57,9 @@
---@field image_pixel_grid_snap boolean ---@field image_pixel_grid_snap boolean
---@field combine_words boolean ---@field combine_words boolean
---@field default_animation string ---@field default_animation string
---@field node_prefab node
---@field text_prefab node ---@field text_prefab node
---@field text_scale vector3
---@field adjust_scale number ---@field adjust_scale number
---@field default_texture string ---@field default_texture string
---@field node_scale vector3
---@field is_multiline boolean ---@field is_multiline boolean
---@field text_leading number ---@field text_leading number
---@field font hash ---@field font hash
@ -71,3 +71,22 @@
---@field height number ---@field height number
---@field max_ascent number ---@field max_ascent number
---@field max_descent number ---@field max_descent number
---@class utf8
---@field len fun(string: string): number
---@field sub fun(string: string, i: number, j: number): string
---@field gmatch fun(string: string, pattern: string): fun(): string
---@field gsub fun(string: string, pattern: string, repl: string, n: number): string
---@field char fun(...: number): string
---@field byte fun(string: string, i: number, j: number): number
---Add generics to some functions.
---Create new component.
---@generic T: druid.base_component
---@param self druid_instance
---@param component T Component module
---@param ... any Other component params to pass it to component:init function
---@return T Component instance
function druid_instance.new(self, component, ...) end