Defold-RichText

Fixed in Defold-RichText 1.4.0. richtext.create() now returns both nodes table and metrics table

5 Likes

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
6 Likes

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?

1 Like

Yes, already planned: https://github.com/britzl/defold-richtext/issues/4

5 Likes

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:

9 Likes

Empty tags are now supported:

<img=texture:image/>
<br/>
3 Likes

Nice job!!
Can the tags have multiple properties? like HTML? E.g. <img src='#joystick' anim='wiggle'/>

1 Like

I guess it should be possible to specify a flipbook anim from the atlas as “image” part in “texture:image”.

1 Like

Correct. <img=smileys:happy/> does this:

gui.set_texture(node, texture)
gui.play_flipbook(node, image)
4 Likes

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.

5 Likes

I’m making a visual novel kit soon and will use Defold-RichText with it.

4 Likes

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:

waves

Released defold-richtext 2.5.0

11 Likes

Sweet baby ray, this is awesome!

4 Likes

astrologists proclaim the week of text RPGs #MadeWithDefold

8 Likes

my space shooter is now also an rpg adventure

9 Likes

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.

spineboy

5 Likes

rt.zip (841.9 KB)

Edit: made slight adjustment

2 Likes