godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Make theme constant and font size use float instead of int #9559

Open dugramen opened 4 months ago

dugramen commented 4 months ago

Describe the project you are working on

Currently building a solution to theme animations in godot

Describe the problem or limitation you are having in your project

Turns out all theme constant and font size types are integers, so animating their values over time can't be smooth

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Floats would allow smooth transitions

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

theme_constant and theme_font_size should use float instead. For any theme constant that may actually need an integer, just floor or round the float

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. Since theme constants are the only way to configure nodes like HBoxContainer, such nodes can't have float constants

Is there a reason why this should be core and not an add-on in the asset library?

Theme constant and theme font size handling are core

bruvzg commented 4 months ago

See https://github.com/godotengine/godot/pull/87243 for a draft (adds support for fractional font sizes and different constant types).

dugramen commented 4 months ago

See https://github.com/godotengine/godot/pull/87243 for a draft (adds support for fractional font sizes and different constant types).

Awesome! As for the boolean issue, just switching to rounding in those scenarios should be enough right?

Calinou commented 4 months ago

Turns out all theme constant and font size types are integers, so animating their values over time can't be smooth

Note that animating font sizes (particularly at sizes above 32) is slow unless using MSDF fonts, as standard DynamicFonts are re-rasterized on the CPU every time their size changes. (This is cached, but you're still forcing a re-render every frame on the first animation cycle.)

dugramen commented 4 months ago

Turns out all theme constant and font size types are integers, so animating their values over time can't be smooth

Note that animating font sizes (particularly at sizes above 32) is slow unless using MSDF fonts, as standard DynamicFonts are re-rasterized on the CPU every time their size changes. (This is cached, but you're still forcing a re-render every frame on the first animation cycle.)

Thanks I didn't know that. I guess animated font sizes aren't really too important though. The main thing is animating things like BoxContainer spacing and MarginContainer margins

AdriaandeJongh commented 4 months ago

Related: https://github.com/godotengine/godot-proposals/issues/9323