0 votes

Hi everyone,

it appears fairly easy to apply some BbCode to (parts of) a text in a RichTextLabel via the editor's Inspector, like right-aligning [right]{text}[/right].

But what if I don't have any straight text to deal with in the Inspector but rather some yet to be inserted input (by the user) in an empty RichTextLabel? How could I mark certain elements of a text (e. g. entered numbers) to only tweak them?
And I'd like to apply a general right-aligning to the whole RichTextLabel, but as there is no such option to select in the Inspector, isn't there any way to apply this by code within the node's script?

Godot version 3.2.3
in Engine by (455 points)
edited by

Could you maybe make a Word doc or something demonstrating what you're trying to achieve and share a screenshot? It's a little hard for me to imagine what you're trying to accomplish.

But of course, I'll try: let's say I have an empty text-field made of a RichTextLabel (gray). The user then enters a couple of numbers, a comma and some more numbers. What I'd like to achieve is three things:
1. the numbers are aligned to the right of the box
2. spacing of the thousands' position is a little farther from the hundreds' than usual (but not an empty space!)
3. the numbers after the comma should be a little smaller and positioned higher in the line

Which could look somewhat like this:

https://we.tl/t-02POeS3Vkg

Telling the Label that the current input is a thousands' position or an after-comma one is a challenge of its own, but I believe I could manage that. I have, however, no idea, how I can BbCode these parts accordingly, so that they „automatically“ do it when these positions are entered. Any thought is much appreciated!

1 Answer

+1 vote
Best answer

Typically, you would not use a RichTextLabel for user input as it's a read-only control. While you could listen for user input and update the contents as needed, I doubt that's really what you want to do.

Instead, I'd guess you might want to use a TextEdit control, which does allow user input and will allow you to vary the color of the input based on the add_keyword_color and add_color_region functions.

You can sort of equate it to a syntax-highlighting programmer's editor. With the proper configuration, it can highlight dynamic text based on your needs.

Here's a short video that goes over some of these features:

https://www.youtube.com/watch?v=f5RfboOKKgw&t=48s

by (14,792 points)
selected by

Thanks, this is really helpful (and straight forward).
So I see three ways of assigning a color to a chosen sign: via code, via Custom Color in the editor or via Theme/Color. (After a quick test with both code and Theme attached, it appears that the first entry respects the code, but then the Theme kicks in - perhaps it's a good idea to choose one of the options and stick to it.)

Now I wonder how far that approach can reach beyond setting colors! I'd love such a simple code-line approach to make all kinds of tweaks possible - font size, alignment, spacing, transparency etc...
Trying to have text aligned to the right, I can see smoothscrolling and wrapenabled and such things, but nothing concerning aligning... (A Label simply features Aligning in the Editor - is there a reason why TextEdit (or RichTextLabel as well) doesn't?)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.