From 4c99b5b368e2c384553ac42278ea555b61d96d00 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 21 Feb 2025 23:38:33 +0000 Subject: [PATCH] Codechange: Return pair from GetBroadestDigit instead of out parameters. --- src/gfx.cpp | 22 +++++++++++++--------- src/gfx_func.h | 2 +- src/strings.cpp | 4 +--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index e4e2f299e5..20e3689e7e 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1248,21 +1248,25 @@ uint8_t GetDigitWidth(FontSize size) /** * 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.) - * @param[out] next Broadest digit, including 0. (Use this digit for all digits, except the first one; or for numbers with only one digit.) - * @param size Font of the digit + * @param size Font of the digit + * @returns Broadest digits, first which is not 0 (use this digit as first digit for numbers with more than one + * digit.), second including 0 (use this digit for all digits, except the first one; or for numbers with + * only one digit.) */ -void GetBroadestDigit(uint *front, uint *next, FontSize size) +std::pair GetBroadestDigit(FontSize size) { + uint8_t front = 0; + uint8_t next = 0; int width = -1; for (char c = '9'; c >= '0'; c--) { int w = GetCharacterWidth(size, c); - if (w > width) { - width = w; - *next = c - '0'; - if (c != '0') *front = c - '0'; - } + if (w <= width) continue; + + width = w; + next = c - '0'; + if (c != '0') front = c - '0'; } + return {front, next}; } void ScreenSizeChanged() diff --git a/src/gfx_func.h b/src/gfx_func.h index 63927c475d..fb9a657900 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -183,7 +183,7 @@ bool ToggleFullScreen(bool fs); /* gfx.cpp */ uint8_t GetCharacterWidth(FontSize size, char32_t key); uint8_t GetDigitWidth(FontSize size = FS_NORMAL); -void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL); +std::pair GetBroadestDigit(FontSize size); int GetCharacterHeight(FontSize size); diff --git a/src/strings.cpp b/src/strings.cpp index d8e9078fd5..270ca3b396 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -201,9 +201,7 @@ void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize si */ void SetDParamMaxDigits(size_t n, uint count, FontSize size) { - uint front = 0; - uint next = 0; - GetBroadestDigit(&front, &next, size); + auto [front, next] = GetBroadestDigit(size); uint64_t val = count > 1 ? front : next; for (; count > 1; count--) { val = 10 * val + next;