Fixed in Defold-RichText 1.4.0. richtext.create() now returns both nodes table and metrics table
No. I mean aligning the whole block of text relative to the origin of the container. Similar to how the North/Center/South pivots work for normal labels.
Ah, ok. If you pass in a parent node that the text nodes will be childed to then it should be trivial to vertically align the parent based on height of the entire text to achieve what you want.
Fair enough. You’d have an extra parent node to manage, though. I guess implementing this in the library vs letting the user implement this is just a matter of usage convenience vs separation of concerns.
Released 2.0.0 with support for getting tagged text (and custom nodes). Get all words with a <b>
tag:
local words, metrics = richtext.create(...)
local bold_words = richtext.tagged(words, "b")
for _,bold_word in pairs(bold_words) do
print(bold_word.text, bold_word.node)
end
And you can use custom tags as well:
local text = "Lorem ipsum dolor sit amet, <foo>consectetur adipiscing elit</foo>. Aliquam vehicula purus sit amet orci molestie vulputate."
local words, metrics = richtext.create(text, ...)
local foo_words = richtext.tagged(words, "foo")
for _,word in pairs(foo_words) do
print(word.text, word.node)
end
I think this would be very useful for chat applications as well.
Any chance it can support smileys/images which can be inserted within the text?
Added support for images in 2.1.0:
<img=texture:image></img>
Example:
"<size=3>RichText</size>Lorem <color=0,0.5,0,1>ipsum </color><img=smileys:zombie></img> dolor <color=red>sit </color><color=#ff00ffff>amet, </color><size=1.15><font=Nanum>consectetur </font></size>adipiscing elit. <b>Nunc </b>tincidunt <b><i>mattis</i> libero</b> <i>non viverra</i>.\n\nNullam ornare <img=smileys:hungry></img>accumsan rhoncus.\n\nNunc placerat nibh a purus auctor, id scelerisque massa <size=2>rutrum.</size>"
Result:
Empty tags are now supported:
<img=texture:image/>
<br/>
Nice job!!
Can the tags have multiple properties? like HTML? E.g. <img src='#joystick' anim='wiggle'/>
I guess it should be possible to specify a flipbook anim from the atlas as “image” part in “texture:image”.
Correct. <img=smileys:happy/>
does this:
gui.set_texture(node, texture)
gui.play_flipbook(node, image)
Added in defold-richtext 2.3.0. You can now pass in align
in settings with one of richtext.ALIGN_LEFT, richtext.ALIGN_CENTER or richtext.ALIGN_RIGHT.
This is probably the last release I’ll do in a while. I’m gonna wait for feedback from users and makes changes based on that feedback.
I’m making a visual novel kit soon and will use Defold-RichText with it.
This was a lie! @Pkeod started experimenting and provided a bunch of suggestions. Added richtext.truncate(words, length)
, richtext.length(text)
and richtext.characters(word)
functions. Makes it quite easy to do text effects such as these:
Released defold-richtext 2.5.0
astrologists proclaim the week of text RPGs #MadeWithDefold
my space shooter is now also an rpg adventure
Released 2.8.0 to fix a bunch of issues reported by @pkeod. I also added experimental support for spine models. Finally it’s now possible to easily assign layers to the generated nodes to reduce draw calls.