mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user