Godot Version
4.4
Question
I created a custom theme through code and want apply it, but it doesnt
var t = Theme.new()
t.set_color(“font_color”, “Label”, Color(0.0, 0.0, 1.0))
test_btn.add_theme_font_size_override(“font_size”, 10)
test_btn.set_theme(t)
with first function it works pretty well, but i want apply all theme. I read about StyleBoxFlat, idk witch different between them, but think that for my project need theme
I think you have multiple questions here so I will answer them all.
If you’re asking why the theme is not being applied to all nodes, the theme will only apply to the node it’s on and its children. You’ll need to set the theme property on all the nodes you want to apply the theme to.
If you’re asking why the theme override doesn’t work, I can’t tell by the code why it wouldn’t work. test_btn
is a Button node, right?
If you’re asking what the difference between StyleBoxFlat and a theme is, a theme is just a collection of different stylings applied to control nodes. A StyleBoxFlat is one of those stylings, and it’s used for panels mainly.
Thank you for explanation about StyleBoxFlat and theme, i need theme. These test_btn
is button node, right, is child of Control node(it’s only one node in project because i make some prototype). Context of top part of code is just check if it works. I apply theme only to one button and wont that it’s apply only to it
why?
create a theme on the first node and the children will inherit it. do not use the custom theme overrides, they are a waste of time.
why would you want to code a theme? it makes no sense.
if you need to change elements in game, you can do that by creating theme_type_variation
s in the theme, you can then assign these to a node and it will change the appearance. you can also do this in code, by replacing the theme_type_variation
value with the name of the variation.
if the idea is to customize the theme in game, which is what these methods are designed for, reference the existing theme instead of creating a new one, or create a copy with duplicate
if you want to preview it.
styleboxes are created and assigned in theme. you can also export them.
styleboxflat is just one version of it, there are others like styleboxtexture and styleboxempty. they can be drawn in the draw function.
styleboxes are used for everything, one use is for buttons. they provide a complex shape with shadows, borders and corners, or can just be empty padding, or use a texture.
every single control that occupies a square area has at least a stylebox, and sometimes styleboxempty is used and so it can be replaced for a visible one.
My needs is some specific. I want write all settings of ui in json file, analyze it to replace my simplification and create elements by its settings. I want make something like computer in my game and want that players can create there own apps. So my structure looks like styles in begin(how elements will looks like) and then theirs functionality. I understand about StyleBoxFlat, I also want to use it for deep customization