The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi everyone,

with this

var ggg = ""
if enteredDigitsCount == 4:
    ggg = ggg.insert(2, "_")
    text = text.insert(1, ggg)

I can have that _ inserted between the 1st and the 2nd digit when I enter the 4th one in my Label (e. g. 1_234).

Now, as there is a property font_color under Custom Colors in the Label's Inspector, I wonder if I could color a certain digit in a different color than the others when the condition is met. So for example, with entering the fourth digit, I'd like the first one to change color.

Is it possible to somehow "replace" that _ with font_color to achieve this?

Godot version 3.2.3
in Engine by (525 points)

1 Answer

0 votes
Best answer

You don't have that level of control over individual character properties in a standard Label control. However, you can do that with a RichTextLabel using the appropriate bbcode .

See here for details.

by (22,674 points)
selected by

Yeah, that description is quite helpful. I'm curious, you say that you disable the number buttons after 4 digits are entered (since you want a comma next). Why would you not just disable the comma button once it's entered also, rather than leaving the button available and flashing the existing comma to indicate the input error? It's likely simpler to do and would be a more cohesive design in that buttons that shouldn't be used based on context are all disabled dynamically.

Hmmm.. I just realized your original question was asking about changing the color of a single digit, but your latest description doesn't mention the color change at all. Having a complete description of the intended results is important when designing a software solution. That way, everything can be accounted for in the initial design, rather than tacking things on later that don't necessarily fit the design pattern.

Certainly that doesn't imply that you won't miss some things in the initial design, or that you won't have new requirements in the future that will alter the design, but defining everything you know about and expect from a solution prior to writing code is a good practice that'll save you some time in the long run...

Generally speaking, I'd guess you'll want to maintain the raw user-entered string at all times. And, rather than trying incrementally modify the bbcode string based on user-input, you'll want to process the entire raw string each time, inserting all the necessary bbcode elements in it and then putting that in the RichTextLabel. Then, when the user modifies their string, you'd just reprocess the new raw string and insert it directly in the RichTextLabel. That seems easier to me than trying to incrementally keep a constructed bbcode string in-sync with the user-modified string at all times.

The comma button is indeed disabled (and darkened) after clicked once, the comma then should blink if clicked again to indicate "hey, there's already a comma!" (often it's the cursor blinking in such cases, but I thought it would be cool (and explicit) to have the comma blinking instead).
In fact, the erase button and the 0 are also darkened/disabled at popup (nothing to erase yet and a 0 doesn't make sense as a first entry. (This applies to an empty field, of course. I did not build the case of an already filled RichTextLabel yet, but the erase button should then be available from the start...)
Disabling the buttons always makes them darkened as well so in these cases the user easily understands there's no need to click a number at the moment anyway. All this, I think, supports intuitive usability and how the whole thing feels.

All your thoughts are, as usual, spot on. I mentioned a color-change in the beginning because I thought it was a rather common thing to start with, which I later, after understanding how it works, can change to basically anything bbcode is offering. But yes, that gap between those digits is the real goal! (And now I'm sorry for that detour...)

It's incredible how many details want to be considered when setting up the concept of such a seemingly little thing like a number-entry-field. I want to believe that I have quite everything covered in the back of my head (and on paper at that) but I'm sure (and sorry) I'm missing things in my descriptions here and there.

I couldn't explain it that way, but (I'm pratically certain that) your latest paragraph nails it as well. Having all the bbcode-"templates" set up in the RichTextLabel-script and then have them refreshed with any buttons-click. (...right?)

For the comma button, if it's disabled after a comma is entered, you won't be able to press it again to trigger the mentioned blinking effect...

And, yeah, you understood properly. Each time the user updates the raw string, you'll want to fully process it to include all necessary bbcode and then update the RichTextLabel with that new code...

I can print and trigger an animation when clicking the disabled button. I thought it registers input by default even if not reacting?
In my szenario the RichTextLabel sends a signal to my comma-button when a comma is written, setting it disabled = true. In this case then if event.is_action_pressed("mousebuttonclick"): returns before button-release, but the Button does register the click.

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.