diff options
author | Thomas Lübking <thomas.luebking@gmail.com> | 2016-07-24 14:40:03 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2016-08-26 05:33:44 (GMT) |
commit | 3bde5c8aee16f7f33e3ce7b9058fded916fe2369 (patch) | |
tree | 8c7791003a4c0196c7261db68a07313a9740bf1f /src/Toolbar.cc | |
parent | 10e3f10b55fbd8f3ff6793a3993b8ee55f3192a2 (diff) | |
download | fluxbox-3bde5c8aee16f7f33e3ce7b9058fded916fe2369.zip fluxbox-3bde5c8aee16f7f33e3ce7b9058fded916fe2369.tar.bz2 |
Improve stretching (RELATIVE) toolbar items
The available space is distributed reg. the preferred width
of items (spacers and the iconbar ;-) instead of evenly.
The preferred width of the iconbar is calculated from its buttons.
This allows to align the iconbar using spacers and makes better use of
the available space
Diffstat (limited to 'src/Toolbar.cc')
-rw-r--r-- | src/Toolbar.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc index b607f21..1bd3fb5 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc | |||
@@ -868,6 +868,8 @@ void Toolbar::rearrangeItems() { | |||
868 | ItemList::iterator item_it_end = m_item_list.end(); | 868 | ItemList::iterator item_it_end = m_item_list.end(); |
869 | int bevel_width = theme()->bevelWidth(); | 869 | int bevel_width = theme()->bevelWidth(); |
870 | int fixed_width = bevel_width; // combined size of all fixed items | 870 | int fixed_width = bevel_width; // combined size of all fixed items |
871 | int relative_width = 0; // combined *desired* size of all relative items | ||
872 | int stretch_items = 0; | ||
871 | int relative_items = 0; | 873 | int relative_items = 0; |
872 | int last_bw = 0; // we show the largest border of adjoining items | 874 | int last_bw = 0; // we show the largest border of adjoining items |
873 | bool first = true; | 875 | bool first = true; |
@@ -895,7 +897,7 @@ void Toolbar::rearrangeItems() { | |||
895 | 897 | ||
896 | last_bw = borderW; | 898 | last_bw = borderW; |
897 | 899 | ||
898 | tmpw = (*item_it)->width(); | 900 | tmpw = (*item_it)->preferredWidth(); |
899 | tmph = (*item_it)->height(); | 901 | tmph = (*item_it)->height(); |
900 | FbTk::translateSize(orient, tmpw, tmph); | 902 | FbTk::translateSize(orient, tmpw, tmph); |
901 | 903 | ||
@@ -906,18 +908,22 @@ void Toolbar::rearrangeItems() { | |||
906 | if (bevel_width) | 908 | if (bevel_width) |
907 | fixed_width -= 2*(borderW + bevel_width); | 909 | fixed_width -= 2*(borderW + bevel_width); |
908 | } else { | 910 | } else { |
909 | relative_items++; | 911 | ++relative_items; |
912 | relative_width += tmpw; | ||
913 | if (!tmpw) | ||
914 | ++stretch_items; | ||
910 | } | 915 | } |
911 | } | 916 | } |
912 | 917 | ||
913 | // calculate what's going to be left over to the relative sized items | 918 | // calculate what's going to be left over to the relative sized items |
914 | int relative_width = 0; | 919 | float stretch_factor = 1.0f; |
915 | int rounding_error = 0; | 920 | if (relative_items) { |
916 | if (relative_items == 0) | 921 | if (relative_width <= width - fixed_width && stretch_items) { |
917 | relative_width = 0; | 922 | relative_width = int(width - fixed_width - relative_width)/stretch_items; |
918 | else { // size left after fixed items / number of relative items | 923 | } else { |
919 | relative_width = (width - fixed_width) / relative_items; | 924 | stretch_factor = float(width - fixed_width)/relative_width; |
920 | rounding_error = width - fixed_width - relative_items * relative_width; | 925 | relative_width = 0; |
926 | } | ||
921 | } | 927 | } |
922 | 928 | ||
923 | // now move and resize the items | 929 | // now move and resize the items |
@@ -952,12 +958,9 @@ void Toolbar::rearrangeItems() { | |||
952 | tmpy = offset; | 958 | tmpy = offset; |
953 | 959 | ||
954 | if ((*item_it)->type() == ToolbarItem::RELATIVE) { | 960 | if ((*item_it)->type() == ToolbarItem::RELATIVE) { |
955 | int extra = 0; | 961 | unsigned int itemw = (*item_it)->preferredWidth(), itemh = (*item_it)->height(); |
956 | if (rounding_error != 0) { // distribute rounding error over all relatives | 962 | FbTk::translateSize(orient, itemw, itemh); |
957 | extra = 1; | 963 | tmpw = itemw ? std::floor(stretch_factor * itemw) : relative_width; |
958 | --rounding_error; | ||
959 | } | ||
960 | tmpw = extra + relative_width; | ||
961 | tmph = height - size_offset; | 964 | tmph = height - size_offset; |
962 | } else if ((*item_it)->type() == ToolbarItem::SQUARE) { | 965 | } else if ((*item_it)->type() == ToolbarItem::SQUARE) { |
963 | tmpw = tmph = height - size_offset; | 966 | tmpw = tmph = height - size_offset; |