improved vertical alignment of text in ingame gui
This commit is contained in:
parent
79041eb52d
commit
55a74f58c1
3 changed files with 11 additions and 5 deletions
|
@ -297,8 +297,8 @@ struct GUISceneImpl final : GUIScene
|
|||
|
||||
switch (rect.text->vertical_align) {
|
||||
case TextVAlign::TOP: break;
|
||||
case TextVAlign::MIDDLE: text_pos.y = (t + b + font_size) * 0.5f; break;
|
||||
case TextVAlign::BOTTOM: text_pos.y = b; break;
|
||||
case TextVAlign::MIDDLE: text_pos.y = (t + b + getAscender(*font) - getDescender(*font)) * 0.5f; break;
|
||||
case TextVAlign::BOTTOM: text_pos.y = b + getDescender(*font); break;
|
||||
}
|
||||
|
||||
switch (rect.text->horizontal_align) {
|
||||
|
|
|
@ -22,12 +22,14 @@ struct Font {
|
|||
FontResource* resource;
|
||||
HashMap<u32, Glyph> glyphs;
|
||||
u32 font_size = 0;
|
||||
float descender = 0;
|
||||
float ascender = 0;
|
||||
u32 ref = 0;
|
||||
};
|
||||
|
||||
float getAdvanceY(const Font& font) {
|
||||
return float(font.font_size);
|
||||
}
|
||||
float getAdvanceY(const Font& font) { return float(font.font_size); }
|
||||
float getDescender(const Font& font) { return font.descender; }
|
||||
float getAscender(const Font& font) { return font.ascender; }
|
||||
|
||||
const Glyph* findGlyph(const Font& font, u32 codepoint) {
|
||||
auto iter = font.glyphs.find(codepoint);
|
||||
|
@ -152,6 +154,8 @@ bool FontManager::build()
|
|||
continue;
|
||||
}
|
||||
|
||||
font->descender = face->descender / 64.f;
|
||||
font->ascender = face->ascender / 64.f;
|
||||
for (Glyph& c : font->glyphs) {
|
||||
c.u0 = c.v0 = 0;
|
||||
c.u1 = c.v1 = 1;
|
||||
|
|
|
@ -28,6 +28,8 @@ struct Glyph {
|
|||
LUMIX_RENDERER_API Vec2 measureTextA(const Font& font, const char* str, const char* str_end);
|
||||
LUMIX_RENDERER_API const Glyph* findGlyph(const Font& font, u32 codepoint);
|
||||
LUMIX_RENDERER_API float getAdvanceY(const Font& font);
|
||||
LUMIX_RENDERER_API float getDescender(const Font& font);
|
||||
LUMIX_RENDERER_API float getAscender(const Font& font);
|
||||
|
||||
|
||||
struct LUMIX_RENDERER_API FontResource final : Resource
|
||||
|
|
Loading…
Reference in a new issue