← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/bug887737 into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/bug887737 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #887737 in widelands: "Player and category buttons in the general statistics window"
  https://bugs.launchpad.net/widelands/+bug/887737

For more details, see:
https://code.launchpad.net/~nomeata/widelands/bug887737/+merge/90035
-- 
https://code.launchpad.net/~nomeata/widelands/bug887737/+merge/90035
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/bug887737 into lp:widelands.
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc	2011-11-30 21:38:37 +0000
+++ src/ui_basic/box.cc	2012-01-25 03:00:32 +0000
@@ -195,7 +195,7 @@
 	// Second pass: Count number of infinite spaces
 	uint32_t infspace_count = 0;
 	for (uint32_t idx = 0; idx < m_items.size(); ++idx)
-		if (m_items[idx].type == Item::ItemInfSpace)
+		if (m_items[idx].fillspace)
 			infspace_count++;
 
 	// Third pass: Distribute left over space to all infinite spaces. To
@@ -205,10 +205,10 @@
 	uint32_t max_depths =
 		m_orientation == Horizontal ? get_inner_w() : get_inner_h();
 	for (uint32_t idx = 0; idx < m_items.size(); ++idx)
-		if (m_items[idx].type == Item::ItemInfSpace) {
-			m_items[idx].u.assigned_space =
+		if (m_items[idx].fillspace) {
+			m_items[idx].assigned_var_depth =
 				(max_depths - totaldepth) / infspace_count;
-			totaldepth += m_items[idx].u.assigned_space;
+			totaldepth += m_items[idx].assigned_var_depth;
 			infspace_count--;
 	}
 
@@ -256,8 +256,11 @@
  * @param fullsize when true, @p panel will be extended to cover the entire width (or height)
  * of the box for horizontal (vertical) panels. If false, then @p panel may end up smaller;
  * in that case, it will be aligned according to @p align
+ *
+ * @param fillspace when true, @p panel will be expanded as an infinite space would be. This can be used to make buttons fill a box completely.
+ * 
  */
-void Box::add(Panel * const panel, uint32_t const align, bool fullsize)
+void Box::add(Panel * const panel, uint32_t const align, bool fullsize, bool fillspace)
 {
 	Item it;
 
@@ -265,6 +268,8 @@
 	it.u.panel.panel = panel;
 	it.u.panel.align = align;
 	it.u.panel.fullsize = fullsize;
+	it.fillspace = fillspace;
+	it.assigned_var_depth = 0;
 
 	m_items.push_back(it);
 
@@ -281,6 +286,7 @@
 
 	it.type = Item::ItemSpace;
 	it.u.space = space;
+	it.fillspace = false;
 
 	m_items.push_back(it);
 
@@ -295,8 +301,10 @@
 {
 	Item it;
 
-	it.type = Item::ItemInfSpace;
-	it.u.assigned_space = 0;
+	it.type = Item::ItemSpace;
+	it.u.space = 0;
+	it.assigned_var_depth = 0;
+	it.fillspace = true;
 
 	m_items.push_back(it);
 
@@ -330,11 +338,6 @@
 		breadth = 0;
 		break;
 
-	case Item::ItemInfSpace:
-		depth   = 0;
-		breadth = 0;
-		break;
-
 	default:
 		throw wexception("Box::get_item_size: bad type %u", it.type);
 	}
@@ -342,7 +345,7 @@
 
 /**
  * Retrieve the given item's size. This differs from get_item_desired_size only
- * for InfSpace items, at least for now.
+ * for expanding items, at least for now.
  */
 void Box::get_item_size
 	(uint32_t const idx, uint32_t & depth, uint32_t & breadth)
@@ -351,16 +354,8 @@
 
 	Item const & it = m_items[idx];
 
-	switch (it.type) {
-	case Item::ItemInfSpace:
-		depth   = it.u.assigned_space;
-		breadth = 0;
-		break;
-
-	default:
-		get_item_desired_size(idx, depth, breadth);
-	}
-
+	get_item_desired_size(idx, depth, breadth);
+	depth += it.assigned_var_depth;
 }
 
 /**
@@ -424,8 +419,6 @@
 	}
 
 	case Item::ItemSpace:; //  no need to do anything
-
-	case Item::ItemInfSpace:; //  no need to do anything
 	};
 }
 

=== modified file 'src/ui_basic/box.h'
--- src/ui_basic/box.h	2011-11-30 21:38:37 +0000
+++ src/ui_basic/box.h	2012-01-25 03:00:32 +0000
@@ -55,7 +55,10 @@
 
 	int32_t get_nritems() const {return m_items.size();}
 
-	void add(Panel * panel, uint32_t align, bool fullsize = false);
+	void add(Panel * panel,
+		uint32_t align,
+		bool fullsize = false,
+		bool fillspace = false);
 	void add_space(uint32_t space);
 	void add_inf_space();
 	bool is_snap_target() const {return true;}
@@ -82,7 +85,6 @@
 		enum Type {
 			ItemPanel,
 			ItemSpace,
-			ItemInfSpace
 		};
 
 		Type type;
@@ -94,8 +96,10 @@
 				bool fullsize;
 			} panel;
 			uint32_t space;
-			uint32_t assigned_space;
 		} u;
+
+		bool fillspace;
+		uint32_t assigned_var_depth;
 	};
 
 	bool m_scrolling;

=== modified file 'src/wui/general_statistics_menu.cc'
--- src/wui/general_statistics_menu.cc	2011-11-30 21:38:37 +0000
+++ src/wui/general_statistics_menu.cc	2012-01-25 03:00:32 +0000
@@ -157,11 +157,11 @@
 
 		m_cbs[p - 1] = &cb;
 
-		hbox1->add(&cb, UI::Box::AlignLeft);
+		hbox1->add(&cb, UI::Box::AlignLeft, false, true);
 	} else //  player nr p does not exist
 		m_cbs[p - 1] = 0;
 
-	m_box.add(hbox1, UI::Box::AlignTop);
+	m_box.add(hbox1, UI::Box::AlignTop, true);
 
 	UI::Box * hbox2 = new UI::Box(&m_box, 0, 0, UI::Box::Horizontal, 0, 0, 1);
 
@@ -173,7 +173,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_landsize.png"),
 		 _("Land"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -181,7 +181,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_nrworkers.png"),
 		 _("Workers"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -189,7 +189,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_nrbuildings.png"),
 		 _("Buildings"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -197,7 +197,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_nrwares.png"),
 		 _("Wares"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -205,7 +205,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_productivity.png"),
 		 _("Productivity"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -213,7 +213,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_casualties.png"),
 		 _("Casualties"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -221,7 +221,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_kills.png"),
 		 _("Kills"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -229,7 +229,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_msites_lost.png"),
 		 _("Military buildings lost"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -237,7 +237,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_msites_defeated.png"),
 		 _("Military buildings defeated"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -245,7 +245,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_civil_blds_lost.png"),
 		 _("Civilian buildings lost"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	m_radiogroup.add_button
 		(hbox2,
@@ -253,7 +253,7 @@
 		 g_gr->get_picture(PicMod_Game, "pics/genstats_militarystrength.png"),
 		 _("Military"),
 		 &btn);
-	hbox2->add(btn, UI::Box::AlignLeft);
+	hbox2->add(btn, UI::Box::AlignLeft, false, true);
 
 	if (hook) {
 		m_radiogroup.add_button
@@ -262,14 +262,14 @@
 			 g_gr->get_picture(PicMod_Game, cs_pic),
 			 cs_name.c_str(),
 			 &btn);
-		hbox2->add(btn, UI::Box::AlignLeft);
+		hbox2->add(btn, UI::Box::AlignLeft, false, true);
 	}
 
 	m_radiogroup.set_state(m_selected_information);
 	m_radiogroup.changedto.connect
 		(boost::bind(&General_Statistics_Menu::radiogroup_changed, this, _1));
 
-	m_box.add(hbox2, UI::Box::AlignTop);
+	m_box.add(hbox2, UI::Box::AlignTop, true);
 
 	m_box.add
 		(new WUIPlot_Area_Slider


Follow ups