godotengine / godot-proposals

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

Add font-specific alignment customizations for Label rendering #9420

Open fmoo opened 5 months ago

fmoo commented 5 months ago

Describe the project you are working on

A 2D game utilizing pixel fonts with latin-1 glyphs.

Describe the problem or limitation you are having in your project

When designing and laying out text within a panel UI, content is perceived as aligned when the margins are evaluated against the the box consisting of cap-height <-> baseline.

When using latin-1 pixel fonts, ascenders on accented capital letters generally exceed the cap-height. Godot seems to size and align labels according to the maximum glyph sizes, which results in text rendered inside of a margins being applied in a way that appears asymmetric, like this:

image

One might hack around this by simply reducing the vertical margin, or setting a margin top constant override for a font-specific Theme, but this problematic for a few reasons:

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

I'd propose one or more of the following:

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

New theme constants or label attributes should be modifiable via the Inspector panel when viewing the Theme, Label, and RichTextLabel as appropriate.

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

No workarounds via script that can address all of the issues are known at this time:

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

The affected controls (Label, RichTextLabel) are part of core.

fmoo commented 5 months ago

Was talking about this issue with some more people this morning, and they pointed out that using a FontVariant instead of a FontFile provides a way to accomplish exactly this via negative Extra Spacing > Top and Extra Spacing > Bottom values:

image

I do think it's possibly worth exposing an override for these directly on the theme or text controls, or trying to improve user awareness of the available features on FontVariant, but as there's a workable solution for this class of issue, this proposal is not going to be as impactful.

bruvzg commented 5 months ago

baseline offset is already available in 4.3 (as a FontVariation property).

align top to cap height

For most fonts, you can't easily determine cap height, so this won't work. Aligning baseline to the bottom can be added (but I'm not sure if it's something that will be used a lot).