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

Proposed by Joachim Breitner
Status: Merged
Merged at revision: 6084
Proposed branch: lp:~nomeata/widelands/help-button-right
Merge into: lp:widelands
Diff against target: 251 lines (+98/-17)
5 files modified
src/ui_basic/box.cc (+73/-4)
src/ui_basic/box.h (+5/-1)
src/ui_basic/panel.cc (+5/-0)
src/ui_basic/table.cc (+1/-0)
src/wui/buildingwindow.cc (+14/-12)
To merge this branch: bzr merge lp:~nomeata/widelands/help-button-right
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+81404@code.launchpad.net

Description of the change

Move the help button to the right.

This also fixes the crash introduced in UI::Table and enhances UI::Box.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/box.cc'
2--- src/ui_basic/box.cc 2011-11-06 12:20:01 +0000
3+++ src/ui_basic/box.cc 2011-11-06 14:41:25 +0000
4@@ -81,7 +81,9 @@
5 }
6
7 /**
8- * Compute the desired size based on our children.
9+ * Compute the desired size based on our children. This assumes that the
10+ * infinite space is zero, and is later on also re-used to calculate the
11+ * space assigned to an infinite space.
12 */
13 void Box::update_desired_size()
14 {
15@@ -105,7 +107,8 @@
16 maxbreadth += Scrollbar::Size;
17 }
18 set_desired_size
19- (std::min(totaldepth, m_max_x), std::min(maxbreadth, m_max_y));
20+ (std::min(totaldepth, m_max_x), // + get_lborder() + get_rborder(),
21+ std::min(maxbreadth, m_max_y)); // + get_tborder() + get_bborder());
22 } else {
23 if (totaldepth > m_max_y && m_scrolling) {
24 maxbreadth += Scrollbar::Size;
25@@ -188,7 +191,27 @@
26 m_scrollbar = 0;
27 }
28
29- // Second pass: Update positions and sizes of all items
30+ // Second pass: Count number of infinite spaces
31+ uint32_t infspace_count = 0;
32+ for (uint32_t idx = 0; idx < m_items.size(); ++idx)
33+ if (m_items[idx].type == Item::ItemInfSpace)
34+ infspace_count++;
35+
36+ // Third pass: Distribute left over space to all infinite spaces. To
37+ // avoid having some pixels left at the end due to rounding errors, we
38+ // divide the remaining space by the number of remaining infinite
39+ // spaces every time, and not just one.
40+ uint32_t max_depths =
41+ m_orientation == Horizontal ? get_inner_w() : get_inner_h();
42+ for (uint32_t idx = 0; idx < m_items.size(); ++idx)
43+ if (m_items[idx].type == Item::ItemInfSpace) {
44+ m_items[idx].u.assigned_space =
45+ (max_depths - totaldepth) / infspace_count;
46+ totaldepth += m_items[idx].u.assigned_space;
47+ infspace_count--;
48+ }
49+
50+ // Forth pass: Update positions of all other items
51 update_positions();
52 }
53
54@@ -203,7 +226,7 @@
55
56 for (uint32_t idx = 0; idx < m_items.size(); ++idx) {
57 uint32_t depth, breadth;
58- get_item_desired_size(idx, depth, breadth);
59+ get_item_size(idx, depth, breadth);
60
61 if (m_items[idx].type == Item::ItemPanel) {
62 set_item_size
63@@ -261,6 +284,22 @@
64
65
66 /**
67+ * Add some infinite space (to align some buttons to the right)
68+*/
69+void Box::add_inf_space()
70+{
71+ Item it;
72+
73+ it.type = Item::ItemInfSpace;
74+ it.u.assigned_space = 0;
75+
76+ m_items.push_back(it);
77+
78+ update_desired_size();
79+}
80+
81+
82+/**
83 * Retrieve the given item's desired size. depth is the size of the
84 * item along the orientation axis, breadth is the size perpendicular
85 * to the orientation axis.
86@@ -286,12 +325,40 @@
87 breadth = 0;
88 break;
89
90+ case Item::ItemInfSpace:
91+ depth = 0;
92+ breadth = 0;
93+ break;
94+
95 default:
96 throw wexception("Box::get_item_size: bad type %u", it.type);
97 }
98 }
99
100 /**
101+ * Retrieve the given item's size. This differs from get_item_desired_size only
102+ * for InfSpace items, at least for now.
103+ */
104+void Box::get_item_size
105+ (uint32_t const idx, uint32_t & depth, uint32_t & breadth)
106+{
107+ assert(idx < m_items.size());
108+
109+ Item const & it = m_items[idx];
110+
111+ switch (it.type) {
112+ case Item::ItemInfSpace:
113+ depth = it.u.assigned_space;
114+ breadth = 0;
115+ break;
116+
117+ default:
118+ get_item_desired_size(idx, depth, breadth);
119+ }
120+
121+}
122+
123+/**
124 * Set the given items actual size.
125 */
126 void Box::set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth)
127@@ -352,6 +419,8 @@
128 }
129
130 case Item::ItemSpace:; // no need to do anything
131+
132+ case Item::ItemInfSpace:; // no need to do anything
133 };
134 }
135
136
137=== modified file 'src/ui_basic/box.h'
138--- src/ui_basic/box.h 2011-11-06 12:20:01 +0000
139+++ src/ui_basic/box.h 2011-11-06 14:41:25 +0000
140@@ -57,6 +57,7 @@
141
142 void add(Panel * panel, uint32_t align, bool fullsize = false);
143 void add_space(uint32_t space);
144+ void add_inf_space();
145 bool is_snap_target() const {return true;}
146
147 void set_min_desired_breadth(uint32_t min);
148@@ -67,6 +68,7 @@
149
150 private:
151 void get_item_desired_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
152+ void get_item_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
153 void set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth);
154 void set_item_pos(uint32_t idx, int32_t pos);
155 void scrollbar_moved(int32_t);
156@@ -79,7 +81,8 @@
157 struct Item {
158 enum Type {
159 ItemPanel,
160- ItemSpace
161+ ItemSpace,
162+ ItemInfSpace
163 };
164
165 Type type;
166@@ -91,6 +94,7 @@
167 bool fullsize;
168 } panel;
169 uint32_t space;
170+ uint32_t assigned_space;
171 } u;
172 };
173
174
175=== modified file 'src/ui_basic/panel.cc'
176--- src/ui_basic/panel.cc 2011-11-04 22:49:27 +0000
177+++ src/ui_basic/panel.cc 2011-11-06 14:41:25 +0000
178@@ -311,6 +311,11 @@
179 if (_desired_w == w && _desired_h == h)
180 return;
181
182+ assert(w >= 0);
183+ assert(h >= 0);
184+ assert(w < 3000);
185+ assert(h < 3000);
186+
187 _desired_w = w;
188 _desired_h = h;
189 if (!get_layout_toplevel() && _parent) {
190
191=== modified file 'src/ui_basic/table.cc'
192--- src/ui_basic/table.cc 2011-11-05 16:32:47 +0000
193+++ src/ui_basic/table.cc 2011-11-06 14:41:25 +0000
194@@ -58,6 +58,7 @@
195 m_last_click_time (-10000),
196 m_last_selection (no_selection_index()),
197 m_sort_column (0),
198+ m_total_width (0),
199 m_sort_descending (descending)
200 {
201 set_think(false);
202
203=== modified file 'src/wui/buildingwindow.cc'
204--- src/wui/buildingwindow.cc 2011-11-06 13:26:01 +0000
205+++ src/wui/buildingwindow.cc 2011-11-06 14:41:25 +0000
206@@ -67,7 +67,7 @@
207 vbox->add(m_tabs, UI::Box::AlignLeft, true);
208
209 m_capsbuttons = new UI::Box(vbox, 0, 0, UI::Box::Horizontal);
210- vbox->add(m_capsbuttons, UI::Box::AlignLeft);
211+ vbox->add(m_capsbuttons, UI::Box::AlignLeft, true);
212 // actually create buttons on the first call to think(),
213 // so that overriding create_capsbuttons() works
214
215@@ -160,17 +160,6 @@
216 bool const can_see = igbase().can_see(owner_number);
217 bool const can_act = igbase().can_act(owner_number);
218
219- if (m_building.descr().has_help_text())
220- capsbuttons->add
221- (new UI::Callback_Button
222- (capsbuttons, "help",
223- 0, 0, 34, 34,
224- g_gr->get_picture(PicMod_UI, "pics/but4.png"),
225- g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
226- boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
227- _("Help")),
228- UI::Box::AlignCenter);
229-
230 if (can_act) {
231 if (upcast(Widelands::ProductionSite const, productionsite, &m_building))
232 if (not dynamic_cast<Widelands::MilitarySite const *>(productionsite)) {
233@@ -274,6 +263,19 @@
234 g_gr->get_picture(PicMod_Game, "pics/menu_goto.png"),
235 boost::bind(&Building_Window::clicked_goto, boost::ref(*this))),
236 UI::Box::AlignCenter);
237+
238+ if (m_building.descr().has_help_text())
239+ capsbuttons->add_inf_space();
240+ capsbuttons->add
241+ (new UI::Callback_Button
242+ (capsbuttons, "help",
243+ 0, 0, 34, 34,
244+ g_gr->get_picture(PicMod_UI, "pics/but4.png"),
245+ g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
246+ boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
247+ _("Help")),
248+ UI::Box::AlignCenter);
249+
250 }
251 }
252

Subscribers

People subscribed via source and target branches

to status/vote changes: