Correct text vertical alignment in Football mode and UI#5638
Correct text vertical alignment in Football mode and UI#5638bricealbiol wants to merge 1 commit intosupertuxkart:masterfrom
Conversation
Previously, using only `getHeightPerLine()` for centering calculations caused text to appear offset because it included line padding. By introducing `getHeightPerGlyph()`, we can now center text based on the visual bounds of the characters. - **IGUIFont.h & CGUIFont.h**: Added `getHeightPerGlyph()` to the font interface to retrieve the actual height of characters without line spacing. - **GlyphLayout.h**: Updated `getGlyphLayoutsDimension` to accept `height_per_glyph` as a parameter for more accurate dimension calculations. - **CGUIButton.cpp**: Improved the centering logic in `draw()` to use the new glyph height, ensuring text is vertically centered within buttons. - **CGUIStaticText.cpp**: Adjusted height and width calculations to account for the difference between line height and glyph height. - **FontWithFace**: Added `m_glyph_max_above` and `m_glyph_max_below` to track precise font metrics (ascender/descender) via FreeType. - **ScalableFont**: Implemented `getHeightPerGlyph()` for STK's scalable font system, including support for borders and shadows. - **GUI Components**: Updated `CGUIEditBox`, `MessageQueue`, `NetworkingLobby`, and `RaceResultGUI` to use the new dimension logic.
|
@bricealbiol, I tested your PR, but I cannot see difference between your code and the actual code in the soccer setup screen. You are finishing this yet? |
|
Hello @GustaLOLE, |
|
I see you don't edited the soccer setup file, why? And send us images with this screen, please. |
|
@bricealbiol Can you send this PR to my fork, pls? |
|
How can i send this PR in your fork pls ? |
|
Send a PR in (https://github.com/GustaLOLE/stk-code) as the same way of you send here |
@GustaLOLE You can just pull the commits once this is merged upstream. Better than having contributors do everything twice. |
|
Ehm, Alayan will take time to put this maybe |
@bricealbiol Thanks for taking a look into this! It seems the Continue button on your screenshot is also vertically misaligned, maybe this could also be fixed in the same patch? Also, there is a small problem when aligning text based on the actual rendered height: anything containing characters that draw below the "text bottom line" (there's probably an official term for that) will make the text go up. Think any of these characters: "JQÇ" and "çgjpqy"). Also, if no capital letters are present (or taller characters, like "bdfhijklt") will bring the text down. The ideal way to align text vertically usually uses the height of the "capital X" character for that font at that size, in order to correctly align text without the issues presented in this paragraph. Edit: by the code, it seems it samples the character 'A', so all good in that regard. |
|
@bricealbiol it seems the "Continue" button was correctly aligned before the patch, so it seems to be a regression. |
|
Yes, actually, without the modifications to the file lib/irrlicht/source/Irrlicht/CGUIButton.cpp, the text on the “continue” button is completely misaligned. I saw it in the middle, but it doesn't actually appear to be centered. |



Issue #5619
Previously, using only
getHeightPerLine()for centering calculations caused text to appear offset because it included line padding. By introducinggetHeightPerGlyph(), we can now center text based on the visual bounds of the characters.IGUIFont.h & CGUIFont.h: Added
getHeightPerGlyph()to the font interface to retrieve the actual height of characters without line spacing.GlyphLayout.h: Updated
getGlyphLayoutsDimensionto acceptheight_per_glyphas a parameter for more accurate dimension calculations.CGUIButton.cpp: Improved the centering logic in
draw()to use the new glyph height, ensuring text is vertically centered within buttons.CGUIStaticText.cpp: Adjusted height and width calculations to account for the difference between line height and glyph height.
FontWithFace: Added
m_glyph_max_aboveandm_glyph_max_belowto track precise font metrics (ascender/descender) via FreeType.ScalableFont: Implemented
getHeightPerGlyph()for STK's scalable font system, including support for borders and shadows.GUI Components: Updated
CGUIEditBox,MessageQueue,NetworkingLobby, andRaceResultGUIto use the new dimension logic.Technical Background: Bearing vs. Height
To fix the vertical alignment, I've distinguished between the line height and the visual glyph metrics. As explained in the FreeType documentation:
By implementing
getHeightPerGlyph()(based on the max ascender and descender metrics), we ensure that UI elements like buttons and the Football score are centered based on the visible part of the text rather than the theoretical line height.Agreement