mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-27 16:39:09 +00:00
Codechange: Add method to guess the width/height required for a multiline string.
This is necessary for widget layouts where a minimum width is not yet known during UpdateWidgetSize().
This commit is contained in:
@@ -1156,6 +1156,26 @@ void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
|
||||
this->resize_y = resize_y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
bool NWidgetResizeBase::UpdateMultilineWidgetSize(const std::string &str, int max_lines)
|
||||
{
|
||||
int y = GetStringHeight(str, this->current_x);
|
||||
if (y > max_lines * FONT_HEIGHT_NORMAL) {
|
||||
/* Text at the current width is too tall, so try to guess a better width. */
|
||||
Dimension d = GetStringBoundingBox(str);
|
||||
d.height *= max_lines;
|
||||
d.width /= 2;
|
||||
return this->UpdateSize(d.width, d.height);
|
||||
}
|
||||
return this->UpdateVerticalSize(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set absolute (post-scaling) minimal size of the widget.
|
||||
* The window will need to be reinited if the size is changed.
|
||||
|
Reference in New Issue
Block a user