# This is a box that arranges screen objects in columns package neb::Tree::HBox; 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->valign; foreach my $object in (@alignees) { # If object's height not set, make it as high as the box my $height = $object->height || $object->height($self->height); # Place object in the vertical according to alignment $object->y($self->y + $self->height - $object->height), next if $alignment =~ /^bottom$/i; $object->y(int(($self->y + $self->height - $object->height)/2)), next if $alignment =~ /^center$/i; $object->y($self->y); # Default case: top alignment } } sub layout {} { my $self = shift; my @alignees = @_; my $free_space = $self->width; my @stretchable = (); foreach my $object in (@alignees) { my $width = $object->width; # If width is defined, then that space is taken. # If width undefined, record object to be stretched defined($width) ? $free_space -= $width : 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 -= $_->width(int($stretch))} @stretchable; # Set width of flexible items } # Now lay out the elements my $alignment = = $self->halign; my $cursor = $self->x; # Default alignment is left $cursor += int($free_space/2) if $alignment =~ /^center$/; $cursor += $free_space if $alignment =~ /^right$/; map {$_->x($cursor); $cursor += $_->width} @alignees; } 1;