--- deliantra/Deliantra-Client/DC/UI.pm 2007/07/22 20:08:17 1.412 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/07/23 15:30:45 1.413 @@ -727,6 +727,8 @@ $self->realloc; + $self->emit (c_add => \@widgets); + map $_+0, @widgets } @@ -735,12 +737,15 @@ } sub remove { - my ($self, $child) = @_; + my ($self, @widgets) = @_; - delete $child->{parent}; - $child->hide; + $self->emit (c_remove => \@widgets); - $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; + for my $child (@widgets) { + delete $child->{parent}; + $child->hide; + $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; + } $self->realloc; } @@ -778,7 +783,7 @@ sub _draw { my ($self) = @_; - $_->draw for @{$self->{children}}; + $_->draw for $self->visible_children; } ############################################################################# @@ -798,7 +803,7 @@ sub add { my ($self, $child) = @_; - $self->SUPER::remove ($_) for @{ $self->{children} }; + $self->clear; $self->SUPER::add ($child); } @@ -1755,14 +1760,16 @@ sub size_request { my ($self) = @_; + my @children = $self->visible_children; + $self->{vertical} ? ( - (List::Util::max map $_->{req_w}, @{$self->{children}}), - (List::Util::sum map $_->{req_h}, @{$self->{children}}), + (List::Util::max map $_->{req_w}, @children), + (List::Util::sum map $_->{req_h}, @children), ) : ( - (List::Util::sum map $_->{req_w}, @{$self->{children}}), - (List::Util::max map $_->{req_h}, @{$self->{children}}), + (List::Util::sum map $_->{req_w}, @children), + (List::Util::max map $_->{req_h}, @children), ) } @@ -2999,7 +3006,7 @@ sub size_request { my ($self) = @_; - my ($empty, $slider) = @{ $self->{children} }; + my ($empty, $slider) = $self->visible_children; local $self->{children} = [$empty, $slider]; $self->SUPER::size_request @@ -3745,25 +3752,62 @@ $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); + { + Scalar::Util::weaken (my $wself = $self); + + $self->{multiplexer}->connect (c_add => sub { + my ($mplex, $widgets) = @_; + + for my $child (@$widgets) { + Scalar::Util::weaken $child; + $child->{c_tab_} ||= do { + my $tab = + (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") + ? $child->{c_tab} + : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; + + $tab->connect (activate => sub { + $wself->set_current_page ($child); + }); + + $tab + }; + + $self->{buttonbar}->add ($child->{c_tab_}); + } + }); + + $self->{multiplexer}->connect (c_remove => sub { + my ($mplex, $widgets) = @_; + + for my $child (@$widgets) { + $wself->{buttonbar}->remove ($child->{c_tab_}); + } + }); + } + $self } sub add { - my ($self, $title, $widget, $tooltip) = @_; + my ($self, @widgets) = @_; - CFPlus::weaken $self; + $self->{multiplexer}->add (@widgets) +} - unless (ref $title) { - $title = new CFPlus::UI::Button - markup => $title, - tooltip => $tooltip, - ; - } +sub remove { + my ($self, @widgets) = @_; + + $self->{multiplexer}->remove (@widgets) +} + +sub add_tab { + my ($self, $title, $widget, $tooltip) = @_; - $title->connect (activate => sub { $self->set_current_page ($widget) }); - $self->{buttonbar}->add ($title); + $title = [$title, $tooltip] unless ref $title; + $widget->{c_tab} = $title; - $self->{multiplexer}->add ($widget); + $self->add ($widget); } sub get_current_page {