Factor out function to get value with broadest digits

pull/532/head
Jonathan G Rennison 1 year ago
parent 18a79a35d0
commit a10c5a62c9

@ -1528,6 +1528,24 @@ byte GetDigitWidth(FontSize size)
return width;
}
/**
* Return some number that is suitable for string size computations.
* @param count Number of digits which shall be displayable.
* @param size Font of the number
* @return The number.
*/
uint64 GetBroadestDigitsValue(uint count, FontSize size)
{
uint front = 0;
uint next = 0;
GetBroadestDigit(&front, &next, size);
uint64 val = count > 1 ? front : next;
for (; count > 1; count--) {
val = 10 * val + next;
}
return val;
}
/**
* Determine the broadest digits for guessing the maximum width of a n-digit number.
* @param[out] front Broadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.)

@ -220,6 +220,7 @@ bool ToggleFullScreen(bool fs);
byte GetCharacterWidth(FontSize size, WChar key);
byte GetDigitWidth(FontSize size = FS_NORMAL);
void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
uint64 GetBroadestDigitsValue(uint count, FontSize size = FS_NORMAL);
extern int font_height_cache[FS_END];

@ -116,14 +116,7 @@ void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
*/
void SetDParamMaxDigits(uint n, uint count, FontSize size)
{
uint front = 0;
uint next = 0;
GetBroadestDigit(&front, &next, size);
uint64 val = count > 1 ? front : next;
for (; count > 1; count--) {
val = 10 * val + next;
}
SetDParam(n, val);
SetDParam(n, GetBroadestDigitsValue(count, size));
}
/**

Loading…
Cancel
Save