File: TextLayout.pm

package info (click to toggle)
libgraphics-primitive-perl 0.67-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: perl: 2,586; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 1,680 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package Graphics::Primitive::Driver::TextLayout;
use Moose::Role;

requires 'slice';

has 'component' => (
    is => 'rw',
    isa => 'Graphics::Primitive::TextBox',
    required => 1,
    weak_ref => 1
);
has 'height' => (
    is => 'rw',
    isa => 'Num',
    default => sub { -1 }
);
has 'width' => (
    is => 'rw',
    isa => 'Num',
    lazy => 1,
    default => sub { my ($self) = @_; $self->component->width }
);

no Moose;
1;
__END__;
=head1 NAME

Graphics::Primitive::Driver::TextLayout - TextLayout role

=head1 DESCRIPTION

Graphics::Primitive::Driver::TextLayout is a role for Driver text layout
engines.

=head1 SYNOPSIS

    package MyLayout;
    use Moose;

    with 'Graphics::Primitive::Driver::TextLayout';

    ...

=head1 METHODS

=over 4

=item I<component>

Set/Get the component from which to draw layout information.

=item I<height>

Set/Get this layout's height

=item I<slice>

Implemented by role consumer. Given an offset and an optional size, returns a
TextBox containing lines from this layout that come as close to C<$size>
without exceeding it.  This method is provided to allow incremental rendering
of text.  For example, if you have a series of containers 80 units high, you
might write code like this:

  for(my $i = 0; $i < 3; $i++) {
      $textbox = $layout->slice($i * 80, 80);
      # render the text
  }

=item I<width>

Set/Get this layout's width.  Defaults to the width of the component supplied.

=back

=head1 AUTHOR

Cory Watson, C<< <gphat@cpan.org> >>

=head1 COPYRIGHT & LICENSE

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.