Skip to content

Commit f0b6500

Browse files
committed
fix: align custom texts
1 parent 7818cf4 commit f0b6500

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Features/Hud/Hud.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,15 @@ HUD_ELEMENT2_NO_DISABLE(text, HudType_InGame | HudType_Paused | HudType_Menu | H
404404
for (auto &t : sar_hud_text_vals) {
405405
int x = ctx->xPadding;
406406
int y = ctx->yPadding + ctx->elements * (ctx->fontSize + ctx->spacing);
407+
int totalPixLen = 0;
408+
for (auto &c : t.second.components) totalPixLen += surface->GetFontLength(ctx->font, "%s", c.text.c_str());
409+
int align = sar_hud_align.GetInt();
410+
int offset = !align ? 0 : align == 1 ? totalPixLen / 2 : totalPixLen;
407411
if (t.second.draw) {
408412
for (auto &c : t.second.components) {
409413
Color color = c.color ? *c.color : t.second.defaultColor ? *t.second.defaultColor : ctx->textColor;
410414
int pixLen = surface->GetFontLength(ctx->font, "%s", c.text.c_str());
411-
surface->DrawTxt(ctx->font, x, y, color, "%s", c.text.c_str());
415+
surface->DrawTxt(ctx->font, x - offset, y, color, "%s", c.text.c_str());
412416
x += pixLen;
413417
}
414418

0 commit comments

Comments
 (0)