… | |
… | |
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 | |
733 | sub children { |
735 | sub children { |
734 | @{ $_[0]{children} } |
736 | @{ $_[0]{children} } |
735 | } |
737 | } |
736 | |
738 | |
737 | sub remove { |
739 | sub 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 | |
748 | sub clear { |
753 | sub clear { |
… | |
… | |
776 | } |
781 | } |
777 | |
782 | |
778 | sub _draw { |
783 | sub _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 | |
786 | package CFPlus::UI::Bin; |
791 | package CFPlus::UI::Bin; |
… | |
… | |
796 | } |
801 | } |
797 | |
802 | |
798 | sub add { |
803 | sub 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 | |
805 | sub remove { |
810 | sub remove { |
806 | my ($self, $widget) = @_; |
811 | my ($self, $widget) = @_; |
… | |
… | |
948 | $self->{view_x} = $x; |
953 | $self->{view_x} = $x; |
949 | $self->{view_y} = $y; |
954 | $self->{view_y} = $y; |
950 | |
955 | |
951 | $self->emit (changed => $x, $y); |
956 | $self->emit (changed => $x, $y); |
952 | $self->update; |
957 | $self->update; |
|
|
958 | } |
|
|
959 | } |
|
|
960 | |
|
|
961 | sub set_center { |
|
|
962 | my ($self, $x, $y) = @_; |
|
|
963 | |
|
|
964 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
965 | } |
|
|
966 | |
|
|
967 | sub make_visible { |
|
|
968 | my ($self, $x, $y, $border) = @_; |
|
|
969 | |
|
|
970 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
971 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
972 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
973 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
974 | ) { |
|
|
975 | $self->set_center ($x, $y); |
953 | } |
976 | } |
954 | } |
977 | } |
955 | |
978 | |
956 | # hmm, this does not work for topleft of $self... but we should not ask for that |
979 | # hmm, this does not work for topleft of $self... but we should not ask for that |
957 | sub coord2local { |
980 | sub coord2local { |
… | |
… | |
1070 | my ($self, $widget) = @_; |
1093 | my ($self, $widget) = @_; |
1071 | |
1094 | |
1072 | $self->{vp}->add ($self->{child} = $widget); |
1095 | $self->{vp}->add ($self->{child} = $widget); |
1073 | } |
1096 | } |
1074 | |
1097 | |
|
|
1098 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1099 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1100 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1101 | |
1075 | sub update_slider { |
1102 | sub update_slider { |
1076 | my ($self) = @_; |
1103 | my ($self) = @_; |
1077 | |
1104 | |
1078 | my $child = ($self->{vp} or return)->child; |
1105 | my $child = ($self->{vp} or return)->child; |
1079 | |
1106 | |
… | |
… | |
1738 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1765 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1739 | |
1766 | |
1740 | $x += $child->{c_halign} * $child->{req_w}; |
1767 | $x += $child->{c_halign} * $child->{req_w}; |
1741 | $y += $child->{c_valign} * $child->{req_h}; |
1768 | $y += $child->{c_valign} * $child->{req_h}; |
1742 | |
1769 | |
1743 | $child->configure ($x, $y, $child->{req_w}, $child->{req_h}); |
1770 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1744 | } |
1771 | } |
1745 | |
1772 | |
1746 | 1 |
1773 | 1 |
1747 | } |
1774 | } |
1748 | |
1775 | |
… | |
… | |
1752 | |
1779 | |
1753 | our @ISA = CFPlus::UI::Container::; |
1780 | our @ISA = CFPlus::UI::Container::; |
1754 | |
1781 | |
1755 | sub size_request { |
1782 | sub size_request { |
1756 | my ($self) = @_; |
1783 | my ($self) = @_; |
|
|
1784 | |
|
|
1785 | my @children = $self->visible_children; |
1757 | |
1786 | |
1758 | $self->{vertical} |
1787 | $self->{vertical} |
1759 | ? ( |
1788 | ? ( |
1760 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1789 | (List::Util::max map $_->{req_w}, @children), |
1761 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1790 | (List::Util::sum map $_->{req_h}, @children), |
1762 | ) |
1791 | ) |
1763 | : ( |
1792 | : ( |
1764 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_w}, @children), |
1765 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1794 | (List::Util::max map $_->{req_h}, @children), |
1766 | ) |
1795 | ) |
1767 | } |
1796 | } |
1768 | |
1797 | |
1769 | sub invoke_size_allocate { |
1798 | sub invoke_size_allocate { |
1770 | my ($self, $w, $h) = @_; |
1799 | my ($self, $w, $h) = @_; |
… | |
… | |
2997 | } |
3026 | } |
2998 | |
3027 | |
2999 | sub size_request { |
3028 | sub size_request { |
3000 | my ($self) = @_; |
3029 | my ($self) = @_; |
3001 | |
3030 | |
3002 | my ($empty, $slider) = @{ $self->{children} }; |
3031 | my ($empty, $slider) = $self->visible_children; |
3003 | |
3032 | |
3004 | local $self->{children} = [$empty, $slider]; |
3033 | local $self->{children} = [$empty, $slider]; |
3005 | $self->SUPER::size_request |
3034 | $self->SUPER::size_request |
3006 | } |
3035 | } |
3007 | |
3036 | |
… | |
… | |
3739 | buttonbar => (new CFPlus::UI::Buttonbar), |
3768 | buttonbar => (new CFPlus::UI::Buttonbar), |
3740 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3769 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3741 | # filter => # will be put between multiplexer and $self |
3770 | # filter => # will be put between multiplexer and $self |
3742 | @_, |
3771 | @_, |
3743 | ); |
3772 | ); |
3744 | |
3773 | |
3745 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3774 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3746 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3775 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3747 | |
3776 | |
|
|
3777 | { |
|
|
3778 | Scalar::Util::weaken (my $wself = $self); |
|
|
3779 | |
|
|
3780 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3781 | my ($mplex, $widgets) = @_; |
|
|
3782 | |
|
|
3783 | for my $child (@$widgets) { |
|
|
3784 | Scalar::Util::weaken $child; |
|
|
3785 | $child->{c_tab_} ||= do { |
|
|
3786 | my $tab = |
|
|
3787 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
3788 | ? $child->{c_tab} |
|
|
3789 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
3790 | |
|
|
3791 | $tab->connect (activate => sub { |
|
|
3792 | $wself->set_current_page ($child); |
|
|
3793 | }); |
|
|
3794 | |
|
|
3795 | $tab |
|
|
3796 | }; |
|
|
3797 | |
|
|
3798 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
3799 | } |
|
|
3800 | }); |
|
|
3801 | |
|
|
3802 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
3803 | my ($mplex, $widgets) = @_; |
|
|
3804 | |
|
|
3805 | for my $child (@$widgets) { |
|
|
3806 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
3807 | } |
|
|
3808 | }); |
|
|
3809 | } |
|
|
3810 | |
3748 | $self |
3811 | $self |
3749 | } |
3812 | } |
3750 | |
3813 | |
3751 | sub add { |
3814 | sub add { |
|
|
3815 | my ($self, @widgets) = @_; |
|
|
3816 | |
|
|
3817 | $self->{multiplexer}->add (@widgets) |
|
|
3818 | } |
|
|
3819 | |
|
|
3820 | sub remove { |
|
|
3821 | my ($self, @widgets) = @_; |
|
|
3822 | |
|
|
3823 | $self->{multiplexer}->remove (@widgets) |
|
|
3824 | } |
|
|
3825 | |
|
|
3826 | sub pages { |
|
|
3827 | my ($self) = @_; |
|
|
3828 | $self->{multiplexer}->children |
|
|
3829 | } |
|
|
3830 | |
|
|
3831 | sub add_tab { |
3752 | my ($self, $title, $widget, $tooltip) = @_; |
3832 | my ($self, $title, $widget, $tooltip) = @_; |
3753 | |
3833 | |
3754 | CFPlus::weaken $self; |
3834 | $title = [$title, $tooltip] unless ref $title; |
|
|
3835 | $widget->{c_tab} = $title; |
3755 | |
3836 | |
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); |
3837 | $self->add ($widget); |
3767 | } |
3838 | } |
3768 | |
3839 | |
3769 | sub get_current_page { |
3840 | sub get_current_page { |
3770 | my ($self) = @_; |
3841 | my ($self) = @_; |
3771 | |
3842 | |