Graphics::Primitive::Insets - Space between things


Graphics-Primitive documentation Contained in the Graphics-Primitive distribution.

Index


Code Index:

NAME

Top

Graphics::Primitive::Insets - Space between things

DESCRIPTION

Top

Graphics::Primitive::Insets represents the amount of space that surrounds something. This object can be used to represent either padding or margins (in the CSS sense, one being inside the bounding box, the other being outside)

SYNOPSIS

Top

  use Graphics::Primitive::Insets;

  my $insets = Graphics::Primitive::Insets->new({
    top     => 5,
    bottom  => 5,
    left    => 5,
    right   => 5
  });

METHODS

Top

Constructor

new

Creates a new Graphics::Primitive::Insets.

Instance Methods

as_array

Return these insets as an array in the form of top, right, bottom and left.

bottom

Set/Get the inset from the bottom.

equal_to

Determine if these Insets are equal to another.

left

Set/Get the inset from the left.

right

Set/Get the inset from the right.

top

Set/Get the inset from the top.

zero

Sets all the insets (top, left, bottom, right) to 0.

AUTHOR

Top

Cory Watson, <gphat@cpan.org>

SEE ALSO

Top

perl(1)

COPYRIGHT & LICENSE

Top


Graphics-Primitive documentation Contained in the Graphics-Primitive distribution.

package Graphics::Primitive::Insets;
use Moose;
use MooseX::Storage;

with 'Geometry::Primitive::Equal';

with 'MooseX::Clone';
with Storage (format => 'JSON', io => 'File');

use Moose::Util::TypeConstraints;

coerce 'Graphics::Primitive::Insets'
    => from 'ArrayRef'
        => via {
            Graphics::Primitive::Insets->new(
                top => $_->[0], right => $_->[1],
                bottom => $_->[2], left => $_->[3]
            )
        };

coerce 'Graphics::Primitive::Insets'
    => from 'Num'
        => via {
            Graphics::Primitive::Insets->new(
                top => $_, right => $_,
                bottom => $_, left => $_
            )
        };

has 'top' => ( is => 'rw', isa => 'Num', default => 0 );
has 'bottom' => ( is => 'rw', isa => 'Num', default => 0 );
has 'left' => ( is => 'rw', isa => 'Num', default => 0 );
has 'right' => ( is => 'rw', isa => 'Num', default => 0 );

sub as_array {
    my ($self) = @_;

    return ($self->top, $self->right, $self->bottom, $self->left);
}

sub equal_to {
    my ($self, $other) = @_;

    return ($self->top == $other->top) && ($self->bottom == $other->bottom)
        && ($self->left == $other->left) && ($self->right == $other->right);
}

sub width {
    my ($self, $width) = @_;

    $self->top($width); $self->bottom($width);
    $self->left($width); $self->right($width);
}

sub zero {
    my ($self) = @_;

    $self->width(0);
}

__PACKAGE__->meta->make_immutable;

no Moose;
1;
__END__