godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.63k stars 20.1k forks source link

Theme on container overrides theme on child button even though one is selected for that button. #94369

Open henkehedstrom opened 1 month ago

henkehedstrom commented 1 month ago

Tested versions

Reproducible in Godot 4.2.2 stable. Tested opening the project in 4.1.2 stable aswell and had the same issue but don't know if it is a good enough test or if I should create everything from scratch.

I used Compatibility mode.

System information

Windows 11

Issue description

I created an HBoxContainer with a theme that made every button green. If I added a button as a child to that container it turned green as expected. If I changed the theme on a child to a theme that made the button red, it turned red. However, when I added a theme that did not alter the button at all (I just made a new theme and saved it with default settings) the button was still green. My new theme did not alter the button.

The picture below is showing an HBoxContainer with the green_theme and then three buttons with different themes. Red and blue buttons have themes that give them their respective colours. The "Default Button" has the theme showed in the theme window in the picture, it should have the default grey colour. image

Steps to reproduce

  1. Create an HBoxContainer (any container might work, haven't tried others)
  2. Give the container a distinct theme (like a color for a button)
  3. Add a button to the container (any control might work but haven't tried)
  4. Give the button a new theme without any changes
  5. The button should have the color from the container's theme instead of it's own theme

Minimal reproduction project (MRP)

Open the test.tscn and you will see the same as in my screenshot MRP.zip

KoBeWi commented 1 month ago

Default Theme resource is empty. It does not define any value, and if something is not defined, the value is taken from parent theme. Currently there is no way to "discard" a Theme, other than explicitly copying values from default theme.

henkehedstrom commented 1 month ago

Default Theme resource is empty. It does not define any value, and if something is not defined, the value is taken from parent theme. Currently there is no way to "discard" a Theme, other than explicitly copying values from default theme.

I see so it only saves diffs compared to the default theme.

How would I explicitly copy values from the default theme. Can I find them somewhere? What if the default theme changes, I need to update my custom default theme then again. I guess a discard function or an option to not inherit themes from parents would be nice.

I guess I could manually set themes on every child that needs a theme aswell. A bit more manual work but then buttons without a theme will work like I want.

KoBeWi commented 1 month ago

In Theme editor there is Import button that allows you to copy values from default theme.

You can also break inheritance chain by enabling top_level in Control (I think), or using non-Control parent. But this makes the node not work in Containers, so it's a rarely feasible solution.