680 static void ResizeToolbar(Window *w) |
680 static void ResizeToolbar(Window *w) |
681 { |
681 { |
682 /* There are 27 buttons plus some spacings if the space allows it */ |
682 /* There are 27 buttons plus some spacings if the space allows it */ |
683 uint button_width; |
683 uint button_width; |
684 uint spacing; |
684 uint spacing; |
685 if (w->width >= 27 * 22) { |
685 if (w->width >= (int)w->widget_count * 22) { |
686 button_width = 22; |
686 button_width = 22; |
687 spacing = w->width - (27 * button_width); |
687 spacing = w->width - (w->widget_count * button_width); |
688 } else { |
688 } else { |
689 button_width = w->width / 27; |
689 button_width = w->width / w->widget_count; |
690 spacing = 0; |
690 spacing = 0; |
691 } |
691 } |
|
692 |
692 uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; |
693 uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; |
693 |
694 uint i = 0; |
694 for (uint i = 0, x = 0, j = 0; i < 27; i++) { |
695 for (uint x = 0, j = 0; i < w->widget_count; i++) { |
695 if (extra_spacing_at[j] == i) { |
696 if (extra_spacing_at[j] == i) { |
696 j++; |
697 j++; |
697 uint add = spacing / (lengthof(extra_spacing_at) - j); |
698 uint add = spacing / (lengthof(extra_spacing_at) - j); |
698 spacing -= add; |
699 spacing -= add; |
699 x += add; |
700 x += add; |
700 } |
701 } |
701 |
702 |
702 w->widget[i].type = WWT_IMGBTN; |
703 w->widget[i].type = WWT_IMGBTN; |
703 w->widget[i].left = x; |
704 w->widget[i].left = x; |
704 x += (spacing != 0) ? button_width : (w->width - x) / (27 - i); |
705 x += (spacing != 0) ? button_width : (w->width - x) / (w->widget_count - i); |
705 w->widget[i].right = x - 1; |
706 w->widget[i].right = x - 1; |
706 } |
707 } |
707 |
708 |
708 w->widget[27].type = WWT_EMPTY; |
709 w->widget[i].type = WWT_EMPTY; // i now points to the last item |
709 _toolbar_mode = TB_NORMAL; |
710 _toolbar_mode = TB_NORMAL; |
710 } |
711 } |
711 |
712 |
712 /* --- Split the toolbar */ |
713 /* --- Split the toolbar */ |
713 |
714 |
744 uint max_icons = max(14U, (w->width + icon_size / 2) / icon_size); |
745 uint max_icons = max(14U, (w->width + icon_size / 2) / icon_size); |
745 |
746 |
746 assert(max_icons >= 14 && max_icons <= 19); |
747 assert(max_icons >= 14 && max_icons <= 19); |
747 |
748 |
748 /* first hide all icons */ |
749 /* first hide all icons */ |
749 for (uint i = 0; i < 27; i++) { |
750 for (uint i = 0; i < w->widget_count; i++) { |
750 w->widget[i].type = WWT_EMPTY; |
751 w->widget[i].type = WWT_EMPTY; |
751 } |
752 } |
752 |
753 |
753 /* now activate them all on their proper positions */ |
754 /* now activate them all on their proper positions */ |
754 for (uint i = 0, x = 0, n = max_icons - 14; i < max_icons; i++) { |
755 for (uint i = 0, x = 0, n = max_icons - 14; i < max_icons; i++) { |