ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.412 by root, Sun Jul 22 20:08:17 2007 UTC vs.
Revision 1.413 by root, Mon Jul 23 15:30:45 2007 UTC

725 @{$self->{children}}, @widgets 725 @{$self->{children}}, @widgets
726 ]; 726 ];
727 727
728 $self->realloc; 728 $self->realloc;
729 729
730 $self->emit (c_add => \@widgets);
731
730 map $_+0, @widgets 732 map $_+0, @widgets
731} 733}
732 734
733sub children { 735sub children {
734 @{ $_[0]{children} } 736 @{ $_[0]{children} }
735} 737}
736 738
737sub remove { 739sub remove {
738 my ($self, $child) = @_; 740 my ($self, @widgets) = @_;
739 741
742 $self->emit (c_remove => \@widgets);
743
744 for my $child (@widgets) {
740 delete $child->{parent}; 745 delete $child->{parent};
741 $child->hide; 746 $child->hide;
742
743 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 747 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
748 }
744 749
745 $self->realloc; 750 $self->realloc;
746} 751}
747 752
748sub clear { 753sub clear {
776} 781}
777 782
778sub _draw { 783sub _draw {
779 my ($self) = @_; 784 my ($self) = @_;
780 785
781 $_->draw for @{$self->{children}}; 786 $_->draw for $self->visible_children;
782} 787}
783 788
784############################################################################# 789#############################################################################
785 790
786package CFPlus::UI::Bin; 791package CFPlus::UI::Bin;
796} 801}
797 802
798sub add { 803sub add {
799 my ($self, $child) = @_; 804 my ($self, $child) = @_;
800 805
801 $self->SUPER::remove ($_) for @{ $self->{children} }; 806 $self->clear;
802 $self->SUPER::add ($child); 807 $self->SUPER::add ($child);
803} 808}
804 809
805sub remove { 810sub remove {
806 my ($self, $widget) = @_; 811 my ($self, $widget) = @_;
1753our @ISA = CFPlus::UI::Container::; 1758our @ISA = CFPlus::UI::Container::;
1754 1759
1755sub size_request { 1760sub size_request {
1756 my ($self) = @_; 1761 my ($self) = @_;
1757 1762
1763 my @children = $self->visible_children;
1764
1758 $self->{vertical} 1765 $self->{vertical}
1759 ? ( 1766 ? (
1760 (List::Util::max map $_->{req_w}, @{$self->{children}}), 1767 (List::Util::max map $_->{req_w}, @children),
1761 (List::Util::sum map $_->{req_h}, @{$self->{children}}), 1768 (List::Util::sum map $_->{req_h}, @children),
1762 ) 1769 )
1763 : ( 1770 : (
1764 (List::Util::sum map $_->{req_w}, @{$self->{children}}), 1771 (List::Util::sum map $_->{req_w}, @children),
1765 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1772 (List::Util::max map $_->{req_h}, @children),
1766 ) 1773 )
1767} 1774}
1768 1775
1769sub invoke_size_allocate { 1776sub invoke_size_allocate {
1770 my ($self, $w, $h) = @_; 1777 my ($self, $w, $h) = @_;
2997} 3004}
2998 3005
2999sub size_request { 3006sub size_request {
3000 my ($self) = @_; 3007 my ($self) = @_;
3001 3008
3002 my ($empty, $slider) = @{ $self->{children} }; 3009 my ($empty, $slider) = $self->visible_children;
3003 3010
3004 local $self->{children} = [$empty, $slider]; 3011 local $self->{children} = [$empty, $slider];
3005 $self->SUPER::size_request 3012 $self->SUPER::size_request
3006} 3013}
3007 3014
3743 ); 3750 );
3744 3751
3745 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3752 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3746 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3753 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3747 3754
3755 {
3756 Scalar::Util::weaken (my $wself = $self);
3757
3758 $self->{multiplexer}->connect (c_add => sub {
3759 my ($mplex, $widgets) = @_;
3760
3761 for my $child (@$widgets) {
3762 Scalar::Util::weaken $child;
3763 $child->{c_tab_} ||= do {
3764 my $tab =
3765 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base")
3766 ? $child->{c_tab}
3767 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3768
3769 $tab->connect (activate => sub {
3770 $wself->set_current_page ($child);
3771 });
3772
3773 $tab
3774 };
3775
3776 $self->{buttonbar}->add ($child->{c_tab_});
3777 }
3778 });
3779
3780 $self->{multiplexer}->connect (c_remove => sub {
3781 my ($mplex, $widgets) = @_;
3782
3783 for my $child (@$widgets) {
3784 $wself->{buttonbar}->remove ($child->{c_tab_});
3785 }
3786 });
3787 }
3788
3748 $self 3789 $self
3749} 3790}
3750 3791
3751sub add { 3792sub add {
3793 my ($self, @widgets) = @_;
3794
3795 $self->{multiplexer}->add (@widgets)
3796}
3797
3798sub remove {
3799 my ($self, @widgets) = @_;
3800
3801 $self->{multiplexer}->remove (@widgets)
3802}
3803
3804sub add_tab {
3752 my ($self, $title, $widget, $tooltip) = @_; 3805 my ($self, $title, $widget, $tooltip) = @_;
3753 3806
3754 CFPlus::weaken $self; 3807 $title = [$title, $tooltip] unless ref $title;
3808 $widget->{c_tab} = $title;
3755 3809
3756 unless (ref $title) {
3757 $title = new CFPlus::UI::Button
3758 markup => $title,
3759 tooltip => $tooltip,
3760 ;
3761 }
3762
3763 $title->connect (activate => sub { $self->set_current_page ($widget) });
3764 $self->{buttonbar}->add ($title);
3765
3766 $self->{multiplexer}->add ($widget); 3810 $self->add ($widget);
3767} 3811}
3768 3812
3769sub get_current_page { 3813sub get_current_page {
3770 my ($self) = @_; 3814 my ($self) = @_;
3771 3815

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines