… | |
… | |
113 | } |
113 | } |
114 | |
114 | |
115 | if ($GRAB) { |
115 | if ($GRAB) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
117 | # mousewheel |
117 | # mousewheel |
118 | $ev->{dx} = 0; |
|
|
119 | $ev->{dy} = $ev->{button} * 2 - 9; |
118 | my $delta = $ev->{button} * 2 - 9; |
|
|
119 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
|
|
120 | |
|
|
121 | $ev->{dx} = $shift ? $delta : 0; |
|
|
122 | $ev->{dy} = $shift ? 0 : $delta; |
|
|
123 | |
120 | $GRAB->emit (mouse_wheel => $ev); |
124 | $GRAB->emit (mouse_wheel => $ev); |
121 | } else { |
125 | } else { |
122 | $GRAB->emit (button_down => $ev) |
126 | $GRAB->emit (button_down => $ev) |
123 | } |
127 | } |
124 | } |
128 | } |
… | |
… | |
642 | my ($self) = @_; |
646 | my ($self) = @_; |
643 | |
647 | |
644 | warn "no draw defined for $self\n"; |
648 | warn "no draw defined for $self\n"; |
645 | } |
649 | } |
646 | |
650 | |
647 | my $cntx;#d# |
|
|
648 | sub DESTROY { |
651 | sub DESTROY { |
649 | my ($self) = @_; |
652 | my ($self) = @_; |
650 | |
653 | |
651 | return if CFPlus::in_destruct; |
654 | return if CFPlus::in_destruct; |
652 | |
655 | |
… | |
… | |
737 | can_events => 0, |
740 | can_events => 0, |
738 | %arg, |
741 | %arg, |
739 | ); |
742 | ); |
740 | |
743 | |
741 | $self->add (@$children) |
744 | $self->add (@$children) |
742 | if $children; |
745 | if $children && @$children; |
743 | |
746 | |
744 | $self |
747 | $self |
745 | } |
748 | } |
746 | |
749 | |
747 | sub realloc { |
750 | sub realloc { |
… | |
… | |
756 | my ($self, @widgets) = @_; |
759 | my ($self, @widgets) = @_; |
757 | |
760 | |
758 | $_->set_parent ($self) |
761 | $_->set_parent ($self) |
759 | for @widgets; |
762 | for @widgets; |
760 | |
763 | |
|
|
764 | # TODO: only do this in widgets that need it, e.g. root, fixed |
761 | use sort 'stable'; |
765 | use sort 'stable'; |
762 | |
766 | |
763 | $self->{children} = [ |
767 | $self->{children} = [ |
764 | sort { $a->{z} <=> $b->{z} } |
768 | sort { $a->{z} <=> $b->{z} } |
765 | @{$self->{children}}, @widgets |
769 | @{$self->{children}}, @widgets |
766 | ]; |
770 | ]; |
767 | |
771 | |
768 | $self->realloc; |
772 | $self->realloc; |
|
|
773 | |
|
|
774 | map $_+0, @widgets |
769 | } |
775 | } |
770 | |
776 | |
771 | sub children { |
777 | sub children { |
772 | @{ $_[0]{children} } |
778 | @{ $_[0]{children} } |
773 | } |
779 | } |
… | |
… | |
784 | } |
790 | } |
785 | |
791 | |
786 | sub clear { |
792 | sub clear { |
787 | my ($self) = @_; |
793 | my ($self) = @_; |
788 | |
794 | |
789 | my $children = delete $self->{children}; |
795 | my $children = $self->{children}; |
790 | $self->{children} = []; |
796 | $self->{children} = []; |
791 | |
797 | |
792 | for (@$children) { |
798 | for (@$children) { |
793 | delete $_->{parent}; |
799 | delete $_->{parent}; |
794 | $_->hide; |
800 | $_->hide; |
… | |
… | |
954 | sub size_request { |
960 | sub size_request { |
955 | my ($self) = @_; |
961 | my ($self) = @_; |
956 | |
962 | |
957 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
963 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
958 | |
964 | |
959 | $w = 10 if $self->{scroll_x}; |
965 | $w = 1 if $self->{scroll_x}; |
960 | $h = 10 if $self->{scroll_y}; |
966 | $h = 1 if $self->{scroll_y}; |
961 | |
967 | |
962 | ($w, $h) |
968 | ($w, $h) |
963 | } |
969 | } |
964 | |
970 | |
965 | sub invoke_size_allocate { |
971 | sub invoke_size_allocate { |
… | |
… | |
1042 | my $child = delete $arg{child}; |
1048 | my $child = delete $arg{child}; |
1043 | |
1049 | |
1044 | my $self; |
1050 | my $self; |
1045 | |
1051 | |
1046 | my $hslider = new CFPlus::UI::Slider |
1052 | my $hslider = new CFPlus::UI::Slider |
|
|
1053 | col => 0, |
|
|
1054 | row => 1, |
1047 | vertical => 0, |
1055 | vertical => 0, |
1048 | range => [0, 0, 1, 0.01], # HACK fix |
1056 | range => [0, 0, 1, 0.01], # HACK fix |
1049 | on_changed => sub { |
1057 | on_changed => sub { |
1050 | $self->{hpos} = $_[1]; |
1058 | $self->{hpos} = $_[1]; |
1051 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1059 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1052 | }, |
1060 | }, |
1053 | ; |
1061 | ; |
1054 | |
1062 | |
1055 | my $vslider = new CFPlus::UI::Slider |
1063 | my $vslider = new CFPlus::UI::Slider |
|
|
1064 | col => 1, |
|
|
1065 | row => 0, |
1056 | vertical => 1, |
1066 | vertical => 1, |
1057 | range => [0, 0, 1, 0.01], # HACK fix |
1067 | range => [0, 0, 1, 0.01], # HACK fix |
1058 | on_changed => sub { |
1068 | on_changed => sub { |
1059 | $self->{vpos} = $_[1]; |
1069 | $self->{vpos} = $_[1]; |
1060 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1070 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1071 | row_expand => [1, 0], |
1081 | row_expand => [1, 0], |
1072 | %arg, |
1082 | %arg, |
1073 | ); |
1083 | ); |
1074 | |
1084 | |
1075 | $self->{vp} = new CFPlus::UI::ViewPort |
1085 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1086 | col => 0, |
|
|
1087 | row => 0, |
1076 | expand => 1, |
1088 | expand => 1, |
1077 | scroll_x => $self->{scroll_x}, |
1089 | scroll_x => $self->{scroll_x}, |
1078 | scroll_y => $self->{scroll_y}, |
1090 | scroll_y => $self->{scroll_y}, |
1079 | on_changed => sub { |
1091 | on_changed => sub { |
1080 | my ($vp, $x, $y) = @_; |
1092 | my ($vp, $x, $y) = @_; |
… | |
… | |
1082 | $vp->{parent}{hslider}->set_value ($x); |
1094 | $vp->{parent}{hslider}->set_value ($x); |
1083 | $vp->{parent}{vslider}->set_value ($y); |
1095 | $vp->{parent}{vslider}->set_value ($y); |
1084 | |
1096 | |
1085 | 0 |
1097 | 0 |
1086 | }, |
1098 | }, |
|
|
1099 | on_size_allocate => sub { |
|
|
1100 | my ($vp, $w, $h) = @_; |
|
|
1101 | $vp->{parent}->update_slider; |
|
|
1102 | 0 |
|
|
1103 | }, |
1087 | ; |
1104 | ; |
1088 | |
1105 | |
1089 | $self->SUPER::add_at (0, 0, $self->{vp}); |
1106 | $self->SUPER::add ($self->{vp}); |
1090 | |
1107 | |
1091 | $self->add ($child) if $child; |
1108 | $self->add ($child) if $child; |
1092 | |
1109 | |
1093 | $self |
1110 | $self |
1094 | } |
1111 | } |
1095 | |
|
|
1096 | #TODO# update range on size_allocate depending on child |
|
|
1097 | |
1112 | |
1098 | sub add { |
1113 | sub add { |
1099 | my ($self, $widget) = @_; |
1114 | my ($self, $widget) = @_; |
1100 | |
1115 | |
1101 | $self->{vp}->add ($self->{child} = $widget); |
1116 | $self->{vp}->add ($self->{child} = $widget); |
… | |
… | |
1104 | sub update_slider { |
1119 | sub update_slider { |
1105 | my ($self) = @_; |
1120 | my ($self) = @_; |
1106 | |
1121 | |
1107 | my $child = ($self->{vp} or return)->child; |
1122 | my $child = ($self->{vp} or return)->child; |
1108 | |
1123 | |
|
|
1124 | if ($self->{scroll_x}) { |
1109 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1125 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1110 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1126 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1111 | |
1127 | |
1112 | my $visible = $w1 > $w2; |
1128 | my $visible = $w1 > $w2; |
1113 | if ($visible != $self->{hslider}{visible}) { |
1129 | if ($visible != $self->{hslider_visible}) { |
|
|
1130 | $self->{hslider_visible} = $visible; |
1114 | $visible ? $self->SUPER::add_at (0, 1, $self->{hslider}) |
1131 | $visible ? $self->SUPER::add ($self->{hslider}) |
1115 | : $self->{hslider}->hide; |
1132 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1133 | } |
1116 | } |
1134 | } |
1117 | |
1135 | |
|
|
1136 | if ($self->{scroll_y}) { |
1118 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1137 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1119 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1138 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1120 | |
1139 | |
1121 | my $visible = $h1 > $h2; |
1140 | my $visible = $h1 > $h2; |
1122 | if ($visible != $self->{vslider}{visible}) { |
1141 | if ($visible != $self->{vslider_visible}) { |
|
|
1142 | $self->{vslider_visible} = $visible; |
1123 | $visible ? $self->SUPER::add_at (1, 0, $self->{vslider}) |
1143 | $visible ? $self->SUPER::add ($self->{vslider}) |
1124 | : $self->{vslider}->hide; |
1144 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1145 | } |
|
|
1146 | } |
|
|
1147 | } |
|
|
1148 | |
|
|
1149 | sub start_dragging { |
|
|
1150 | my ($self, $ev) = @_; |
|
|
1151 | |
|
|
1152 | $self->grab_focus; |
|
|
1153 | |
|
|
1154 | my $ox = $self->{vp}{view_x}; |
|
|
1155 | my $oy = $self->{vp}{view_y}; |
|
|
1156 | |
|
|
1157 | $self->{motion} = sub { |
|
|
1158 | my ($ev, $x, $y) = @_; |
|
|
1159 | |
|
|
1160 | $ox -= $ev->{xrel}; |
|
|
1161 | $oy -= $ev->{yrel}; |
|
|
1162 | |
|
|
1163 | $self->{vp}->set_offset ($ox, $oy); |
1125 | } |
1164 | }; |
1126 | } |
|
|
1127 | |
|
|
1128 | sub update { |
|
|
1129 | my ($self) = @_; |
|
|
1130 | |
|
|
1131 | $self->update_slider; |
|
|
1132 | $self->SUPER::update; |
|
|
1133 | } |
1165 | } |
1134 | |
1166 | |
1135 | sub invoke_mouse_wheel { |
1167 | sub invoke_mouse_wheel { |
1136 | my ($self, $ev) = @_; |
1168 | my ($self, $ev) = @_; |
1137 | |
1169 | |
1138 | return 0 unless $ev->{dy}; # only vertical movements for now |
|
|
1139 | |
|
|
1140 | $self->{vslider}->emit (mouse_wheel => $ev); |
1170 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
|
|
1171 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1141 | |
1172 | |
1142 | 1 |
1173 | 1 |
1143 | } |
1174 | } |
1144 | |
1175 | |
1145 | sub invoke_button_down { |
1176 | sub invoke_button_down { |
1146 | my ($self, $ev, $x, $y) = @_; |
1177 | my ($self, $ev, $x, $y) = @_; |
1147 | |
1178 | |
1148 | if ($ev->{button} == 2) { |
1179 | if ($ev->{button} == 2) { |
1149 | $self->grab_focus; |
1180 | $self->start_dragging ($ev); |
1150 | |
|
|
1151 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
|
|
1152 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1153 | |
|
|
1154 | $self->{motion} = sub { |
|
|
1155 | my ($ev, $x, $y) = @_; |
|
|
1156 | |
|
|
1157 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1158 | $self->update; |
|
|
1159 | }; |
|
|
1160 | |
|
|
1161 | return 1; |
1181 | return 1; |
1162 | } |
1182 | } |
1163 | |
1183 | |
1164 | 0 |
1184 | 0 |
1165 | } |
1185 | } |
… | |
… | |
1575 | |
1595 | |
1576 | ############################################################################# |
1596 | ############################################################################# |
1577 | |
1597 | |
1578 | package CFPlus::UI::Table; |
1598 | package CFPlus::UI::Table; |
1579 | |
1599 | |
1580 | our @ISA = CFPlus::UI::Base::; |
1600 | our @ISA = CFPlus::UI::Container::; |
1581 | |
1601 | |
1582 | use List::Util qw(max sum); |
1602 | use List::Util qw(max sum); |
1583 | |
1603 | |
1584 | use CFPlus::OpenGL; |
1604 | use CFPlus::OpenGL; |
1585 | |
1605 | |
1586 | sub new { |
1606 | sub new { |
1587 | my $class = shift; |
1607 | my $class = shift; |
1588 | |
1608 | |
1589 | $class->SUPER::new ( |
1609 | $class->SUPER::new ( |
1590 | children => [], |
|
|
1591 | col_expand => [], |
1610 | col_expand => [], |
1592 | row_expand => [], |
1611 | row_expand => [], |
1593 | @_, |
1612 | @_, |
1594 | ) |
1613 | ) |
1595 | } |
1614 | } |
1596 | |
1615 | |
1597 | sub children { |
|
|
1598 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1599 | } |
|
|
1600 | |
|
|
1601 | # TODO: store row/col info in child widget and use standard add/del |
|
|
1602 | sub add { |
1616 | sub add { |
1603 | my $self = shift; |
1617 | my ($self, @widgets) = @_; |
1604 | |
1618 | |
1605 | Carp::cluck "please use the add_at method instead of calling add, thank you.\n";#d# |
1619 | for my $child (@widgets) { |
1606 | $self->add_at (@_); |
1620 | $child->{rowspan} ||= 1; |
|
|
1621 | $child->{colspan} ||= 1; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | $self->SUPER::add (@widgets); |
1607 | } |
1625 | } |
1608 | |
1626 | |
1609 | sub add_at { |
1627 | sub add_at { |
1610 | my $self = shift; |
1628 | my $self = shift; |
1611 | |
1629 | |
|
|
1630 | my @widgets; |
|
|
1631 | |
1612 | while (@_) { |
1632 | while (@_) { |
1613 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1633 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1614 | |
1634 | |
1615 | $child->set_parent ($self); |
1635 | $child->{row} = $row; |
1616 | $self->{children}[$row][$col] = $child; |
1636 | $child->{col} = $col; |
1617 | } |
|
|
1618 | |
1637 | |
1619 | $self->{force_realloc} = 1; |
1638 | push @widgets, $child; |
1620 | $self->{force_size_alloc} = 1; |
1639 | } |
1621 | $self->realloc; |
|
|
1622 | } |
|
|
1623 | |
1640 | |
1624 | sub remove { |
1641 | $self->add (@widgets); |
|
|
1642 | } |
|
|
1643 | |
|
|
1644 | sub get_wh { |
1625 | my ($self, $child) = @_; |
1645 | my ($self) = @_; |
1626 | |
1646 | |
1627 | for (@{ $self->{children} }) { |
1647 | my (@w, @h); |
1628 | for (@{ $_ || [] }) { |
1648 | |
1629 | $_ = undef if $_ == $child; |
1649 | my @children = $self->children; |
|
|
1650 | |
|
|
1651 | # first pass, columns |
|
|
1652 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
|
|
1653 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
|
|
1654 | |
|
|
1655 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1656 | |
|
|
1657 | if ($w > $sw) { |
|
|
1658 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1630 | } |
1659 | } |
1631 | } |
1660 | } |
1632 | } |
|
|
1633 | |
1661 | |
1634 | # TODO: move to container class maybe? send children a signal on removal? |
1662 | # second pass, rows |
1635 | sub clear { |
1663 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1636 | my ($self) = @_; |
|
|
1637 | |
|
|
1638 | my @children = $self->children; |
|
|
1639 | delete $self->{children}; |
|
|
1640 | |
|
|
1641 | for (@children) { |
|
|
1642 | delete $_->{parent}; |
|
|
1643 | $_->hide; |
|
|
1644 | } |
|
|
1645 | |
|
|
1646 | $self->realloc; |
|
|
1647 | } |
|
|
1648 | |
|
|
1649 | sub get_wh { |
|
|
1650 | my ($self) = @_; |
|
|
1651 | |
|
|
1652 | my (@w, @h); |
|
|
1653 | |
|
|
1654 | for my $y (0 .. $#{$self->{children}}) { |
|
|
1655 | my $row = $self->{children}[$y] |
|
|
1656 | or next; |
|
|
1657 | |
|
|
1658 | for my $x (0 .. $#$row) { |
|
|
1659 | my $widget = $row->[$x] |
|
|
1660 | or next; |
|
|
1661 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
1664 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1662 | |
1665 | |
1663 | $w[$x] = max $w[$x], $w; |
1666 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1664 | $h[$y] = max $h[$y], $h; |
1667 | |
|
|
1668 | if ($h > $sh) { |
|
|
1669 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1665 | } |
1670 | } |
1666 | } |
1671 | } |
1667 | |
1672 | |
1668 | (\@w, \@h) |
1673 | (\@w, \@h) |
1669 | } |
1674 | } |
… | |
… | |
1685 | my ($ws, $hs) = $self->get_wh; |
1690 | my ($ws, $hs) = $self->get_wh; |
1686 | |
1691 | |
1687 | my $req_w = (sum @$ws) || 1; |
1692 | my $req_w = (sum @$ws) || 1; |
1688 | my $req_h = (sum @$hs) || 1; |
1693 | my $req_h = (sum @$hs) || 1; |
1689 | |
1694 | |
1690 | # TODO: nicer code |
1695 | # now linearly scale the rows/columns to the allocated size |
1691 | my @col_expand = @{$self->{col_expand}}; |
1696 | my @col_expand = @{$self->{col_expand}}; |
1692 | @col_expand = (1) x @$ws unless @col_expand; |
1697 | @col_expand = (1) x @$ws unless @col_expand; |
1693 | my $col_expand = (sum @col_expand) || 1; |
1698 | my $col_expand = (sum @col_expand) || 1; |
1694 | |
1699 | |
1695 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1700 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
… | |
… | |
1702 | |
1707 | |
1703 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1708 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1704 | |
1709 | |
1705 | CFPlus::UI::harmonize $hs; |
1710 | CFPlus::UI::harmonize $hs; |
1706 | |
1711 | |
1707 | my $y; |
1712 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1713 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1708 | |
1714 | |
1709 | for my $r (0 .. $#{$self->{children}}) { |
1715 | for my $widget ($self->children) { |
1710 | my $row = $self->{children}[$r] |
1716 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1711 | or next; |
|
|
1712 | |
1717 | |
1713 | my $x = 0; |
1718 | $widget->configure ( |
1714 | my $row_h = $hs->[$r]; |
1719 | $x[$c], $y[$r], |
|
|
1720 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1715 | |
1721 | ); |
1716 | for my $c (0 .. $#$row) { |
|
|
1717 | my $col_w = $ws->[$c]; |
|
|
1718 | |
|
|
1719 | if (my $widget = $row->[$c]) { |
|
|
1720 | $widget->configure ($x, $y, $col_w, $row_h); |
|
|
1721 | } |
|
|
1722 | |
|
|
1723 | $x += $col_w; |
|
|
1724 | } |
|
|
1725 | |
|
|
1726 | $y += $row_h; |
|
|
1727 | } |
1722 | } |
1728 | |
1723 | |
1729 | 1 |
1724 | 1 |
1730 | } |
1725 | } |
1731 | |
1726 | |
1732 | sub find_widget { |
|
|
1733 | my ($self, $x, $y) = @_; |
|
|
1734 | |
|
|
1735 | $x -= $self->{x}; |
|
|
1736 | $y -= $self->{y}; |
|
|
1737 | |
|
|
1738 | my $res; |
|
|
1739 | |
|
|
1740 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1741 | $res = $_->find_widget ($x, $y) |
|
|
1742 | and return $res; |
|
|
1743 | } |
|
|
1744 | |
|
|
1745 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1746 | } |
|
|
1747 | |
|
|
1748 | sub _draw { |
|
|
1749 | my ($self) = @_; |
|
|
1750 | |
|
|
1751 | for (grep $_, @{$self->{children}}) { |
|
|
1752 | $_->draw for grep $_, @$_; |
|
|
1753 | } |
|
|
1754 | } |
|
|
1755 | |
|
|
1756 | ############################################################################# |
1727 | ############################################################################# |
1757 | |
1728 | |
1758 | package CFPlus::UI::Fixed; |
1729 | package CFPlus::UI::Fixed; |
1759 | |
1730 | |
1760 | use List::Util qw(min max); |
1731 | use List::Util qw(min max); |
1761 | |
1732 | |
1762 | our @ISA = CFPlus::UI::Container::; |
1733 | our @ISA = CFPlus::UI::Container::; |
1763 | |
1734 | |
1764 | sub add { |
1735 | sub add_fixed { |
1765 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1736 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1766 | |
1737 | |
1767 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1738 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1768 | $self->SUPER::add ($child); |
1739 | $self->SUPER::add ($child); |
1769 | } |
1740 | } |
… | |
… | |
4175 | while ($self->{refresh_hook}) { |
4146 | while ($self->{refresh_hook}) { |
4176 | $_->() |
4147 | $_->() |
4177 | for values %{delete $self->{refresh_hook}}; |
4148 | for values %{delete $self->{refresh_hook}}; |
4178 | } |
4149 | } |
4179 | |
4150 | |
4180 | if ($self->{realloc}) { |
4151 | while ($self->{realloc}) { |
4181 | my %queue; |
4152 | my %queue; |
4182 | my @queue; |
4153 | my @queue; |
4183 | my $widget; |
4154 | my $widget; |
4184 | |
4155 | |
4185 | outer: |
4156 | outer: |
… | |
… | |
4232 | } |
4203 | } |
4233 | } |
4204 | } |
4234 | |
4205 | |
4235 | delete $self->{realloc}{$widget+0}; |
4206 | delete $self->{realloc}{$widget+0}; |
4236 | } |
4207 | } |
4237 | } |
|
|
4238 | |
4208 | |
4239 | while (my $size_alloc = delete $self->{size_alloc}) { |
4209 | while (my $size_alloc = delete $self->{size_alloc}) { |
4240 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4210 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4241 | values %$size_alloc; |
4211 | values %$size_alloc; |
4242 | |
4212 | |
4243 | while () { |
4213 | while () { |
4244 | my $widget = pop @queue || last; |
4214 | my $widget = pop @queue || last; |
4245 | |
4215 | |
4246 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4216 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4247 | |
4217 | |
4248 | $w = 0 if $w < 0; |
|
|
4249 | $h = 0 if $h < 0; |
|
|
4250 | |
|
|
4251 | $w = max $widget->{min_w}, $w; |
4218 | $w = max $widget->{min_w}, $w; |
4252 | $h = max $widget->{min_h}, $h; |
4219 | $h = max $widget->{min_h}, $h; |
4253 | |
4220 | |
4254 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4221 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4255 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4222 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4256 | |
4223 | |
4257 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4224 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4258 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4225 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4259 | |
4226 | |
4260 | $w = int $w + 0.5; |
4227 | $w = int $w + 0.5; |
4261 | $h = int $h + 0.5; |
4228 | $h = int $h + 0.5; |
4262 | |
4229 | |
4263 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4230 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4264 | $widget->{old_w} = $widget->{w}; |
4231 | $widget->{old_w} = $widget->{w}; |
4265 | $widget->{old_h} = $widget->{h}; |
4232 | $widget->{old_h} = $widget->{h}; |
4266 | |
4233 | |
4267 | $widget->{w} = $w; |
4234 | $widget->{w} = $w; |
4268 | $widget->{h} = $h; |
4235 | $widget->{h} = $h; |
4269 | |
4236 | |
4270 | $widget->emit (size_allocate => $w, $h); |
4237 | $widget->emit (size_allocate => $w, $h); |
|
|
4238 | } |
4271 | } |
4239 | } |
4272 | } |
4240 | } |
4273 | } |
4241 | } |
4274 | |
4242 | |
4275 | while ($self->{post_alloc_hook}) { |
4243 | while ($self->{post_alloc_hook}) { |