Skip to content

Commit d0eebba

Browse files
committed
feat: sar_toast_align_text
1 parent 0e1cba1 commit d0eebba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/cvars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@
621621
|sar_timer_stop|cmd|sar_timer_stop - stops timer|
622622
|sar_timer_time_pauses|1|Timer adds non-simulated ticks when server pauses.|
623623
|sar_toast_align|0|The side to align toasts to horizontally. 0 = left, 1 = center, 2 = right.|
624+
|sar_toast_align_text|0|The side to align text to inside toasts horizontally. 0 = left, 1 = center, 2 = right.|
624625
|sar_toast_anchor|1|Where to put new toasts. 0 = bottom, 1 = top.|
625626
|sar_toast_background|1|Sets the background highlight for toasts. 0 = no background, 1 = text width only, 2 = full width.|
626627
|sar_toast_compact|0|Enables a compact form of the toasts HUD.|

src/Features/Hud/Toasts.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Variable sar_toast_width("sar_toast_width", "250", 2 * SIDE_PAD + 10, "The maxim
6060
Variable sar_toast_x("sar_toast_x", EXP_STR(TOAST_GAP), 0, "The horizontal position of the toasts HUD.\n", FCVAR_DONTRECORD);
6161
Variable sar_toast_y("sar_toast_y", EXP_STR(TOAST_GAP), 0, "The vertical position of the toasts HUD.\n", FCVAR_DONTRECORD);
6262
Variable sar_toast_align("sar_toast_align", "0", 0, 2, "The side to align toasts to horizontally. 0 = left, 1 = center, 2 = right.\n", FCVAR_DONTRECORD);
63+
Variable sar_toast_align_text("sar_toast_align_text", "0", 0, 2, "The side to align text to inside toasts horizontally. 0 = left, 1 = center, 2 = right.\n", FCVAR_DONTRECORD);
6364
Variable sar_toast_anchor("sar_toast_anchor", "1", 0, 1, "Where to put new toasts. 0 = bottom, 1 = top.\n", FCVAR_DONTRECORD);
6465
Variable sar_toast_compact("sar_toast_compact", "0", "Enables a compact form of the toasts HUD.\n", FCVAR_DONTRECORD);
6566
Variable sar_toast_background("sar_toast_background", "1", 0, 2, "Sets the background highlight for toasts. 0 = no background, 1 = text width only, 2 = full width.\n", FCVAR_DONTRECORD);
@@ -196,12 +197,15 @@ CON_COMMAND_F(sar_toast_setpos, "sar_toast_setpos <bottom|top> <left|center|righ
196197

197198
if (!strcmp(args[2], "left")) {
198199
sar_toast_align.SetValue(0);
200+
sar_toast_align_text.SetValue(0);
199201
sar_toast_x.SetValue(TOAST_GAP);
200202
} else if (!strcmp(args[2], "center")) {
201203
sar_toast_align.SetValue(1);
204+
sar_toast_align_text.SetValue(1);
202205
sar_toast_x.SetValue((screenWidth - sar_toast_width.GetInt()) / 2);
203206
} else {
204207
sar_toast_align.SetValue(2);
208+
sar_toast_align_text.SetValue(2);
205209
sar_toast_x.SetValue(screenWidth - sar_toast_width.GetInt() - TOAST_GAP);
206210
}
207211
}
@@ -391,6 +395,7 @@ void ToastHud::Paint(int slot) {
391395
int maxWidth = sar_toast_width.GetInt();
392396

393397
Alignment align = (Alignment)sar_toast_align.GetInt();
398+
Alignment textalign = (Alignment)sar_toast_align_text.GetInt();
394399
bool againstTop = sar_toast_anchor.GetBool();
395400

396401
int mainX = sar_toast_x.GetInt();
@@ -449,7 +454,12 @@ void ToastHud::Paint(int slot) {
449454

450455
for (std::string line : lines) {
451456
int length = surface->GetFontLength(font, "%s", line.c_str());
452-
int pad = (longestLine - length) / 2;
457+
int pad = 0;
458+
if (textalign == Alignment::CENTER) {
459+
pad = (longestLine - length) / 2;
460+
} else if (textalign == Alignment::RIGHT) {
461+
pad = longestLine - length;
462+
}
453463
surface->DrawTxt(font, xLeft + sidePadding + pad, yOffset, textCol, "%s", line.c_str());
454464
yOffset += lineHeight;
455465
}

0 commit comments

Comments
 (0)