697 |
697 |
698 WP(w2,dropdown_d).click_delay = 0; |
698 WP(w2,dropdown_d).click_delay = 0; |
699 WP(w2,dropdown_d).drag_mode = true; |
699 WP(w2,dropdown_d).drag_mode = true; |
700 } |
700 } |
701 |
701 |
702 /* Make the buttons in the bottom equal in size */ |
702 |
703 void ResizeButtons(Window *w, byte a, byte b, byte c, byte d, byte right) |
703 static void ResizeWidgets(Window *w, byte a, byte b) |
704 { |
704 { |
705 w->widget[d].right = w->widget[right].left - 1; // now we set the right of the widgets |
705 int16 offset = w->widget[a].left; |
706 |
706 int16 length = w->widget[b].right - offset; |
707 /* Now we will find the middle, then the middle of each of the two blocks on each side of the middle. |
707 |
708 * This way, if we got leftover pixels from the division, they will be somewhat evenly distributed */ |
708 w->widget[a].right = (length / 2) + offset; |
709 w->widget[b].right = w->widget[d].right / 2; |
709 |
710 w->widget[a].right = w->widget[b].right / 2; |
710 w->widget[b].left = w->widget[a].right + 1; |
711 w->widget[c].right = (w->widget[b].right + w->widget[d].right)/2; |
711 } |
|
712 |
|
713 static void ResizeWidgets(Window *w, byte a, byte b, byte c) |
|
714 { |
|
715 int16 offset = w->widget[a].left; |
|
716 int16 length = w->widget[c].right - offset; |
|
717 |
|
718 w->widget[a].right = length / 3; |
|
719 w->widget[b].right = w->widget[a].right * 2; |
|
720 |
|
721 w->widget[a].right += offset; |
|
722 w->widget[b].right += offset; |
|
723 |
712 /* Now the right side of the buttons are set. We will now set the left sides next to them */ |
724 /* Now the right side of the buttons are set. We will now set the left sides next to them */ |
713 w->widget[b].left = w->widget[a].right + 1; |
725 w->widget[b].left = w->widget[a].right + 1; |
714 w->widget[c].left = w->widget[b].right + 1; |
726 w->widget[c].left = w->widget[b].right + 1; |
715 w->widget[d].left = w->widget[c].right + 1; |
727 } |
716 } |
728 |
717 |
729 /** Evenly distribute some widgets when resizing horizontally (often a button row) |
718 void ResizeButtons(Window *w, byte a, byte b, byte c, byte right) |
730 * When only two arguments are given, the widgets are presumed to be on a line and only the ends are given |
719 { |
731 * @param w widow to modify |
720 w->widget[c].right = w->widget[right].left - 1; // now we set the right of the widgets |
732 * @param left The leftmost widget to resize |
721 |
733 * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT |
722 w->widget[a].right = w->widget[c].right / 3; |
734 */ |
723 w->widget[b].right = w->widget[a].right * 2; |
|
724 |
|
725 /* Now the right side of the buttons are set. We will now set the left sides next to them */ |
|
726 w->widget[b].left = w->widget[a].right + 1; |
|
727 w->widget[c].left = w->widget[b].right + 1; |
|
728 } |
|
729 |
|
730 void ResizeButtons(Window *w, byte a, byte b, byte right) |
|
731 { |
|
732 w->widget[b].right = w->widget[right].left - 1; // now we set the right of the widgets |
|
733 |
|
734 w->widget[a].right = w->widget[b].right / 2; |
|
735 |
|
736 w->widget[b].left = w->widget[a].right + 1; |
|
737 } |
|
738 |
|
739 void ResizeButtons(Window *w, byte left, byte right) |
735 void ResizeButtons(Window *w, byte left, byte right) |
740 { |
736 { |
741 switch (right - left) { |
737 int16 num_widgets = right - left + 1; |
742 case 2: ResizeButtons(w, left, left + 1, left + 2); break; |
738 |
743 case 3: ResizeButtons(w, left, left + 1, left + 2, left + 3); break; |
739 if (num_widgets < 2) NOT_REACHED(); |
744 case 4: ResizeButtons(w, left, left + 1, left + 2, left + 3, left + 4); break; |
740 |
745 default: NOT_REACHED(); |
741 switch (num_widgets) { |
746 } |
742 case 2: ResizeWidgets(w, left, right); break; |
747 } |
743 case 3: ResizeWidgets(w, left, left + 1, right); break; |
|
744 default: { |
|
745 /* Looks like we got more than 3 widgets to resize |
|
746 * Now we will find the middle of the space desinated for the widgets |
|
747 * and place half of the widgets on each side of it and call recursively. |
|
748 * Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */ |
|
749 int16 offset = w->widget[left].left; |
|
750 int16 length = w->widget[right].right - offset; |
|
751 byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side |
|
752 |
|
753 /* Now we need to find the middle of the widgets. |
|
754 * It will not always be the middle because if we got an uneven number of widgets, |
|
755 * we will need it to be 2/5, 3/7 and so on |
|
756 * To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get: |
|
757 * |
|
758 * num_widgets/2 (rounding down) |
|
759 * --------------- |
|
760 * num_widgets |
|
761 * |
|
762 * as multiplier to length. We just multiply before divide to that we stay in the int area though */ |
|
763 int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
|
764 |
|
765 /* Set left and right on the widgets, that's next to our "middle" */ |
|
766 w->widget[widget].right = middle; |
|
767 w->widget[widget + 1].left = w->widget[widget].right + 1; |
|
768 /* Now resize the left and right of the middle */ |
|
769 ResizeButtons(w, left, widget); |
|
770 ResizeButtons(w, widget + 1, right); |
|
771 } |
|
772 } |
|
773 } |