| Graphics-Primitive documentation | Contained in the Graphics-Primitive distribution. |
Graphics::Primitive::Insets - Space between things
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)
use Graphics::Primitive::Insets;
my $insets = Graphics::Primitive::Insets->new({
top => 5,
bottom => 5,
left => 5,
right => 5
});
Creates a new Graphics::Primitive::Insets.
Return these insets as an array in the form of top, right, bottom and left.
Set/Get the inset from the bottom.
Determine if these Insets are equal to another.
Set/Get the inset from the left.
Set/Get the inset from the right.
Set/Get the inset from the top.
Sets all the insets (top, left, bottom, right) to 0.
Cory Watson, <gphat@cpan.org>
perl(1)
Copyright 2008-2010 by Cory G Watson.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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__