From f2f9ef7a9f72efb5bc1f0011f9e3f08011a0989e Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 29 Nov 2009 21:17:37 +0000 Subject: (svn r18347) -Codechange: Compute width of labels in news settings window once. --- src/news_gui.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/news_gui.cpp') diff --git a/src/news_gui.cpp b/src/news_gui.cpp index c36fe29ec..314f268cf 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. } -- cgit v1.2.3-54-g00ecf