… | |
… | |
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 | |
|
|
14 | our $LAYOUT; |
13 | our $ROOT; |
15 | our $ROOT; |
14 | our $TOOLTIP; |
16 | our $TOOLTIP; |
15 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
16 | |
18 | |
17 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
|
|
20 | |
|
|
21 | sub get_layout { |
|
|
22 | for (grep { $_->{name} } values %WIDGET) { |
|
|
23 | $LAYOUT->{$_->{name}} = { |
|
|
24 | x => $_->{x} / $::WIDTH, |
|
|
25 | y => $_->{y} / $::HEIGHT, |
|
|
26 | w => $_->{w} / $::WIDTH, |
|
|
27 | h => $_->{h} / $::HEIGHT |
|
|
28 | }; |
|
|
29 | } |
|
|
30 | |
|
|
31 | return $LAYOUT; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub set_layout { |
|
|
35 | my ($layout) = @_; |
|
|
36 | $LAYOUT = $layout; |
|
|
37 | } |
18 | |
38 | |
19 | sub check_tooltip { |
39 | sub check_tooltip { |
20 | if (!$GRAB) { |
40 | if (!$GRAB) { |
21 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
22 | if (length $widget->{tooltip}) { |
42 | if (length $widget->{tooltip}) { |
… | |
… | |
193 | } |
213 | } |
194 | } |
214 | } |
195 | |
215 | |
196 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
197 | |
217 | |
|
|
218 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
|
|
219 | $self->{user_x} = $layout->{x} * $::WIDTH; |
|
|
220 | $self->{user_y} = $layout->{y} * $::HEIGHT; |
|
|
221 | $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
|
|
222 | $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
|
|
223 | } |
|
|
224 | |
198 | $self |
225 | $self |
199 | } |
226 | } |
200 | |
227 | |
201 | sub destroy { |
228 | sub destroy { |
202 | my ($self) = @_; |
229 | my ($self) = @_; |
… | |
… | |
228 | sub set_invisible { |
255 | sub set_invisible { |
229 | my ($self) = @_; |
256 | my ($self) = @_; |
230 | |
257 | |
231 | # broken show/hide model |
258 | # broken show/hide model |
232 | |
259 | |
|
|
260 | delete $self->{root}; |
233 | delete $self->{visible}; |
261 | delete $self->{visible}; |
234 | |
262 | |
235 | undef $GRAB if $GRAB == $self; |
263 | undef $GRAB if $GRAB == $self; |
236 | undef $HOVER if $HOVER == $self; |
264 | undef $HOVER if $HOVER == $self; |
237 | |
265 | |
… | |
… | |
459 | my ($self, $parent) = @_; |
487 | my ($self, $parent) = @_; |
460 | |
488 | |
461 | Scalar::Util::weaken ($self->{parent} = $parent); |
489 | Scalar::Util::weaken ($self->{parent} = $parent); |
462 | |
490 | |
463 | $self->{root} = $parent->{root}; |
491 | $self->{root} = $parent->{root}; |
464 | $self->{visible} = $parent->{visible}; |
492 | $self->{visible} = $parent->{visible} + 1; |
465 | |
493 | |
466 | # TODO: req_w _does_change after ->reconfigure |
494 | # TODO: req_w _does_change after ->reconfigure |
467 | $self->check_size |
495 | $self->check_size |
468 | unless exists $self->{req_w}; |
496 | unless exists $self->{req_w}; |
469 | |
497 | |
… | |
… | |
874 | $self->{vp}->add ($self->{scrolled}); |
902 | $self->{vp}->add ($self->{scrolled}); |
875 | $self->add ($self->{vp}); |
903 | $self->add ($self->{vp}); |
876 | $self->add ($self->{slider}); |
904 | $self->add ($self->{slider}); |
877 | |
905 | |
878 | $self |
906 | $self |
|
|
907 | } |
|
|
908 | |
|
|
909 | sub update { |
|
|
910 | my ($self) = @_; |
|
|
911 | |
|
|
912 | $self->SUPER::update; |
|
|
913 | |
|
|
914 | # todo: overwrite size_allocate of child |
|
|
915 | my $child = $self->{vp}->child; |
|
|
916 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
879 | } |
917 | } |
880 | |
918 | |
881 | sub size_allocate { |
919 | sub size_allocate { |
882 | my ($self, $w, $h) = @_; |
920 | my ($self, $w, $h) = @_; |
883 | |
921 | |
… | |
… | |
1171 | sub size_allocate { |
1209 | sub size_allocate { |
1172 | my ($self, $w, $h) = @_; |
1210 | my ($self, $w, $h) = @_; |
1173 | |
1211 | |
1174 | my ($ws, $hs) = $self->get_wh; |
1212 | my ($ws, $hs) = $self->get_wh; |
1175 | |
1213 | |
1176 | my $req_w = sum @$ws; |
1214 | my $req_w = (sum @$ws) || 1; |
1177 | my $req_h = sum @$hs; |
1215 | my $req_h = (sum @$hs) || 1; |
1178 | |
1216 | |
1179 | # TODO: nicer code && do row_expand |
1217 | # TODO: nicer code && do row_expand |
1180 | my @col_expand = @{$self->{col_expand}}; |
1218 | my @col_expand = @{$self->{col_expand}}; |
1181 | @col_expand = (1) x @$ws unless @col_expand; |
1219 | @col_expand = (1) x @$ws unless @col_expand; |
1182 | my $col_expand = (sum @col_expand) || 1; |
1220 | my $col_expand = (sum @col_expand) || 1; |
… | |
… | |
2136 | } |
2174 | } |
2137 | |
2175 | |
2138 | sub set_range { |
2176 | sub set_range { |
2139 | my ($self, $range) = @_; |
2177 | my ($self, $range) = @_; |
2140 | |
2178 | |
2141 | $self->{range} = $range; |
2179 | ($range, $self->{range}) = ($self->{range}, $range); |
2142 | |
2180 | |
2143 | $self->update; |
2181 | $self->update |
|
|
2182 | if "@$range" ne "@{$self->{range}}"; |
2144 | } |
2183 | } |
2145 | |
2184 | |
2146 | sub set_value { |
2185 | sub set_value { |
2147 | my ($self, $value) = @_; |
2186 | my ($self, $value) = @_; |
2148 | |
2187 | |
… | |
… | |
2751 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2790 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2752 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2791 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2753 | |
2792 | |
2754 | $row++; |
2793 | $row++; |
2755 | } |
2794 | } |
2756 | |
|
|
2757 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2758 | } |
2795 | } |
2759 | |
2796 | |
2760 | sub size_request { |
2797 | sub size_request { |
2761 | my ($self) = @_; |
2798 | my ($self) = @_; |
2762 | ($self->{req_w}, $self->{req_h}); |
2799 | ($self->{req_w}, $self->{req_h}); |
… | |
… | |
2954 | |
2991 | |
2955 | sub new { |
2992 | sub new { |
2956 | my $class = shift; |
2993 | my $class = shift; |
2957 | |
2994 | |
2958 | $class->SUPER::new ( |
2995 | $class->SUPER::new ( |
|
|
2996 | visible => 1, |
2959 | @_, |
2997 | @_, |
2960 | ) |
2998 | ) |
2961 | } |
2999 | } |
2962 | |
3000 | |
2963 | sub configure { |
3001 | sub configure { |
… | |
… | |
3021 | sub add { |
3059 | sub add { |
3022 | my ($self, @children) = @_; |
3060 | my ($self, @children) = @_; |
3023 | |
3061 | |
3024 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3062 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3025 | push @widgets, $w->children; |
3063 | push @widgets, $w->children; |
3026 | $w->{root} = $self; |
3064 | $w->{root} = $self; |
3027 | $w->{visible} = 1; |
3065 | $w->{visible} = $self->{visible} + 1; |
3028 | } |
3066 | } |
3029 | |
3067 | |
3030 | for my $child (@children) { |
3068 | for my $child (@children) { |
3031 | $child->{is_toplevel} = 1; |
3069 | $child->{is_toplevel} = 1; |
3032 | |
3070 | |