From b85262d6226ccc763a5a5c99d73b53661e4df782 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 29 Nov 2009 21:17:37 +0000 Subject: [PATCH] (svn r18347) -Codechange: Compute width of labels in news settings window once. --- src/news_gui.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index c36fe29ecf..314f268cf9 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -1071,7 +1071,8 @@ enum MessageOptionWidgets { struct MessageOptionsWindow : Window { static const StringID message_opt[]; ///< Message report options, 'off', 'summary', or 'full'. - int state; ///< Option value for setting all categories at once. + int state; ///< Option value for setting all categories at once. + Dimension dim_message_opt; ///< Amount of space needed for a label such that all labels will fit. MessageOptionsWindow(const WindowDesc *desc) : Window() { @@ -1118,6 +1119,12 @@ struct MessageOptionsWindow : Window { } } + virtual void OnInit() + { + this->dim_message_opt = {0, 0}; + for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) this->dim_message_opt = maxdim(this->dim_message_opt, GetStringBoundingBox(*str)); + } + virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget >= WIDGET_NEWSOPT_START_OPTION && widget < WIDGET_NEWSOPT_END_OPTION) { @@ -1126,9 +1133,7 @@ struct MessageOptionsWindow : Window { /* Compute width for the label widget only. */ if ((widget - WIDGET_NEWSOPT_START_OPTION) % MOS_WIDG_PER_SETTING == 1) { - Dimension d = {0, 0}; - for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) d = maxdim(d, GetStringBoundingBox(*str)); - size->width = d.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks. + size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks. } return; } @@ -1139,9 +1144,7 @@ struct MessageOptionsWindow : Window { size->height = FONT_HEIGHT_NORMAL + max(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM); if (widget == WIDGET_NEWSOPT_DROP_SUMMARY) { - Dimension d = {0, 0}; - for (const StringID *str = message_opt; *str != INVALID_STRING_ID; str++) d = maxdim(d, GetStringBoundingBox(*str)); - size->width = d.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks. + size->width = this->dim_message_opt.width + padding.width + MOS_BUTTON_SPACE; // A bit extra for better looks. } else if (widget == WIDGET_NEWSOPT_SOUNDTICKER) { size->width += MOS_BUTTON_SPACE; // A bit extra for better looks. }