| 1 | package Graphics::Primitive::TextBox; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use MooseX::Storage; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | # enum 'Graphics::Primitive::TextBox::Directions' => [( | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # 'auto', 'ltr', 'rtl' | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # )]; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # enum 'Graphics::Primitive::TextBox::WrapModes' | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # => [qw(word char word_char)]; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # enum 'Graphics::Primitive::TextBox::EllipsizeModes' | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # => [qw(none start middle end)]; | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | extends 'Graphics::Primitive::Component'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | with qw(MooseX::Clone Graphics::Primitive::Aligned); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | with Storage (format => 'JSON', io => 'File'); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Graphics::Primitive::Font; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | has 'angle' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | isa => 'Num', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | has 'direction' => ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | has 'ellipsize_mode' => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | has 'font' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | isa => 'Graphics::Primitive::Font', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | default => sub { Graphics::Primitive::Font->new }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | has '+horizontal_alignment' => ( default => sub { 'left'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | has 'indent' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | isa => 'Num', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | default => sub { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | has 'justify' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | default => sub { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | has 'layout' => ( | |||||||||||||||||||||||||||||||||||||||||
| 52 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | does => 'Graphics::Primitive::Driver::TextLayout', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | has 'lines' => ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | has 'line_height' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 59 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | isa => 'Num', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | has 'text' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 64 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | has 'text_bounding_box' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => 'Geometry::Primitive::Rectangle', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | trigger => sub { my ($self) = @_; $self->prepared(0); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | has '+vertical_alignment' => ( default => sub { 'top'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | has 'wrap_mode' => ( | |||||||||||||||||||||||||||||||||||||||||
| 75 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | override('prepare', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ($self, $driver) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | super; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return unless defined($self->text) || defined($self->lines) || defined($self->layout); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $self->text or defined $self->lines or defined $self->layout
defined $self->text or defined $self->lines
MC/DC0%0/3
defined $self->text or defined $self->lines or defined $self->layout
defined $self->text
defined $self->lines
defined $self->layout
Truth table0%0/4
A or B or C
A= defined $self->textB= defined $self->linesC= defined $self->layout
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | unless($self->lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $layout = $driver->get_textbox_layout($self); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->layout($layout); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $mw = $layout->width + $self->outside_width; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if($mw > $self->minimum_width) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->minimum_width($mw); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $mh = $layout->height + $self->outside_height; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if($mh > $self->minimum_height) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->minimum_height($mh); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | Graphics::Primitive::TextBox - Text component | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | Graphics::Primitive::TextBox is a Component with text. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | use Graphics::Primitive::Font; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | use Graphics::Primitive::TextBox; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | my $tx = Graphics::Primitive::TextBox->new( | ||||||||||||||||||||||||||||||||||||||||||
| 120 | font => Graphics::Primitive::Font->new( | ||||||||||||||||||||||||||||||||||||||||||
| 121 | face => 'Myriad Pro', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | size => 12 | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 124 | text => 'I am a textbox!' | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 WARNING | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | This component is likely to change drastically. Here be dragons. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head2 Constructor | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | =item I<new> | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | Creates a new Graphics::Primitive::TextBox. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =head2 Instance Methods | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =item I<angle> | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | The angle this text will be rotated. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =item I<font> | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | Set this textbox's font | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =item I<horizontal_alignment> | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | Horizontal alignment. See L<Graphics::Primitive::Aligned>. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =item I<text> | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Set this textbox's text. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =item I<vertical_alignment> | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | Vertical alignment. See L<Graphics::Primitive::Aligned>. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | Cory Watson, C<< <gphat@cpan.org> >> | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | Copyright 2008-2010 by Cory G Watson. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 178 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||