FS#13537: format_sound_value alignment issue in themes

Positive values included a leading space, which
meant they weren't displayed center-aligned in
themes anymore.

Change-Id: Ibe75e9b81a2989c87630dd3ea78e4b90c6c74502
This commit is contained in:
Christian Soffke 2025-01-02 02:10:16 +01:00
parent af7ed73f31
commit 384c35418a
3 changed files with 28 additions and 18 deletions

View file

@ -1167,8 +1167,7 @@ void replaygain_update(void)
dsp_replaygain_set_settings(&settings);
}
/* format a sound value like: -1.05 dB */
int format_sound_value(char *buf, size_t size, int snd, int val)
void format_sound_value_ex(char *buf, size_t buf_sz, int snd, int val, bool skin_token)
{
int numdec = sound_numdecimals(snd);
const char *unit = sound_unit(snd);
@ -1183,8 +1182,15 @@ int format_sound_value(char *buf, size_t size, int snd, int val)
unsigned int av = abs(physval);
unsigned int i = av / factor;
unsigned int d = av - i*factor;
return snprintf(buf, size, "%c%u%.*s%.*u %s", " -"[physval < 0],
i, numdec, ".", numdec, d, unit);
snprintf(buf, buf_sz, "%s%u%.*s%.*u%s%s", physval < 0 ? "-" : &" "[skin_token],
i, numdec, ".", numdec, d, &" "[skin_token], skin_token ? "" : unit);
}
/* format a sound value as "-1.05 dB", or " 1.05 dB" */
void format_sound_value(char *buf, size_t buf_sz, int snd, int val)
{
format_sound_value_ex(buf, buf_sz, snd, val, false);
}
#endif /* !defined(__PCTOOL__) */