aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lübking <thomas.luebking@gmail.com>2016-10-01 21:00:34 (GMT)
committerThomas Lübking <thomas.luebking@gmail.com>2016-10-02 13:53:24 (GMT)
commita375fdb1832db072008fab5e8e6d2c56372f31ad (patch)
treeee24bbe1d96aff6433ae3613803617069090d66d
parent93a91904e631c0ae95242c6de95bf8a1b3d90c20 (diff)
downloadfluxbox-a375fdb1832db072008fab5e8e6d2c56372f31ad.zip
fluxbox-a375fdb1832db072008fab5e8e6d2c56372f31ad.tar.bz2
attempt a more fair container item squeezing
Ein Schrumpffreibetrag, faktisch schon Kommunismus ;-) When short on space, items would be squeezed evenly, but this can turn "a" and "a very long item with useless information text" into "a very long item" and "", so in a pre-pass we check whether some very large items cause the shortage and preferably squeeze them.
-rw-r--r--src/FbTk/Container.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc
index f7d5c35..0ddc421 100644
--- a/src/FbTk/Container.cc
+++ b/src/FbTk/Container.cc
@@ -386,6 +386,35 @@ void Container::repositionItems() {
386 totalDemands += buttonDemands.back(); 386 totalDemands += buttonDemands.back();
387 } 387 }
388 if (totalDemands) { 388 if (totalDemands) {
389 int overhead = totalDemands - total_width;
390 if (overhead > int(buttonDemands.size())) {
391 // try to be fair. If we're short on space and some items
392 // take > 150% of the average, we preferably shrink them, so
393 // "a" and "a very long item with useless information" won't
394 // become "a very long item with" and ""
395 overhead += buttonDemands.size(); // compensate forrounding errors
396 const int mean = totalDemands / buttonDemands.size();
397 const int thresh = 3 * mean / 2;
398 int greed = 0;
399 for (int i = 0; i < buttonDemands.size(); ++i) {
400 if (buttonDemands.at(i) > thresh)
401 greed += buttonDemands.at(i);
402 }
403 if (greed) {
404 for (int i = 0; i < buttonDemands.size(); ++i) {
405 if (buttonDemands.at(i) > thresh) {
406 int d = buttonDemands.at(i)*overhead/greed;
407 if (buttonDemands.at(i) - d > mean) {
408 buttonDemands.at(i) -= d;
409 } else { // do not shrink below mean or a huge item number would super-punish larger ones
410 d = buttonDemands.at(i) - mean;
411 buttonDemands.at(i) = mean;
412 }
413 totalDemands -= d;
414 }
415 }
416 }
417 }
389 rounding_error = total_width; 418 rounding_error = total_width;
390 for (int i = 0; i < buttonDemands.size(); ++i) { 419 for (int i = 0; i < buttonDemands.size(); ++i) {
391 rounding_error -= buttonDemands.at(i)*total_width/totalDemands; 420 rounding_error -= buttonDemands.at(i)*total_width/totalDemands;