|
|
|
|
Reply From: |
Bojidar Marinov |
It is relatively simple, you should just use Control::add_color_override
or Object::set
First of all, hover over the label before the color you want to change in the inspector. It would show a tooltip with info about the property name. In this case, it was custom_colors/font_color
To make it with add_color_override
, take the right-most part of the property name. E.g. font_color
. Then, use it like this:
add_color_override("font_color", Color(1,0,0))
Making it with set
is just a bit easier (and a character shorter):
set("custom_colors/font_color", Color(1,0,0))
Thank you very much !
I didn’t understand the 1st parameter of add_color_override(String name, Color color)
nor the link between set()
and the inspector.
Matt_UV | 2016-03-11 15:50
I wouldn’t have understood either, but a few days ago I was doing some Control
-related PR, and saw it…
Bojidar Marinov | 2016-03-11 16:52
From the documentation alone, it’s quite hard to know where this "custom_colors/font_color"
comes from, and how you are supposed to figure it out.
Godot provides much of this information in hover-over tooltips. For instance, in this case, you have a Label
node. In the inspector, you go to Control
, and find Custom Colors
, and under there Font Color
, which is the property you want to manipulate in code. If you hover over the property name (not the input field, mind you), i.e. the Font Color
text itself, you’ll get a tooltip that says
Property: custom_colors/font_color
This covers the set(property: String, value: Variant)
function.
If anyone has a good tip to know that for instance the custom_color/
prefix is covered by add_color_override()
, I’d love to know. The documentation for Label
will list the various properties under Theme Properties. For example, it shows font_color
there. But this prefix of custom_color/
is not shown, and the link to add_color_override
is as far as I can tell, is also not mentioned.
If working mostly in scripts, it seems to lead to the following scenario:
- Read documentation of Label
- See theme property of
font_color
, and decide to change it in code. But you need the full path of the property.
- Create the Node in the scene in order to see it in the inspector.
- Search through all the properties for something that looks like it matches
font_color
. Hover over and find the full path.
- Delete the node from the scene, and use the full property path in
set
.
swalog | 2019-10-15 01:28
Now how do I change it for pressed, hover, disabled, etc…?
wetbadger | 2022-05-06 20:24