This commit is contained in:
Insality
2025-03-05 21:42:54 +02:00
parent 2c2789f1f9
commit c3b132187a
26 changed files with 338 additions and 574 deletions

View File

@@ -1,38 +1,38 @@
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
--- Druid Rich Input custom component.
---Druid Rich Input custom component.
-- It's wrapper on Input component with cursor and placeholder text
-- @module RichInput
-- @alias druid.rich_input
--- The component druid instance
---The component druid instance
-- @tfield DruidInstance druid DruidInstance
--- Root node
---Root node
-- @tfield node root
--- On input field text change callback(self, input_text)
---On input field text change callback(self, input_text)
-- @tfield Input input Input
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield node cursor
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield node cursor_text
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield vector3 cursor_position
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield druid.text input_text
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield druid.drag drag
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield druid.text placeholder
--- On input field text change to empty string callback(self, input_text)
---On input field text change to empty string callback(self, input_text)
-- @tfield vector3 text_position
---
@@ -120,7 +120,7 @@ local function on_unselect(self)
end
--- Update selection
---Update selection
local function update_selection(self)
update_text(self)
end
@@ -264,7 +264,7 @@ function M:on_input(action_id, action)
end
--- Set placeholder text
---Set placeholder text
---@param placeholder_text string The placeholder text
function M:set_placeholder(placeholder_text)
self.placeholder:set_text(placeholder_text)
@@ -272,13 +272,13 @@ function M:set_placeholder(placeholder_text)
end
--- Select input field
---Select input field
function M:select()
self.input:select()
end
--- Set input field text
---Set input field text
---@param text string The input text
---@return druid.rich_input self Current instance
function M:set_text(text)
@@ -289,7 +289,7 @@ function M:set_text(text)
end
--- Set input field font
---Set input field font
---@param font hash The font hash
---@return druid.rich_input self Current instance
function M:set_font(font)
@@ -300,13 +300,13 @@ function M:set_font(font)
end
--- Set input field text
---Set input field text
function M:get_text()
return self.input:get_text()
end
--- Set allowed charaters for input field.
---Set allowed charaters for input field.
-- See: https://defold.com/ref/stable/string/
-- ex: [%a%d] for alpha and numeric
---@param characters string Regulax exp. for validate user input

View File

@@ -50,7 +50,7 @@ local function compare_words(one, two)
end
--- Get the length of a text ignoring any tags except image tags
---Get the length of a text ignoring any tags except image tags
-- which are treated as having a length of 1
-- @param text String with text or a list of words (from richtext.create)
-- @return Length of text
@@ -152,12 +152,12 @@ end
-- Create rich text gui nodes from text
--- @param text string The text to create rich text nodes from
--- @param settings table Optional settings table (refer to documentation for details)
--- @param style druid.rich_text.style
--- @return druid.rich_text.word[]
--- @return druid.rich_text.settings
--- @return druid.rich_text.lines_metrics
---@param text string The text to create rich text nodes from
---@param settings table Optional settings table (refer to documentation for details)
---@param style druid.rich_text.style
---@return druid.rich_text.word[]
---@return druid.rich_text.settings
---@return druid.rich_text.lines_metrics
function M.create(text, settings, style)
assert(text, "You must provide a text")
@@ -522,7 +522,7 @@ function M.is_fit_info_area(lines, settings)
end
--- Get all words with a specific tag
---Get all words with a specific tag
-- @param words The words to search (as received from richtext.create)
-- @param tag The tag to search for. Nil to search for words without a tag
-- @return Words matching the tag

View File

@@ -107,7 +107,7 @@ local function merge_tags(dst, src)
end
--- Parse the text into individual words
---Parse the text into individual words
-- @param text The text to parse
-- @param default_settings Default settings for each word
-- @param color_aliases Color aliases table
@@ -184,7 +184,7 @@ function M.parse(text, default_settings, style)
end
--- Get the length of a text, excluding any tags (except image and spine tags)
---Get the length of a text, excluding any tags (except image and spine tags)
function M.length(text)
return utf8.len(text:gsub("<img.-/>", " "):gsub("<.->", ""))
end

View File

@@ -1,6 +1,6 @@
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
--- Druid Rich Text Custom Component.
---Druid Rich Text Custom Component.
-- <b># Overview #</b>
--
-- This custom component is inspired by <a href="https://github.com/britzl/defold-richtext" target="_blank">defold-richtext</a> by britzl.
@@ -62,13 +62,13 @@
-- @within BaseComponent
-- @alias druid.rich_text
--- The component druid instance
---The component druid instance
-- @tfield DruidInstance druid DruidInstance
--- The root node of the Rich Text
---The root node of the Rich Text
-- @tfield node root
--- The text prefab node
---The text prefab node
-- @tfield node text_prefab
--
@@ -150,7 +150,7 @@ local rich_text = require("druid.custom.rich_text.module.rt")
local M = component.create("rich_text")
--- The RichText constructor
---The RichText constructor
---@param text_node node|string The text node to make Rich Text
---@param value string|nil The initial text value. Default will be gui.get_text(text_node)
function M:init(text_node, value)
@@ -175,7 +175,7 @@ function M:on_layout_change()
end
--- Component style params.
---Component style params.
-- You can override this component styles params in Druid styles table
-- or create your own style
-- @table style
@@ -190,7 +190,7 @@ function M:on_style_change(style)
end
--- Set text for Rich Text
---Set text for Rich Text
---@param text string|nil The text to set
---@return druid.rich_text.word[] words
---@return druid.rich_text.lines_metrics line_metrics
@@ -252,7 +252,7 @@ function M:set_text(text)
end
--- Get current text
---Get current text
---@return string text
function M:get_text()
return self._last_value
@@ -266,7 +266,7 @@ function M:on_remove()
end
--- Clear all created words.
---Clear all created words.
function M:clear()
if self._words then
rich_text.remove(self._words)
@@ -276,7 +276,7 @@ function M:clear()
end
--- Get all words, which has a passed tag.
---Get all words, which has a passed tag.
---@param tag string
---@return druid.rich_text.word[] words
function M:tagged(tag)
@@ -296,14 +296,14 @@ function M:characters(word)
end
--- Get all current words.
---Get all current words.
---@return druid.rich_text.word[]
function M:get_words()
return self._words
end
--- Get current line metrics
---Get current line metrics
----@return druid.rich_text.lines_metrics
function M:get_line_metric()
return self._line_metrics