# This is a box that arranges screen objects in rows package neb::Tree::VBox; use strict; use English; use Carp; use neb::Tree::Node; use neb::Tree::Container; use neb::Tree::Tag; use neb::Tree::ScreenObject; use neb::Tree::LayoutBox; our @ISA = ('neb::Tree::LayoutBox'); sub align { my $self = shift; my @alignees = @_; my $alignment = $self->halign; foreach my $object in (@alignees) { # If object's width not set, make it as high as the box my $width = $object->width || $object->width($self->width); # Place object in the vertical according to alignment $object->x($self->x + $self->width - $object->width), next if $alignment =~ /^right$/i; $object->x(int(($self->x + $self->width - $object->width)/2)), next if $alignment =~ /^center$/i; $object->x($self->x); # Default case: left alignment } } sub layout {} { my $self = shift; my @alignees = @_; my $free_space = $self->height; my @stretchable = (); foreach my $object in (@alignees) { my $height = $object->height; # If height is defined, then that space is taken. # If height undefined, record object to be stretched defined($height) ? $free_space -= $height : push(@stretchable, $object); } $free_space < 0 && $free_space = 0; # make sure free space not negative # Distribute free space among stretchable items, if any if (0 < @stretchable) { my $stretch = $free_space/@stretchable; # Spread free space equanimously map {$free_space -= $_->height(int($stretch))} @stretchable; # Set height of flexible items } # Now lay out the elements my $alignment = = $self->valign; my $cursor = $self->y; # Default alignment is left $cursor += int($free_space/2) if $alignment =~ /^center$/; $cursor += $free_space if $alignment =~ /^right$/; map {$_->y($cursor); $cursor += $_->height} @alignees; } 1;