aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Container.cc35
-rw-r--r--src/FbTk/Container.hh2
2 files changed, 29 insertions, 8 deletions
diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc
index d8a230e..f7d5c35 100644
--- a/src/FbTk/Container.cc
+++ b/src/FbTk/Container.cc
@@ -23,12 +23,14 @@
23#include "Container.hh" 23#include "Container.hh"
24 24
25#include "Button.hh" 25#include "Button.hh"
26#include "TextButton.hh"
26#include "TextUtils.hh" 27#include "TextUtils.hh"
27#include "EventManager.hh" 28#include "EventManager.hh"
28#include "CompareEqual.hh" 29#include "CompareEqual.hh"
29#include "STLUtil.hh" 30#include "STLUtil.hh"
30 31
31#include <algorithm> 32#include <algorithm>
33#include <vector>
32 34
33namespace FbTk { 35namespace FbTk {
34 36
@@ -304,7 +306,7 @@ void Container::repositionItems() {
304 306
305 unsigned int max_width_per_client = maxWidthPerClient(); 307 unsigned int max_width_per_client = maxWidthPerClient();
306 unsigned int borderW = m_item_list.front()->borderWidth(); 308 unsigned int borderW = m_item_list.front()->borderWidth();
307 size_t num_items = m_item_list.size(); 309 const size_t num_items = m_item_list.size();
308 310
309 unsigned int total_width; 311 unsigned int total_width;
310 unsigned int cur_width; 312 unsigned int cur_width;
@@ -364,10 +366,6 @@ void Container::repositionItems() {
364 366
365 int rounding_error = 0; 367 int rounding_error = 0;
366 368
367 if (align == RELATIVE || total_width == m_max_total_size) {
368 rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW);
369 }
370
371 int next_x = -borderW; // zero so the border of the first shows 369 int next_x = -borderW; // zero so the border of the first shows
372 int extra = 0; 370 int extra = 0;
373 int direction = 1; 371 int direction = 1;
@@ -378,7 +376,25 @@ void Container::repositionItems() {
378 376
379 int tmpx, tmpy; 377 int tmpx, tmpy;
380 unsigned int tmpw, tmph; 378 unsigned int tmpw, tmph;
381 for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) { 379 unsigned int totalDemands = 0;
380 std::vector<unsigned int> buttonDemands;
381
382 if (align == RELATIVE || total_width == m_max_total_size) {
383 buttonDemands.reserve(num_items);
384 for (it = begin(); it != it_end; ++it) {
385 buttonDemands.push_back((*it)->preferredWidth());
386 totalDemands += buttonDemands.back();
387 }
388 if (totalDemands) {
389 rounding_error = total_width;
390 for (int i = 0; i < buttonDemands.size(); ++i) {
391 rounding_error -= buttonDemands.at(i)*total_width/totalDemands;
392 }
393 }
394 }
395
396 it = begin();
397 for (int i = 0; it != it_end; ++it, ++i) {
382 // we only need to do error stuff with alignment RELATIVE 398 // we only need to do error stuff with alignment RELATIVE
383 // OR with max_total_size triggered 399 // OR with max_total_size triggered
384 if (rounding_error) { 400 if (rounding_error) {
@@ -395,8 +411,13 @@ void Container::repositionItems() {
395 // rotate the x and y coords 411 // rotate the x and y coords
396 tmpx = next_x; 412 tmpx = next_x;
397 tmpy = -borderW; 413 tmpy = -borderW;
398 tmpw = max_width_per_client + extra; 414 if (align == RELATIVE && totalDemands) {
415 tmpw = buttonDemands.at(i)*total_width/totalDemands + extra;
416 } else {
417 tmpw = max_width_per_client + extra;
418 }
399 tmph = height; 419 tmph = height;
420 next_x += direction*(tmpw + borderW);
400 421
401 translateCoords(m_orientation, tmpx, tmpy, total_width, height); 422 translateCoords(m_orientation, tmpx, tmpy, total_width, height);
402 translatePosition(m_orientation, tmpx, tmpy, tmpw, tmph, borderW); 423 translatePosition(m_orientation, tmpx, tmpy, tmpw, tmph, borderW);
diff --git a/src/FbTk/Container.hh b/src/FbTk/Container.hh
index f3d9bac..0f8ac08 100644
--- a/src/FbTk/Container.hh
+++ b/src/FbTk/Container.hh
@@ -98,8 +98,8 @@ public:
98 98
99 void clear(); // clear all windows 99 void clear(); // clear all windows
100 100
101private:
102 void repositionItems(); 101 void repositionItems();
102private:
103 103
104 Orientation m_orientation; 104 Orientation m_orientation;
105 105