Change: Make vehicle list dropdown buttons resize to fit strings. (#10286)

This commit is contained in:
PeterN
2022-12-27 18:39:37 +00:00
committed by GitHub
parent 6caed5f15e
commit f7e2b6ef12
4 changed files with 76 additions and 20 deletions

View File

@@ -922,6 +922,21 @@ Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize)
return GetStringBoundingBox(buffer, start_fontsize);
}
/**
* Get maximum width of a list of strings.
* @param list List of strings, terminated with INVALID_STRING_ID.
* @param fontsize Font size to use.
* @return Width of longest string within the list.
*/
uint GetStringListWidth(const StringID *list, FontSize fontsize)
{
uint width = 0;
for (const StringID *str = list; *str != INVALID_STRING_ID; str++) {
width = std::max(width, GetStringBoundingBox(*str, fontsize).width);
}
return width;
}
/**
* Get the leading corner of a character in a single-line string relative
* to the start of the string.