MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateMultilineWidgetSize

Method UpdateMultilineWidgetSize

src/widget.cpp:1114–1125  ·  view source on GitHub ↗

* Try to set optimum widget size for a multiline text widget. * The window will need to be reinited if the size is changed. * @param str Multiline string contents that will fill the widget. * @param max_line Maximum number of lines. * @return true iff the widget minimum size has changed. */

Source from the content-addressed store, hash-verified

1112 * @return true iff the widget minimum size has changed.
1113 */
1114bool NWidgetResizeBase::UpdateMultilineWidgetSize(const std::string &str, int max_lines)
1115{
1116 int y = GetStringHeight(str, this->current_x);
1117 if (y > max_lines * GetCharacterHeight(FS_NORMAL)) {
1118 /* Text at the current width is too tall, so try to guess a better width. */
1119 Dimension d = GetStringBoundingBox(str);
1120 d.height *= max_lines;
1121 d.width /= 2;
1122 return this->UpdateSize(d.width, d.height);
1123 }
1124 return this->UpdateVerticalSize(y);
1125}
1126
1127/**
1128 * Set absolute (post-scaling) minimal size of the widget.

Callers 1

OnResizeMethod · 0.80

Calls 5

UpdateSizeMethod · 0.95
UpdateVerticalSizeMethod · 0.95
GetStringHeightFunction · 0.85
GetCharacterHeightFunction · 0.85
GetStringBoundingBoxFunction · 0.85

Tested by

no test coverage detected