Skip to content

Commit

Permalink
Update richtext.lua to add richtext.remove() (#65)
Browse files Browse the repository at this point in the history
* Update richtext.lua to add richtext.remove()

Added function richtext.remove(). It's trivial to loop over the words table and do it yourself, but it looks a bit cluttered when you are attempting to delete multiple rich text tables.

* Update README.md

Add description of function richtext.remove()

* Update richtext.lua

Replace table.getn with #
  • Loading branch information
8bitskull authored Sep 9, 2020
1 parent f94a23b commit 2f32b42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ Call this function when a click/touch has been detected and your text contains w
* `consumed` (boolean) - True if any word was clicked.


### richtext.remove(words)
Removes all gui text nodes created by `richtext.create()`.

**PARAMETERS**
* `words` (table) - Table of words, as received from a call to `richtext.create()`.


### richtext.ALIGN_LEFT
Left-align text. The words of a line starts at the specified position (see `richtext.create` settings above).

Expand Down
10 changes: 10 additions & 0 deletions richtext/richtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,15 @@ function M.characters(word)
return chars
end

---Removes the gui nodes created by rich text
function M.remove(words)
assert(words)

local num = #words
for i=1,num do
gui.delete_node(words[i].node)
end
end


return M

0 comments on commit 2f32b42

Please sign in to comment.