widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #05964
[Merge] lp:~widelands-dev/widelands/building-statistics-window-labels into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/building-statistics-window-labels into lp:widelands.
Commit message:
Fixes/Improvements to Building Statistics:
- The labels below the buttons are now properly center-aligned
- The text size of the labels below the buttons is now calculated based on on actual available space
- Fixed bug where some perm_pressed buttons weren't reset.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1539906 in widelands: "Buttons in building statistics window are ever shown deepened"
https://bugs.launchpad.net/widelands/+bug/1539906
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/building-statistics-window-labels/+merge/285292
Fixes/Improvements to Building Statistics:
- The labels below the buttons are now properly center-aligned
- The text size of the labels below the buttons is now calculated based on on actual available space
- Fixed bug where some perm_pressed buttons weren't reset.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/building-statistics-window-labels into lp:widelands.
=== modified file 'src/wui/building_statistics_menu.cc'
--- src/wui/building_statistics_menu.cc 2016-01-31 10:57:58 +0000
+++ src/wui/building_statistics_menu.cc 2016-02-07 11:03:02 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team
+ * Copyright (C) 2002-2016 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -399,11 +399,11 @@
owned_labels_[id] =
new UI::Textarea(button_box, 0, 0, kBuildGridCellWidth, kLabelHeight, UI::Align::kCenter);
- button_box->add(owned_labels_[id], UI::Align::kLeft);
+ button_box->add(owned_labels_[id], UI::Align::kHCenter);
productivity_labels_[id] =
new UI::Textarea(button_box, 0, 0, kBuildGridCellWidth, kLabelHeight, UI::Align::kCenter);
- button_box->add(productivity_labels_[id], UI::Align::kLeft);
+ button_box->add(productivity_labels_[id], UI::Align::kHCenter);
row.add(button_box, UI::Align::kLeft);
@@ -419,6 +419,7 @@
++*column;
if (*column == kColumns) {
tabs_[tab_index]->add(&row, UI::Align::kLeft);
+ tabs_[tab_index]->add_space(6);
*column = 0;
return true;
}
@@ -762,30 +763,45 @@
void BuildingStatisticsMenu::set_labeltext_autosize(UI::Textarea* textarea,
const std::string& text,
const RGBColor& color) {
- int fontsize = text.length() > 7 ? kLabelFontSize - floor(text.length() / 3) : kLabelFontSize;
-
- UI::TextStyle style;
- if (text.length() > 5) {
- style.font = UI::Font::get(UI::g_fh1->fontset().condensed(), fontsize);
- } else {
- style.font = UI::Font::get(UI::g_fh1->fontset().serif(), fontsize);
- }
- style.fg = color;
- style.bold = true;
-
- textarea->set_textstyle(style);
+
+ const int min_font_size = 6;
+ const int max_width = kBuildGridCellWidth - 2;
+ const int max_height = kLabelHeight - 2;
+
+ int font_size = UI_FONT_SIZE_SMALL;
+ std::string fontset = UI::g_fh1->fontset().serif();
+
+ textarea->set_font(fontset, font_size, color);
textarea->set_text(text);
+
+ while (textarea->get_h() > max_height && font_size > min_font_size) {
+ --font_size;
+ textarea->set_font(fontset, font_size, color);
+ }
+
+ if (textarea->get_w() > max_width) {
+ fontset = UI::g_fh1->fontset().condensed();
+ while (textarea->get_w() > max_width && font_size > min_font_size) {
+ --font_size;
+ textarea->set_font(fontset, font_size, color);
+ }
+ }
+
textarea->set_visible(true);
}
void BuildingStatisticsMenu::set_current_building_type(DescriptionIndex id) {
assert(building_buttons_[id] != nullptr);
- current_building_type_ = id;
- for (DescriptionIndex i = 0; i < iplayer().player().tribe().get_nrbuildings(); ++i) {
+
+ // Reset button states
+ for (size_t i = 0; i < building_buttons_.size(); ++i) {
if (building_buttons_[i] != nullptr) {
building_buttons_[i]->set_flat(true);
}
}
+
+ // Update for current button
+ current_building_type_ = id;
building_buttons_[current_building_type_]->set_flat(false);
building_buttons_[current_building_type_]->set_perm_pressed(true);
building_name_.set_text(iplayer().player().tribe().get_building_descr(id)->descname());
Follow ups