… | |
… | |
240 | %$self = (); |
240 | %$self = (); |
241 | } |
241 | } |
242 | |
242 | |
243 | sub show { |
243 | sub show { |
244 | my ($self) = @_; |
244 | my ($self) = @_; |
|
|
245 | |
245 | return if $self->{parent}; |
246 | return if $self->{parent}; |
246 | |
247 | |
247 | $CFClient::UI::ROOT->add ($self); |
248 | $CFClient::UI::ROOT->add ($self); |
248 | } |
249 | } |
249 | |
250 | |
250 | sub show_centered { |
251 | sub center { |
251 | my ($self) = @_; |
252 | my ($self) = @_; |
252 | return if $self->{parent}; |
|
|
253 | |
|
|
254 | $self->show; |
|
|
255 | |
253 | |
256 | $CFClient::UI::ROOT->on_post_alloc ( |
254 | $CFClient::UI::ROOT->on_post_alloc ( |
257 | "centered $self" => sub { |
255 | "center_$self" => sub { |
258 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
256 | $self->move (($self->{parent}{w} - $self->{w}) * 0.5, ($self->{parent}{h} - $self->{h}) * 0.5); |
259 | }, |
257 | }, |
260 | ); |
258 | ); |
|
|
259 | |
|
|
260 | $self->update; |
261 | } |
261 | } |
262 | |
262 | |
263 | sub set_visible { |
263 | sub set_visible { |
264 | my ($self) = @_; |
264 | my ($self) = @_; |
265 | |
265 | |
266 | return if $self->{visible}; |
266 | return if $self->{visible}; |
267 | |
267 | |
268 | $self->{root} = $self->{parent}{root}; |
268 | $self->{root} = $self->{parent}{root}; |
269 | $self->{visible} = $self->{parent}{visible} + 1; |
269 | $self->{visible} = $self->{parent}{visible} + 1; |
270 | |
270 | |
271 | $self->emit (visibility_change => 1) |
271 | $self->emit (visibility_change => 1); |
272 | } |
272 | } |
273 | |
273 | |
274 | sub set_invisible { |
274 | sub set_invisible { |
275 | my ($self) = @_; |
275 | my ($self) = @_; |
276 | |
276 | |
… | |
… | |
509 | sub set_parent { |
509 | sub set_parent { |
510 | my ($self, $parent) = @_; |
510 | my ($self, $parent) = @_; |
511 | |
511 | |
512 | Scalar::Util::weaken ($self->{parent} = $parent); |
512 | Scalar::Util::weaken ($self->{parent} = $parent); |
513 | |
513 | |
514 | $self->set_visible; |
514 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
515 | |
515 | |
516 | $self->check_size; |
516 | $self->check_size; |
517 | $self->show; |
|
|
518 | } |
517 | } |
519 | |
518 | |
520 | sub check_size { |
519 | sub check_size { |
521 | my ($self, $forced) = @_; |
520 | my ($self, $forced) = @_; |
522 | |
521 | |
… | |
… | |
835 | } |
834 | } |
836 | |
835 | |
837 | sub size_request { |
836 | sub size_request { |
838 | my ($self) = @_; |
837 | my ($self) = @_; |
839 | |
838 | |
840 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
839 | my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
841 | |
840 | |
842 | @$self{qw(child_w child_h)} |
841 | $w = 10 if $self->{scroll_x}; |
|
|
842 | $h = 10 if $self->{scroll_y}; |
|
|
843 | |
|
|
844 | ($w, $h) |
843 | } |
845 | } |
844 | |
846 | |
845 | sub size_allocate { |
847 | sub size_allocate { |
846 | my ($self, $w, $h) = @_; |
848 | my ($self, $w, $h) = @_; |
847 | |
849 | |
… | |
… | |
1324 | my ($self, $w, $h) = @_; |
1326 | my ($self, $w, $h) = @_; |
1325 | |
1327 | |
1326 | my $space = $self->{vertical} ? $h : $w; |
1328 | my $space = $self->{vertical} ? $h : $w; |
1327 | my $children = $self->{children}; |
1329 | my $children = $self->{children}; |
1328 | |
1330 | |
1329 | my @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
1331 | my @req; |
1330 | my $req = List::Util::sum @req; |
|
|
1331 | |
1332 | |
1332 | if ($req > $space) { |
1333 | if ($self->{homogeneous}) { |
1333 | # ah well, not enough space |
1334 | @req = ($space / (@$children || 1)) x @$children; |
1334 | $_ *= $space / $req for @req; |
|
|
1335 | } else { |
1335 | } else { |
|
|
1336 | @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
|
|
1337 | my $req = List::Util::sum @req; |
|
|
1338 | |
|
|
1339 | if ($req > $space) { |
|
|
1340 | # ah well, not enough space |
|
|
1341 | $_ *= $space / $req for @req; |
|
|
1342 | } else { |
1336 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1343 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1337 | |
1344 | |
|
|
1345 | $space = ($space - $req) / $expand; # remaining space to give away |
|
|
1346 | |
1338 | $req[$_] += ($space - $req) * $children->[$_]{expand} / $expand |
1347 | $req[$_] += $space * $children->[$_]{expand} |
1339 | for 0 .. $#$children; |
1348 | for 0 .. $#$children; |
|
|
1349 | } |
1340 | } |
1350 | } |
1341 | |
1351 | |
1342 | CFClient::UI::harmonize \@req; |
1352 | CFClient::UI::harmonize \@req; |
1343 | |
1353 | |
1344 | my $pos = 0; |
1354 | my $pos = 0; |
… | |
… | |
3113 | } |
3123 | } |
3114 | } |
3124 | } |
3115 | } |
3125 | } |
3116 | |
3126 | |
3117 | while ($self->{size_alloc}) { |
3127 | while ($self->{size_alloc}) { |
|
|
3128 | for ( |
|
|
3129 | sort { $a->[0]{visible} <=> $b->[0]{visible} } |
3118 | for (values %{delete $self->{size_alloc}}) { |
3130 | values %{delete $self->{size_alloc}} |
|
|
3131 | ) { |
3119 | my ($widget, $w, $h) = @$_; |
3132 | my ($widget, $w, $h) = @$_; |
3120 | |
3133 | |
3121 | $w = 0 if $w < 0; |
3134 | $w = 0 if $w < 0; |
3122 | $h = 0 if $h < 0; |
3135 | $h = 0 if $h < 0; |
3123 | |
3136 | |