/[papo]/papo/neb/neb/Tree/LayoutBox.pm
ViewVC logotype

Diff of /papo/neb/neb/Tree/LayoutBox.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by fheinz, Wed Apr 16 14:07:05 2003 UTC revision 1.6 by fheinz, Wed Apr 16 18:19:03 2003 UTC
# Line 37  sub boxtype Line 37  sub boxtype
37      return $self->attribute("lam:boxtype") || "v";      return $self->attribute("lam:boxtype") || "v";
38  }  }
39    
40    sub computed_height
41    {
42        my $self = shift;
43        my $height = 0;
44        my $horizontal = $self->boxtype =~ /^h/i;
45    
46        foreach my $child (grep {ref} map {$_->screen_children} $self->content)
47        {
48            my $child_height = $child->height;
49            ($height = undef), last unless defined $child_height;
50            ($height = $child_height), next if $horizontal && $height < $child_height;
51            $height += $child_height unless $horizontal;
52        }
53        return $height;
54    }
55    
56    sub height
57    {
58        my $self = shift;
59        my $height = shift;
60    
61        return $self->SUPER::height($height) if defined($height);
62    
63        $height = $self->SUPER::height;
64        return undef if defined($height) && $height eq "*";
65        if (!defined($height))
66        {
67            $height = $self->computed_height;
68            $self->SUPER::height($height) if defined($height);
69        }
70        return $self->SUPER::height;
71    }
72    
73    sub computed_width
74    {
75        my $self = shift;
76        my $width = 0;
77        my $vertical = $self->boxtype =~ /^v/i;
78    
79        foreach my $child (grep {ref} map {$_->screen_children} $self->content)
80        {
81            my $child_width = $child->width;
82            ($width = undef), last unless defined $child_width;
83            ($width = $child_width), next if $vertical && $width < $child_width;
84            $width += $child_width unless $vertical;
85        }
86        return $width;
87    }
88    
89    
90    sub width
91    {
92        my $self = shift;
93        my $width = shift;
94    
95        return $self->SUPER::width($width) if defined($width);
96    
97        $width = $self->SUPER::width;
98        return undef if defined($width) && $width eq "*";
99        if (!defined($width))
100        {
101            $width = $self->computed_width;
102            $self->SUPER::width($width) if defined($width);
103        }
104        return $self->SUPER::width;
105    }
106    
107  sub contents_width  sub contents_width
108  {  {
109      my $self = shift;      my $self = shift;
# Line 76  sub align_vertically Line 143  sub align_vertically
143          # If object's width not set, make it as wide as the box          # If object's width not set, make it as wide as the box
144          my $width = $object->width || $object->width($self->contents_width);          my $width = $object->width || $object->width($self->contents_width);
145    
146            # Don't touch object if coordinate exists.
147            next if defined($object->x);
148    
149          # Place object in the vertical according to alignment          # Place object in the vertical according to alignment
150          $object->x($self->contents_origin_x + $self->contents_width - $object->width), next if $alignment =~ /^r/i; #          $object->x($self->contents_origin_x + $self->contents_width - $object->width), next if $alignment =~ /^r/i; #
151          $object->x(int(($self->contents_origin_x + $self->contents_width - $object->width)/2)), next if $alignment =~ /^c/i;          $object->x(int(($self->contents_origin_x + $self->contents_width - $object->width)/2)), next if $alignment =~ /^c/i;
# Line 89  sub layout_vertically Line 159  sub layout_vertically
159      my @alignees = @_;      my @alignees = @_;
160      my $free_space = $self->contents_height;      my $free_space = $self->contents_height;
161      my @stretchable = ();      my @stretchable = ();
162        my @layoutable = ();
163    
164      foreach my $object (@alignees)      foreach my $object (@alignees)
165      {      {
166          my $height = $object->height;          my $height = $object->height;
167    
168            # ignore object that are already in place
169            next if defined($object->y);
170            push(@layoutable, $object);
171    
172          # If height is defined, then that space is taken.          # If height is defined, then that space is taken.
173          # If height undefined, record object to be stretched          # If height undefined, record object to be stretched
174          defined($height) ? $free_space -= $height : push(@stretchable, $object);          defined($height) ? $free_space -= $height : push(@stretchable, $object);
# Line 111  sub layout_vertically Line 187  sub layout_vertically
187      my $cursor = $self->contents_origin_y;      # Default alignment is top      my $cursor = $self->contents_origin_y;      # Default alignment is top
188      $cursor += int($free_space/2) if $alignment =~ /^c/i;      $cursor += int($free_space/2) if $alignment =~ /^c/i;
189      $cursor += $free_space if $alignment =~ /^b/i;      $cursor += $free_space if $alignment =~ /^b/i;
190      map {$_->y($cursor); $cursor += $_->height} @alignees;      map {$_->y($cursor); $cursor += $_->height} @layoutable;
191            
192  }  }
193    
# Line 126  sub align_horizontally Line 202  sub align_horizontally
202          # If object's height not set, make it as high as the box          # If object's height not set, make it as high as the box
203          my $height = $object->height || $object->height($self->contents_height);          my $height = $object->height || $object->height($self->contents_height);
204    
205            # Don't touch object if coordinate exists.
206            next if defined($object->y);
207    
208          # Place object in the vertical according to alignment          # Place object in the vertical according to alignment
209          $object->y($self->contents_origin_y + $self->contents_height - $object->height), next if $alignment =~ /^b/i;          $object->y($self->contents_origin_y + $self->contents_height - $object->height), next if $alignment =~ /^b/i;
210          $object->y(int(($self->contents_origin_y + $self->contents_height - $object->height)/2)), next if $alignment =~ /^c/i;          $object->y(int(($self->contents_origin_y + $self->contents_height - $object->height)/2)), next if $alignment =~ /^c/i;
# Line 139  sub layout_horizontally Line 218  sub layout_horizontally
218      my @alignees = @_;      my @alignees = @_;
219      my $free_space = $self->contents_width;      my $free_space = $self->contents_width;
220      my @stretchable = ();      my @stretchable = ();
221        my @layoutable = ();
222    
223      foreach my $object (@alignees)      foreach my $object (@alignees)
224      {      {
225          my $width = $object->width;          my $width = $object->width;
226    
227            # ignore object that are already in place
228            next if defined($object->x);
229            push(@layoutable, $object);
230    
231          # If width is defined, then that space is taken.          # If width is defined, then that space is taken.
232          # If width undefined, record object to be stretched          # If width undefined, record object to be stretched
233          defined($width) ? $free_space -= $width : push(@stretchable, $object);          defined($width) ? $free_space -= $width : push(@stretchable, $object);
# Line 161  sub layout_horizontally Line 246  sub layout_horizontally
246      my $cursor = $self->contents_origin_x;      # Default alignment is left      my $cursor = $self->contents_origin_x;      # Default alignment is left
247      $cursor += int($free_space/2) if $alignment =~ /^c/i; # Advance cursor by free/2: centered      $cursor += int($free_space/2) if $alignment =~ /^c/i; # Advance cursor by free/2: centered
248      $cursor += $free_space if $alignment =~ /^r/i; # Advance cursor by free: flush right      $cursor += $free_space if $alignment =~ /^r/i; # Advance cursor by free: flush right
249      map {$_->x($cursor); $cursor += $_->width} @alignees;      map {$_->x($cursor); $cursor += $_->width} @layoutable;
250            
251  }  }
252    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26