Update docs

This commit is contained in:
Insality
2025-03-18 21:23:30 +02:00
parent 5348561d68
commit 1bc916e187
25 changed files with 937 additions and 380 deletions

View File

@@ -4,12 +4,13 @@ local const = require("druid.const")
local utf8_lua = require("druid.system.utf8")
local utf8 = utf8 or utf8_lua
---The component that handles a rich text input field, it's a wrapper around the druid.input component
---@class druid.rich_input: druid.component
---@field root node
---@field input druid.input
---@field cursor node
---@field cursor_text node
---@field cursor_position vector3
---@field root node The root node of the rich input
---@field input druid.input The input component
---@field cursor node The cursor node
---@field cursor_text node The cursor text node
---@field cursor_position vector3 The position of the cursor
local M = component.create("druid.rich_input")
local DOUBLE_CLICK_TIME = 0.35
@@ -131,7 +132,12 @@ local function on_touch_start_callback(self, touch)
end
---@param self druid.rich_input
---@param dx number The delta x position
---@param dy number The delta y position
---@param x number The x position
---@param y number The y position
---@param touch table The touch table
local function on_drag_callback(self, dx, dy, x, y, touch)
if not self._last_touch_info.cursor_index then
return
@@ -218,6 +224,7 @@ end
---Set placeholder text
---@param placeholder_text string The placeholder text
---@return druid.rich_input self Current instance
function M:set_placeholder(placeholder_text)
self.placeholder:set_text(placeholder_text)
return self
@@ -225,8 +232,10 @@ end
---Select input field
---@return druid.rich_input self Current instance
function M:select()
self.input:select()
return self
end
@@ -262,7 +271,7 @@ end
-- See: https://defold.com/ref/stable/string/
-- ex: [%a%d] for alpha and numeric
---@param characters string Regulax exp. for validate user input
---@return druid.rich_input Current instance
---@return druid.rich_input self Current instance
function M:set_allowed_characters(characters)
self.input:set_allowed_characters(characters)

View File

@@ -65,11 +65,12 @@ local rich_text = require("druid.custom.rich_text.module.rt")
---@field offset_y number|nil
---@field node_size vector3|nil
---The component that handles a rich text display, allows to custom color, size, font, etc. of the parts of the text
---@class druid.rich_text: druid.component
---@field root node
---@field text_prefab node
---@field private _last_value string
---@field private _settings table
---@field root node The root node of the rich text
---@field text_prefab node The text prefab node
---@field private _last_value string The last value of the rich text
---@field private _settings table The settings of the rich text
local M = component.create("rich_text")
@@ -145,13 +146,14 @@ function M:set_text(text)
end
---Get current text
---@return string text
---Get the current text of the rich text
---@return string text The current text of the rich text
function M:get_text()
return self._last_value
end
---@private
function M:on_remove()
gui.set_scale(self.root, self._default_scale)
gui.set_size(self.root, self._default_size)
@@ -170,8 +172,8 @@ end
---Get all words, which has a passed tag.
---@param tag string
---@return druid.rich_text.word[] words
---@param tag string The tag to get the words for
---@return druid.rich_text.word[] words The words with the passed tag
function M:tagged(tag)
if not self._words then
return {}
@@ -181,28 +183,22 @@ function M:tagged(tag)
end
---Split a word into it's characters
---@param word druid.rich_text.word
---@return druid.rich_text.word[] characters
function M:characters(word)
return rich_text.characters(word)
end
---Get all current words.
---Get all current created words, each word is a table that contains the information about the word
---@return druid.rich_text.word[]
function M:get_words()
return self._words
end
---Get current line metrics
----@return druid.rich_text.lines_metrics
---Get the current line metrics
---@return druid.rich_text.lines_metrics lines_metrics The line metrics of the rich text
function M:get_line_metric()
return self._line_metrics
end
---@private
---@return table settings The settings of the rich text, they are created based on the root node on the GUI scene
function M:_create_settings()
local root_size = gui.get_size(self.root)
local scale = gui.get_scale(self.root)