mirror of https://github.com/OpenTTD/OpenTTD
Fix 96d98d08: Crash in text layouter due to trying to find height of string with zero-width.
96d98d08
removed the hardcoded minimum width in favour of all-calculated widths, however this does not work when determining multiline text sizes.
pull/11481/head
parent
62d4fd0572
commit
0d60dc0353
|
@ -297,33 +297,21 @@ struct SelectGameWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateWidgetSize(int widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
void OnResize() override
|
||||||
{
|
{
|
||||||
StringID str = 0;
|
bool changed = false;
|
||||||
switch (widget) {
|
|
||||||
case WID_SGI_BASESET:
|
|
||||||
SetDParam(0, _missing_extra_graphics);
|
|
||||||
str = STR_INTRO_BASESET;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WID_SGI_TRANSLATION:
|
if (NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_SGI_BASESET); wid != nullptr && wid->current_x > 0) {
|
||||||
SetDParam(0, _current_language->missing);
|
SetDParam(0, _missing_extra_graphics);
|
||||||
str = STR_INTRO_TRANSLATION;
|
changed |= wid->UpdateMultilineWidgetSize(GetString(STR_INTRO_BASESET), 3);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str != 0) {
|
if (NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_SGI_TRANSLATION); wid != nullptr && wid->current_x > 0) {
|
||||||
int height = GetStringHeight(str, size->width);
|
SetDParam(0, _current_language->missing);
|
||||||
if (height > 3 * FONT_HEIGHT_NORMAL) {
|
changed |= wid->UpdateMultilineWidgetSize(GetString(STR_INTRO_TRANSLATION), 3);
|
||||||
/* Don't let the window become too high. */
|
|
||||||
Dimension textdim = GetStringBoundingBox(str);
|
|
||||||
textdim.height *= 3;
|
|
||||||
textdim.width -= textdim.width / 2;
|
|
||||||
*size = maxdim(*size, textdim);
|
|
||||||
} else {
|
|
||||||
size->height = height + padding.height;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed) this->ReInit(0, 0, this->flags & WF_CENTERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override
|
void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override
|
||||||
|
|
Loading…
Reference in New Issue