… | |
… | |
245 | return if $self->{parent}; |
245 | return if $self->{parent}; |
246 | |
246 | |
247 | $CFClient::UI::ROOT->add ($self); |
247 | $CFClient::UI::ROOT->add ($self); |
248 | } |
248 | } |
249 | |
249 | |
250 | sub show_centered { |
250 | sub center { |
251 | my ($self) = @_; |
251 | my ($self) = @_; |
252 | return if $self->{parent}; |
|
|
253 | |
|
|
254 | $self->show; |
|
|
255 | |
252 | |
256 | $CFClient::UI::ROOT->on_post_alloc ( |
253 | $CFClient::UI::ROOT->on_post_alloc ( |
257 | "centered $self" => sub { |
254 | "center_$self" => sub { |
258 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
255 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
259 | }, |
256 | }, |
260 | ); |
257 | ); |
|
|
258 | |
|
|
259 | $self->update; |
261 | } |
260 | } |
262 | |
261 | |
263 | sub set_visible { |
262 | sub set_visible { |
264 | my ($self) = @_; |
263 | my ($self) = @_; |
265 | |
264 | |
… | |
… | |
509 | sub set_parent { |
508 | sub set_parent { |
510 | my ($self, $parent) = @_; |
509 | my ($self, $parent) = @_; |
511 | |
510 | |
512 | Scalar::Util::weaken ($self->{parent} = $parent); |
511 | Scalar::Util::weaken ($self->{parent} = $parent); |
513 | |
512 | |
514 | $self->set_visible; |
513 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
515 | |
514 | |
516 | $self->check_size; |
515 | $self->check_size; |
517 | $self->show; |
|
|
518 | } |
516 | } |
519 | |
517 | |
520 | sub check_size { |
518 | sub check_size { |
521 | my ($self, $forced) = @_; |
519 | my ($self, $forced) = @_; |
522 | |
520 | |
… | |
… | |
835 | } |
833 | } |
836 | |
834 | |
837 | sub size_request { |
835 | sub size_request { |
838 | my ($self) = @_; |
836 | my ($self) = @_; |
839 | |
837 | |
840 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
838 | my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
841 | |
839 | |
842 | @$self{qw(child_w child_h)} |
840 | $w = 10 if $self->{scroll_x}; |
|
|
841 | $h = 10 if $self->{scroll_y}; |
|
|
842 | |
|
|
843 | ($w, $h) |
843 | } |
844 | } |
844 | |
845 | |
845 | sub size_allocate { |
846 | sub size_allocate { |
846 | my ($self, $w, $h) = @_; |
847 | my ($self, $w, $h) = @_; |
847 | |
848 | |
… | |
… | |
1324 | my ($self, $w, $h) = @_; |
1325 | my ($self, $w, $h) = @_; |
1325 | |
1326 | |
1326 | my $space = $self->{vertical} ? $h : $w; |
1327 | my $space = $self->{vertical} ? $h : $w; |
1327 | my $children = $self->{children}; |
1328 | my $children = $self->{children}; |
1328 | |
1329 | |
1329 | my @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
1330 | my @req; |
1330 | my $req = List::Util::sum @req; |
|
|
1331 | |
1331 | |
1332 | if ($req > $space) { |
1332 | if ($self->{homogeneous}) { |
1333 | # ah well, not enough space |
1333 | @req = ($space / (@$children || 1)) x @$children; |
1334 | $_ *= $space / $req for @req; |
|
|
1335 | } else { |
1334 | } else { |
|
|
1335 | @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
|
|
1336 | my $req = List::Util::sum @req; |
|
|
1337 | |
|
|
1338 | if ($req > $space) { |
|
|
1339 | # ah well, not enough space |
|
|
1340 | $_ *= $space / $req for @req; |
|
|
1341 | } else { |
1336 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1342 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1337 | |
1343 | |
|
|
1344 | $space = ($space - $req) / $expand; # remaining space to give away |
|
|
1345 | |
1338 | $req[$_] += ($space - $req) * $children->[$_]{expand} / $expand |
1346 | $req[$_] += $space * $children->[$_]{expand} |
1339 | for 0 .. $#$children; |
1347 | for 0 .. $#$children; |
|
|
1348 | } |
1340 | } |
1349 | } |
1341 | |
1350 | |
1342 | CFClient::UI::harmonize \@req; |
1351 | CFClient::UI::harmonize \@req; |
1343 | |
1352 | |
1344 | my $pos = 0; |
1353 | my $pos = 0; |