← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/help-button-right into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/help-button-right into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~nomeata/widelands/help-button-right/+merge/81404

Move the help button to the right.

This also fixes the crash introduced in UI::Table and enhances UI::Box.
-- 
https://code.launchpad.net/~nomeata/widelands/help-button-right/+merge/81404
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/help-button-right into lp:widelands.
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc	2011-11-06 12:20:01 +0000
+++ src/ui_basic/box.cc	2011-11-06 14:37:25 +0000
@@ -81,7 +81,9 @@
 }
 
 /**
- * Compute the desired size based on our children.
+ * Compute the desired size based on our children. This assumes that the
+ * infinite space is zero, and is later on also re-used to calculate the
+ * space assigned to an infinite space.
  */
 void Box::update_desired_size()
 {
@@ -105,7 +107,8 @@
 			maxbreadth += Scrollbar::Size;
 		}
 		set_desired_size
-			(std::min(totaldepth, m_max_x), std::min(maxbreadth, m_max_y));
+			(std::min(totaldepth, m_max_x), // + get_lborder() + get_rborder(),
+			 std::min(maxbreadth, m_max_y)); // + get_tborder() + get_bborder());
 	} else {
 		if (totaldepth > m_max_y && m_scrolling) {
 			maxbreadth += Scrollbar::Size;
@@ -188,7 +191,27 @@
 		m_scrollbar = 0;
 	}
 
-	// Second pass: Update positions and sizes of all items
+	// 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)
+			infspace_count++;
+
+	// Third pass: Distribute left over space to all infinite spaces. To
+	// avoid having some pixels left at the end due to rounding errors, we
+	// divide the remaining space by the number of remaining infinite
+	// spaces every time, and not just one.
+	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 =
+				(max_depths - totaldepth) / infspace_count;
+			totaldepth += m_items[idx].u.assigned_space;
+			infspace_count--;
+	}
+
+	// Forth pass: Update positions of all other items
 	update_positions();
 }
 
@@ -203,7 +226,7 @@
 
 	for (uint32_t idx = 0; idx < m_items.size(); ++idx) {
 		uint32_t depth, breadth;
-		get_item_desired_size(idx, depth, breadth);
+		get_item_size(idx, depth, breadth);
 
 		if (m_items[idx].type == Item::ItemPanel) {
 			set_item_size
@@ -261,6 +284,22 @@
 
 
 /**
+ * Add some infinite space (to align some buttons to the right)
+*/
+void Box::add_inf_space()
+{
+	Item it;
+
+	it.type = Item::ItemInfSpace;
+	it.u.assigned_space = 0;
+
+	m_items.push_back(it);
+
+	update_desired_size();
+}
+
+
+/**
  * Retrieve the given item's desired size. depth is the size of the
  * item along the orientation axis, breadth is the size perpendicular
  * to the orientation axis.
@@ -286,12 +325,40 @@
 		breadth = 0;
 		break;
 
+	case Item::ItemInfSpace:
+		depth   = 0;
+		breadth = 0;
+		break;
+
 	default:
 		throw wexception("Box::get_item_size: bad type %u", it.type);
 	}
 }
 
 /**
+ * Retrieve the given item's size. This differs from get_item_desired_size only
+ * for InfSpace items, at least for now.
+ */
+void Box::get_item_size
+	(uint32_t const idx, uint32_t & depth, uint32_t & breadth)
+{
+	assert(idx < m_items.size());
+
+	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);
+	}
+
+}
+
+/**
  * Set the given items actual size.
  */
 void Box::set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth)
@@ -352,6 +419,8 @@
 	}
 
 	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-06 12:20:01 +0000
+++ src/ui_basic/box.h	2011-11-06 14:37:25 +0000
@@ -57,6 +57,7 @@
 
 	void add(Panel * panel, uint32_t align, bool fullsize = false);
 	void add_space(uint32_t space);
+	void add_inf_space();
 	bool is_snap_target() const {return true;}
 
 	void set_min_desired_breadth(uint32_t min);
@@ -67,6 +68,7 @@
 
 private:
 	void get_item_desired_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
+	void get_item_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
 	void set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth);
 	void set_item_pos(uint32_t idx, int32_t pos);
 	void scrollbar_moved(int32_t);
@@ -79,7 +81,8 @@
 	struct Item {
 		enum Type {
 			ItemPanel,
-			ItemSpace
+			ItemSpace,
+			ItemInfSpace
 		};
 
 		Type type;
@@ -91,6 +94,7 @@
 				bool fullsize;
 			} panel;
 			uint32_t space;
+			uint32_t assigned_space;
 		} u;
 	};
 

=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc	2011-11-04 22:49:27 +0000
+++ src/ui_basic/panel.cc	2011-11-06 14:37:25 +0000
@@ -311,6 +311,11 @@
 	if (_desired_w == w && _desired_h == h)
 		return;
 
+	assert(w >= 0);
+	assert(h >= 0);
+	assert(w < 3000);
+	assert(h < 3000);
+
 	_desired_w = w;
 	_desired_h = h;
 	if (!get_layout_toplevel() && _parent) {

=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2011-11-05 16:32:47 +0000
+++ src/ui_basic/table.cc	2011-11-06 14:37:25 +0000
@@ -58,6 +58,7 @@
 	m_last_click_time (-10000),
 	m_last_selection  (no_selection_index()),
 	m_sort_column     (0),
+	m_total_width     (0),
 	m_sort_descending (descending)
 {
 	set_think(false);

=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2011-11-06 13:26:01 +0000
+++ src/wui/buildingwindow.cc	2011-11-06 14:37:25 +0000
@@ -67,7 +67,7 @@
 	vbox->add(m_tabs, UI::Box::AlignLeft, true);
 
 	m_capsbuttons = new UI::Box(vbox, 0, 0, UI::Box::Horizontal);
-	vbox->add(m_capsbuttons, UI::Box::AlignLeft);
+	vbox->add(m_capsbuttons, UI::Box::AlignLeft, true);
 	// actually create buttons on the first call to think(),
 	// so that overriding create_capsbuttons() works
 
@@ -160,17 +160,6 @@
 	bool const can_see = igbase().can_see(owner_number);
 	bool const can_act = igbase().can_act(owner_number);
 
-	if (m_building.descr().has_help_text())
-		capsbuttons->add
-			(new UI::Callback_Button
-				(capsbuttons, "help",
-				 0, 0, 34, 34,
-				 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-				 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
-				 boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
-				 _("Help")),
-			 UI::Box::AlignCenter);
-
 	if (can_act) {
 		if (upcast(Widelands::ProductionSite const, productionsite, &m_building))
 			if (not dynamic_cast<Widelands::MilitarySite const *>(productionsite)) {
@@ -274,6 +263,19 @@
 				 g_gr->get_picture(PicMod_Game, "pics/menu_goto.png"),
 				 boost::bind(&Building_Window::clicked_goto, boost::ref(*this))),
 			 UI::Box::AlignCenter);
+
+	if (m_building.descr().has_help_text())
+		capsbuttons->add_inf_space();
+		capsbuttons->add
+			(new UI::Callback_Button
+				(capsbuttons, "help",
+				 0, 0, 34, 34,
+				 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
+				 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
+				 boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
+				 _("Help")),
+			 UI::Box::AlignCenter);
+
 	}
 }
 


Follow ups