Update docs

This commit is contained in:
Insality
2023-07-11 22:23:48 +03:00
parent 6ed48772a3
commit 23ac068f51
9 changed files with 72 additions and 55 deletions

View File

@@ -534,52 +534,6 @@ function M.tagged(words, tag)
end
--- Split a word into it's characters
-- @param word The word to split
-- @return The individual characters
function M.characters(word)
assert(word)
local parent = gui.get_parent(word.node)
local font = gui.get_font(word.node)
local layer = gui.get_layer(word.node)
local pivot = gui.get_pivot(word.node)
local word_length = utf8.len(word.text)
-- exit early if word is a single character or empty
if word_length <= 1 then
local char = helper.deepcopy(word)
char.node, char.metrics = create_node(char, parent, font)
gui.set_pivot(char.node, pivot)
gui.set_position(char.node, gui.get_position(word.node))
gui.set_layer(char.node, layer)
return { char }
end
-- split word into characters
local chars = {}
local position = gui.get_position(word.node)
local position_x = position.x
for i = 1, word_length do
local char = helper.deepcopy(word)
chars[#chars + 1] = char
char.text = utf8.sub(word.text, i, i)
char.node, char.metrics = create_node(char, parent, font)
gui.set_layer(char.node, layer)
gui.set_pivot(char.node, pivot)
local sub_metrics = get_text_metrics(word, font, utf8.sub(word.text, 1, i))
position.x = position_x + sub_metrics.width - char.metrics.width
char.position = vmath.vector3(position)
gui.set_position(char.node, char.position)
end
return chars
end
---Removes the gui nodes created by rich text
function M.remove(words)
assert(words)

View File

@@ -3,10 +3,28 @@
--- Druid Rich Text custom component.
-- <b># Overview #</b>
--
-- Heavily inspired by https://github.com/britzl/defold-richtext.
-- Heavily inspired by <a href="https://github.com/britzl/defold-richtext" target="_blank">https://github.com/britzl/defold-richtext</a>.
--
-- Uses the same syntax for tags, but currently have less tags support.
--
-- All Rich Text params are adjusted in GUI scene
--
-- The Rich Text template should have next scheme:
--
-- root
--
-- - text_prefab
--
-- - icon_prefab
--
-- <b># Rich Text Setup #</b>
-- • Root node size - maximum width and height of the text
-- • Root anchor - Aligment of the Rich Text inside root node size area
-- • Text prefab - all text params for the text node
-- • Text prefab anchor - Anchor for each text node (you should adjust this only if animate text)
-- • Icon prefab - all node params for the icon node
-- • Icon prefab anchor - Anchor for each icon node (you should adjust this only if animate icon)
--
-- <b># Notes #</b>
--
-- • Nested tags are supported