Hello,
I’m trying to make a card with description written on it. Some words shloud be highlighted in some way (different color and/or bold letters). I’m using labels to display the text. The card itself is a gameobject, and I’d prefer to keep it that way. Is there any way to achive that?
I’m aware that there is Ritch Text library by britzl, which does all that and much much more, but it’s only for GUI.
You’ll have to build it yourself with multiple labels. Use label.get_text_metrics() to get the sizes of things so you know how to piece the parts together. You can use a game object factory to spawn and place the label parts as needed when text changes. Don’t worry about creating / destroying as needed it’s fast.
I’m not sure Rich Text is possible with labels right now because label.set_text() is not synchronous, so you can’t call label.set_text() followed by a label.get_text_metrics() in quick succession the way Rich Text does.
That is not that big of a problem. I’m using two functions for this, one that creates all the labels and fills them with text, and posts a message, calling another function that will position the text. Thanks to the way that the message system works, it ensures that the second function is called after the label.set_text() is done doing it’s thing.
I’m almost done with my code, I’ll post it here soon.
Generated using following message: msg.post("printer", "text", {text = "This {important}text consist of {green}multiple labels.", width = 350})
The the code contains very simple styling function, using keywords to change label properties. You cannot stack keywords. The styling function only knows important and green keywords.
Here is the zip containig the code and all the game objects you’ll need to generate this text: printer.zip (1.7 KB)
This is not a library, it’s just code snippets and examples.
I know that GitLab is not as popular for public repositories, but it’s what I have been using for a while, so I’m hosting it there. Feel free to DM me here on the forum instead of making an issue.