… | |
… | |
5 | |
5 | |
6 | use Scalar::Util (); |
6 | use Scalar::Util (); |
7 | use List::Util (); |
7 | use List::Util (); |
8 | |
8 | |
9 | use CFClient; |
9 | use CFClient; |
|
|
10 | use CFClient::Texture; |
10 | |
11 | |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | |
13 | |
13 | our $ROOT; |
14 | our $ROOT; |
14 | our $TOOLTIP; |
15 | our $TOOLTIP; |
… | |
… | |
228 | sub set_invisible { |
229 | sub set_invisible { |
229 | my ($self) = @_; |
230 | my ($self) = @_; |
230 | |
231 | |
231 | # broken show/hide model |
232 | # broken show/hide model |
232 | |
233 | |
|
|
234 | delete $self->{root}; |
233 | delete $self->{visible}; |
235 | delete $self->{visible}; |
234 | |
236 | |
235 | undef $GRAB if $GRAB == $self; |
237 | undef $GRAB if $GRAB == $self; |
236 | undef $HOVER if $HOVER == $self; |
238 | undef $HOVER if $HOVER == $self; |
237 | |
239 | |
… | |
… | |
458 | sub set_parent { |
460 | sub set_parent { |
459 | my ($self, $parent) = @_; |
461 | my ($self, $parent) = @_; |
460 | |
462 | |
461 | Scalar::Util::weaken ($self->{parent} = $parent); |
463 | Scalar::Util::weaken ($self->{parent} = $parent); |
462 | |
464 | |
|
|
465 | $self->{root} = $parent->{root}; |
|
|
466 | $self->{visible} = $parent->{visible} + 1; |
|
|
467 | |
463 | # TODO: req_w _does_change after ->reconfigure |
468 | # TODO: req_w _does_change after ->reconfigure |
464 | $self->check_size |
469 | $self->check_size |
465 | unless exists $self->{req_w}; |
470 | unless exists $self->{req_w}; |
466 | |
471 | |
467 | $self->show; |
472 | $self->show; |
… | |
… | |
618 | delete $child->{parent}; |
623 | delete $child->{parent}; |
619 | $child->hide; |
624 | $child->hide; |
620 | |
625 | |
621 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
626 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
622 | |
627 | |
623 | $self->check_size; |
628 | $self->check_size (1); |
624 | $self->update; |
629 | $self->update; |
625 | } |
630 | } |
626 | |
631 | |
627 | sub clear { |
632 | sub clear { |
628 | my ($self) = @_; |
633 | my ($self) = @_; |
… | |
… | |
871 | $self->{vp}->add ($self->{scrolled}); |
876 | $self->{vp}->add ($self->{scrolled}); |
872 | $self->add ($self->{vp}); |
877 | $self->add ($self->{vp}); |
873 | $self->add ($self->{slider}); |
878 | $self->add ($self->{slider}); |
874 | |
879 | |
875 | $self |
880 | $self |
|
|
881 | } |
|
|
882 | |
|
|
883 | sub update { |
|
|
884 | my ($self) = @_; |
|
|
885 | |
|
|
886 | $self->SUPER::update; |
|
|
887 | |
|
|
888 | # todo: overwrite size_allocate of child |
|
|
889 | my $child = $self->{vp}->child; |
|
|
890 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
876 | } |
891 | } |
877 | |
892 | |
878 | sub size_allocate { |
893 | sub size_allocate { |
879 | my ($self, $w, $h) = @_; |
894 | my ($self, $w, $h) = @_; |
880 | |
895 | |
… | |
… | |
1101 | col_expand => [], |
1116 | col_expand => [], |
1102 | @_, |
1117 | @_, |
1103 | ) |
1118 | ) |
1104 | } |
1119 | } |
1105 | |
1120 | |
|
|
1121 | sub children { |
|
|
1122 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1123 | } |
|
|
1124 | |
1106 | sub add { |
1125 | sub add { |
1107 | my ($self, $x, $y, $child) = @_; |
1126 | my ($self, $x, $y, $child) = @_; |
1108 | |
1127 | |
1109 | $child->set_parent ($self); |
1128 | $child->set_parent ($self); |
1110 | $self->{children}[$y][$x] = $child; |
1129 | $self->{children}[$y][$x] = $child; |
1111 | |
1130 | |
1112 | $child->check_size; |
1131 | $self->check_size (1); |
1113 | } |
1132 | } |
1114 | |
1133 | |
1115 | sub children { |
|
|
1116 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | # TODO: move to container class maybe? send childs a signal on removal? |
1134 | # TODO: move to container class maybe? send children a signal on removal? |
1120 | sub clear { |
1135 | sub clear { |
1121 | my ($self) = @_; |
1136 | my ($self) = @_; |
1122 | |
1137 | |
1123 | my @children = $self->children; |
1138 | my @children = $self->children; |
1124 | delete $self->{children}; |
1139 | delete $self->{children}; |
… | |
… | |
1126 | for (@children) { |
1141 | for (@children) { |
1127 | delete $_->{parent}; |
1142 | delete $_->{parent}; |
1128 | $_->hide; |
1143 | $_->hide; |
1129 | } |
1144 | } |
1130 | |
1145 | |
|
|
1146 | $self->check_size (1); |
1131 | $self->update; |
1147 | $self->update; |
1132 | } |
1148 | } |
1133 | |
1149 | |
1134 | sub get_wh { |
1150 | sub get_wh { |
1135 | my ($self) = @_; |
1151 | my ($self) = @_; |
… | |
… | |
1167 | sub size_allocate { |
1183 | sub size_allocate { |
1168 | my ($self, $w, $h) = @_; |
1184 | my ($self, $w, $h) = @_; |
1169 | |
1185 | |
1170 | my ($ws, $hs) = $self->get_wh; |
1186 | my ($ws, $hs) = $self->get_wh; |
1171 | |
1187 | |
1172 | my $req_w = sum @$ws; |
1188 | my $req_w = (sum @$ws) || 1; |
1173 | my $req_h = sum @$hs; |
1189 | my $req_h = (sum @$hs) || 1; |
1174 | |
1190 | |
1175 | # TODO: nicer code && do row_expand |
1191 | # TODO: nicer code && do row_expand |
1176 | my @col_expand = @{$self->{col_expand}}; |
1192 | my @col_expand = @{$self->{col_expand}}; |
1177 | @col_expand = (1) x @$ws unless @col_expand; |
1193 | @col_expand = (1) x @$ws unless @col_expand; |
1178 | my $col_expand = (sum @col_expand) || 1; |
1194 | my $col_expand = (sum @col_expand) || 1; |
… | |
… | |
2132 | } |
2148 | } |
2133 | |
2149 | |
2134 | sub set_range { |
2150 | sub set_range { |
2135 | my ($self, $range) = @_; |
2151 | my ($self, $range) = @_; |
2136 | |
2152 | |
2137 | $self->{range} = $range; |
2153 | ($range, $self->{range}) = ($self->{range}, $range); |
2138 | |
2154 | |
2139 | $self->update; |
2155 | $self->update |
|
|
2156 | if "@$range" ne "@{$self->{range}}"; |
2140 | } |
2157 | } |
2141 | |
2158 | |
2142 | sub set_value { |
2159 | sub set_value { |
2143 | my ($self, $value) = @_; |
2160 | my ($self, $value) = @_; |
2144 | |
2161 | |
… | |
… | |
2747 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2764 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2748 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2765 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2749 | |
2766 | |
2750 | $row++; |
2767 | $row++; |
2751 | } |
2768 | } |
2752 | |
|
|
2753 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2754 | } |
2769 | } |
2755 | |
2770 | |
2756 | sub size_request { |
2771 | sub size_request { |
2757 | my ($self) = @_; |
2772 | my ($self) = @_; |
2758 | ($self->{req_w}, $self->{req_h}); |
2773 | ($self->{req_w}, $self->{req_h}); |
… | |
… | |
2950 | |
2965 | |
2951 | sub new { |
2966 | sub new { |
2952 | my $class = shift; |
2967 | my $class = shift; |
2953 | |
2968 | |
2954 | $class->SUPER::new ( |
2969 | $class->SUPER::new ( |
|
|
2970 | visible => 1, |
2955 | @_, |
2971 | @_, |
2956 | ) |
2972 | ) |
2957 | } |
2973 | } |
2958 | |
2974 | |
2959 | sub configure { |
2975 | sub configure { |
… | |
… | |
3017 | sub add { |
3033 | sub add { |
3018 | my ($self, @children) = @_; |
3034 | my ($self, @children) = @_; |
3019 | |
3035 | |
3020 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3036 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3021 | push @widgets, $w->children; |
3037 | push @widgets, $w->children; |
3022 | $w->{root} = $self; |
3038 | $w->{root} = $self; |
3023 | $w->{visible} = 1; |
3039 | $w->{visible} = $self->{visible} + 1; |
3024 | } |
3040 | } |
3025 | |
3041 | |
3026 | for my $child (@children) { |
3042 | for my $child (@children) { |
3027 | $child->{is_toplevel} = 1; |
3043 | $child->{is_toplevel} = 1; |
3028 | |
3044 | |