Adjust RELATIVE ::repositionItems (more relative)

The evenly distributed space causes a lot of whitespace and otoh. cut
items, so we use the items internal size as indicator IF the item is a
textbutton (the regular usecase in fluxbox)

Also publish the function to be triggered from outside (because the
caller can, in theory, much better compress several text changes)
This commit is contained in:
Thomas Lübking 2016-08-03 00:24:39 +02:00
parent cc80230bd8
commit 10e3f10b55
2 changed files with 29 additions and 8 deletions

View file

@ -23,12 +23,14 @@
#include "Container.hh"
#include "Button.hh"
#include "TextButton.hh"
#include "TextUtils.hh"
#include "EventManager.hh"
#include "CompareEqual.hh"
#include "STLUtil.hh"
#include <algorithm>
#include <vector>
namespace FbTk {
@ -304,7 +306,7 @@ void Container::repositionItems() {
unsigned int max_width_per_client = maxWidthPerClient();
unsigned int borderW = m_item_list.front()->borderWidth();
size_t num_items = m_item_list.size();
const size_t num_items = m_item_list.size();
unsigned int total_width;
unsigned int cur_width;
@ -364,10 +366,6 @@ void Container::repositionItems() {
int rounding_error = 0;
if (align == RELATIVE || total_width == m_max_total_size) {
rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW);
}
int next_x = -borderW; // zero so the border of the first shows
int extra = 0;
int direction = 1;
@ -378,7 +376,25 @@ void Container::repositionItems() {
int tmpx, tmpy;
unsigned int tmpw, tmph;
for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) {
unsigned int totalDemands = 0;
std::vector<unsigned int> buttonDemands;
if (align == RELATIVE || total_width == m_max_total_size) {
buttonDemands.reserve(num_items);
for (it = begin(); it != it_end; ++it) {
buttonDemands.push_back((*it)->preferredWidth());
totalDemands += buttonDemands.back();
}
if (totalDemands) {
rounding_error = total_width;
for (int i = 0; i < buttonDemands.size(); ++i) {
rounding_error -= buttonDemands.at(i)*total_width/totalDemands;
}
}
}
it = begin();
for (int i = 0; it != it_end; ++it, ++i) {
// we only need to do error stuff with alignment RELATIVE
// OR with max_total_size triggered
if (rounding_error) {
@ -395,8 +411,13 @@ void Container::repositionItems() {
// rotate the x and y coords
tmpx = next_x;
tmpy = -borderW;
tmpw = max_width_per_client + extra;
if (align == RELATIVE && totalDemands) {
tmpw = buttonDemands.at(i)*total_width/totalDemands + extra;
} else {
tmpw = max_width_per_client + extra;
}
tmph = height;
next_x += direction*(tmpw + borderW);
translateCoords(m_orientation, tmpx, tmpy, total_width, height);
translatePosition(m_orientation, tmpx, tmpy, tmpw, tmph, borderW);

View file

@ -98,8 +98,8 @@ public:
void clear(); // clear all windows
private:
void repositionItems();
private:
Orientation m_orientation;