MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / getStringWidthNewlined

Function getStringWidthNewlined

src/openrct2/drawing/Drawing.String.cpp:38–65  ·  view source on GitHub ↗

* * rct2: 0x006C23B1 */

Source from the content-addressed store, hash-verified

36 * rct2: 0x006C23B1
37 */
38 int32_t getStringWidthNewlined(std::string_view text, FontStyle fontStyle)
39 {
40 u8string buffer;
41
42 std::optional<int32_t> maxWidth;
43 FmtString fmt(text);
44 for (const auto& token : fmt)
45 {
46 if (token.kind == FormatToken::newline || token.kind == FormatToken::newlineSmall)
47 {
48 auto width = getStringWidth(buffer, fontStyle);
49 if (!maxWidth.has_value() || maxWidth.value() > width)
50 {
51 maxWidth = width;
52 }
53 buffer.clear();
54 }
55 else
56 {
57 buffer.append(token.text);
58 }
59 }
60 if (!maxWidth.has_value())
61 {
62 maxWidth = getStringWidth(buffer, fontStyle);
63 }
64 return maxWidth.value();
65 }
66
67 /**
68 * Clip the text in buffer to width, add ellipsis and return the new width of the clipped string

Callers 2

ErrorOpenFunction · 0.85
FormatTextForTooltipMethod · 0.85

Calls 4

getStringWidthFunction · 0.85
valueMethod · 0.80
appendMethod · 0.80
clearMethod · 0.65

Tested by

no test coverage detected