← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/fsmenu_fullscreen_2_about into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/fsmenu_fullscreen_2_about into lp:widelands.

Commit message:
The About menu now relayouts itself when fullscreen mode is toggled.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1398733 in widelands: "Fullscreen Menus cannot relayout themselves"
  https://bugs.launchpad.net/widelands/+bug/1398733

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fsmenu_fullscreen_2_about/+merge/309754
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fsmenu_fullscreen_2_about into lp:widelands.
=== modified file 'src/ui_basic/fileview_panel.cc'
--- src/ui_basic/fileview_panel.cc	2016-08-04 15:49:05 +0000
+++ src/ui_basic/fileview_panel.cc	2016-11-01 13:19:49 +0000
@@ -36,6 +36,7 @@
                              const Image* background,
                              TabPanel::Type border_type)
    : TabPanel(parent, x, y, w, h, background, border_type), padding_(5) {
+	layout();
 }
 
 void FileViewPanel::add_tab(const std::string& lua_script) {
@@ -53,21 +54,34 @@
 	   std::unique_ptr<UI::Box>(new UI::Box(this, 0, 0, UI::Box::Vertical, 0, 0, padding_)));
 	size_t index = boxes_.size() - 1;
 
-	// If there is a border, we have less space
-	const int width =
+	textviews_.push_back(std::unique_ptr<UI::MultilineTextarea>(
+	   new UI::MultilineTextarea(boxes_.at(index).get(), 0, 0, Scrollbar::kSize, 0, content)));
+	add((boost::format("about_%lu") % index).str(), title, boxes_.at(index).get(), "");
+
+	assert(boxes_.size() == textviews_.size());
+	assert(tabs().size() == textviews_.size());
+	update_tab_size(index);
+}
+
+void FileViewPanel::update_tab_size(size_t index) {
+	boxes_.at(index)->set_size(get_inner_w(), get_inner_h());
+	textviews_.at(index)->set_size(contents_width_, contents_height_);
+}
+
+void FileViewPanel::layout() {
+	assert(boxes_.size() == textviews_.size());
+
+	// If there is a border, we have less space for the contents
+	contents_width_ =
 	   border_type_ == TabPanel::Type::kNoBorder ? get_w() - padding_ : get_w() - 2 * padding_;
 
-	const int height = border_type_ == TabPanel::Type::kNoBorder ?
+	contents_height_ = border_type_ == TabPanel::Type::kNoBorder ?
 	                      get_inner_h() - 2 * padding_ - UI::kTabPanelButtonHeight :
 	                      get_inner_h() - 3 * padding_ - UI::kTabPanelButtonHeight;
 
-	textviews_.push_back(std::unique_ptr<UI::MultilineTextarea>(
-	   new UI::MultilineTextarea(boxes_.at(index).get(), 0, 0, width, height, content)));
-	add((boost::format("about_%lu") % index).str(), title, boxes_.at(index).get(), "");
-	boxes_.at(index)->set_size(get_inner_w(), get_inner_h());
-
-	assert(boxes_.size() == textviews_.size());
-	assert(tabs().size() == textviews_.size());
+	for (size_t i = 0; i < boxes_.size(); ++i) {
+		update_tab_size(i);
+	}
 }
 
 }  // namespace UI

=== modified file 'src/ui_basic/fileview_panel.h'
--- src/ui_basic/fileview_panel.h	2016-08-04 15:49:05 +0000
+++ src/ui_basic/fileview_panel.h	2016-11-01 13:19:49 +0000
@@ -48,7 +48,11 @@
 	void add_tab(const std::string& lua_script);
 
 private:
+	void update_tab_size(size_t index);
+	void layout() override;
 	const uint32_t padding_;
+	int contents_width_;
+	int contents_height_;
 
 	// Tab contents
 	std::vector<std::unique_ptr<Box>> boxes_;

=== modified file 'src/ui_fsmenu/about.cc'
--- src/ui_fsmenu/about.cc	2016-10-24 14:04:00 +0000
+++ src/ui_fsmenu/about.cc	2016-11-01 13:19:49 +0000
@@ -26,39 +26,36 @@
 
 FullscreenMenuAbout::FullscreenMenuAbout()
    : FullscreenMenuBase(),
-
-     // Values for alignment and size
-     butw_(get_w() / 5),
-     buth_(get_h() * 9 / 200),
-     hmargin_(get_w() * 19 / 200),
-     tab_panel_width_(get_inner_w() - 2 * hmargin_),
-     tab_panel_y_(get_h() * 14 / 100),
-
-     title_(this, get_w() / 2, buth_, _("About Widelands"), UI::Align::kCenter),
-
-     close_(this,
-            "close",
-            get_w() * 2 / 4 - butw_ / 2,
-            get_inner_h() - hmargin_,
-            butw_,
-            buth_,
-            g_gr->images().get("images/ui_basic/but2.png"),
-            _("Close")),
-
+     title_(this, 0, 0, _("About Widelands"), UI::Align::kCenter),
+     close_(this, "close", 0, 0, 0, 0, g_gr->images().get("images/ui_basic/but2.png"), _("Close")),
      tabs_(this,
-           hmargin_,
-           0,
-           tab_panel_width_,
-           get_inner_h() - tab_panel_y_ - buth_ - hmargin_,
+           0,
+           0,
+           0,
+           0,
            g_gr->images().get("images/ui_basic/but1.png"),
            UI::TabPanel::Type::kBorder) {
 	title_.set_fontsize(UI_FONT_SIZE_BIG);
-	tabs_.set_pos(Vector2i(hmargin_, tab_panel_y_));
-
 	tabs_.add_tab("txts/README.lua");
 	tabs_.add_tab("txts/LICENSE.lua");
 	tabs_.add_tab("txts/AUTHORS.lua");
 	tabs_.add_tab("txts/TRANSLATORS.lua");
-
 	close_.sigclicked.connect(boost::bind(&FullscreenMenuAbout::clicked_back, this));
+	layout();
+}
+
+void FullscreenMenuAbout::layout() {
+	// Values for alignment and size
+	butw_ = get_w() / 5;
+	buth_ = get_h() * 9 / 200;
+	hmargin_ = get_w() * 19 / 200;
+	tab_panel_width_ = get_inner_w() - 2 * hmargin_;
+	tab_panel_y_ = get_h() * 14 / 100;
+
+	title_.set_size(get_w(), title_.get_h());
+	title_.set_pos(Vector2i(0, buth_));
+	close_.set_size(butw_, buth_);
+	close_.set_pos(Vector2i(get_w() * 2 / 4 - butw_ / 2, get_inner_h() - hmargin_));
+	tabs_.set_pos(Vector2i(hmargin_, tab_panel_y_));
+	tabs_.set_size(tab_panel_width_, get_inner_h() - tab_panel_y_ - buth_ - hmargin_);
 }

=== modified file 'src/ui_fsmenu/about.h'
--- src/ui_fsmenu/about.h	2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/about.h	2016-11-01 13:19:49 +0000
@@ -33,11 +33,13 @@
 	FullscreenMenuAbout();
 
 private:
-	uint32_t const butw_;
-	uint32_t const buth_;
-	uint32_t const hmargin_;
-	uint32_t const tab_panel_width_;
-	uint32_t const tab_panel_y_;
+	void layout() override;
+
+	uint32_t butw_;
+	uint32_t buth_;
+	uint32_t hmargin_;
+	uint32_t tab_panel_width_;
+	uint32_t tab_panel_y_;
 
 	UI::Textarea title_;
 	UI::Button close_;


Follow ups