godot icon indicating copy to clipboard operation
godot copied to clipboard

Font not inherited in theme type variation

Open jotson opened this issue 2 years ago • 1 comments

Godot version

4.1.1.stable

System information

Ubuntu Linux 22.04, Nvidia

Issue description

Creating a new theme type variation that inherits from a Base Type of Button does not inherit the font of the Button. Instead, it inherits from the Default Font for the theme and ignores the Base Type font. However, the inherited button does correctly inherit other properties like Styleboxes.

I expected the new button to inherit all of the properties of the base type including the font.

Steps to reproduce

  1. Create a new theme
  2. Set a default font for the theme
  3. Create a theme item for Button
  4. Add a different custom font for the Button
  5. Create a theme item called Button2
  6. Set the Base Type for Button2 to Button
  7. Add a Button to a scene
  8. Set the Type Variation to Button2

Minimal reproduction project

ThemeTypeFontBug.zip

jotson avatar Aug 17 '23 19:08 jotson

This also applies to font size.

dagarsar avatar Oct 18 '24 16:10 dagarsar

Was it really fixed by #101066? I can't reproduce this issue in 4.2. Looks like something else fixed it and #101066 was unnecessary?

KoBeWi avatar Dec 13 '25 22:12 KoBeWi

Can you try with 4.3? That's the version I encountered both inheritance problems in.

dagarsar avatar Dec 15 '25 08:12 dagarsar

Was it really fixed by #101066? I can't reproduce this issue in 4.2. Looks like something else fixed it and #101066 was unnecessary?

It should be reproduceable in 4.2 and before, because of the extra checks that both font and font size have which none other theme properties do. And it is definitely reproduceable in 4.3. The issue wasn't really fixed by #101066 even, only superficially patched, with half of it still reproduceable in 4.5.

YuriSizov avatar Dec 15 '25 09:12 YuriSizov

So I assume the bug is that the buttons use different font?

Image

This was 4.1.

4.2.2

Image

4.3

Image

...

Current master (regardless if that PR is reverted):

Image

KoBeWi avatar Dec 15 '25 12:12 KoBeWi

Are you using current builds or official release builds? #101066 had cherrypick tags

dagarsar avatar Dec 15 '25 13:12 dagarsar

Official builds. This wasn't cherry-picked to 4.3. And I'm getting the same result in base 4.2.

EDIT: Also for "current master" I forgot to mention that I get the same results with that PR reverted.

If you are experiencing this issue in any of the aforementioned versions it's likely something else. Provide an updated MRP so it can be tested.

KoBeWi avatar Dec 15 '25 13:12 KoBeWi

It is very weird because I was able to reproduce the issue in 4.3 and fix it with that PR. I'll test it when I can.

dagarsar avatar Dec 15 '25 14:12 dagarsar

So I assume the bug is that the buttons use different font?

The issue (which is not necessarily a bug, it's implemented this way by design by bruvzg, for font sizes at least) is that default fonts and default font sizes from themes take precedence over inherited values from types. So

  • If theme type B extends theme type A (whether through ClassDB types or theme type variations),
  • And type B doesn't explicitly declare a font or a font size,
  • And there is a theme, that affects an element of type B, that has a default font or default font size configured,

Then whether or not type A has a font or a font size declaration, type B will not use that, and it will use the default value from the theme instead. This breaks user expectations of how theme types propagate and makes configuring fonts and font sizes for extending theme types that more annoying. You have to explicitly declare fonts and font sizes in extending types and cannot rely on inheritance.

If you need a repro project, I've already attached one in my latest comment on the linked PR https://github.com/godotengine/godot/pull/101066#issuecomment-3576193686. It shows the issue with built-in types that is reproduceable in 4.5, and if you open it in 4.3, it will also show the issue for type variations.

PS. And I'd like to reiterate that this is currently the intended behavior. It's just... not very useful. I don't recall if fonts behaved this way initially, but font sizes were definitely created this way when bruvzg was working on the new font rendering for 4.0. He may have borrowed the idea to do it this way from fonts, which previously were the only kind of theme items to have default values in themes. In retrospect, I believe this to be a mistake though.

PPS. @KoBeWi The reason why MRP from the OP no longer works, I bet, is that we changed how theme type variations are resolved somewhere around 4.2, IIRC. The theme in the OP is not configured correctly: the Button2 type variation is not defined in the theme and does not have its base type set to Button. Prior to that you could just drop in a type variation without a base type and it would work. That's unrelated to the issue.

YuriSizov avatar Dec 15 '25 15:12 YuriSizov