Widget/VLine.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 39 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2023 -- leonerd@leonerd.org.uk
5  
6 use v5.20;
7 use warnings;
8 use Object::Pad 0.807;
9  
10 package Tickit::Widget::VLine 0.42;
11 class Tickit::Widget::VLine :strict(params);
12  
13 inherit Tickit::Widget;
14  
15 use Tickit::Style;
16 use Tickit::RenderBuffer qw( LINE_SINGLE CAP_BOTH );
17  
18 use constant WIDGET_PEN_FROM_STYLE => 1;
19  
20 =head1 NAME
21  
22 C<Tickit::Widget::VLine> - a widget displaying a vertical line
23  
24 =head1 SYNOPSIS
25  
26 use Tickit::Widget::HBox;
27 use Tickit::Widget::VLine;
28  
29 my $hbox = Tickit::Widget::HBox->new;
30  
31 $hbox->add( ... );
32  
33 $hbox->add( Tickit::Widget::VLine->new );
34  
35 $hbox->add( ... );
36  
37 Tickit->new( root => $hbox )->run;
38  
39 =head1 DESCRIPTION
40  
41 This class provides a widget which displays a single vertical line, using
42 line-drawing characters. It consumes the full height of the window given to it
43 by its parent. By default it is drawn in the horizontal centre of the window but
44 this can be adjusted by the C<align> style value.
45  
46 =head1 STYLE
47  
48 The default style pen is used as the widget pen.
49  
50 The following additional style keys are used:
51  
52 =over 4
53  
54 =item line_style => INT
55  
56 The style to draw the line in. Must be one of the C<LINE_*> constants from
57 L<Tickit::RenderBuffer>.
58  
59 =item align => NUM | STR
60  
61 A fraction giving a position within the window to draw the line. Defaults to
62 C<0.5>, which puts it in the centre.
63  
64 Symbolic names of C<left>, C<centre> and C<right> are also accepted.
65  
66 =back
67  
68 =cut
69  
70 style_definition base =>
71 line_style => LINE_SINGLE,
72 align => 0.5;
73  
74 style_redraw_keys qw( line_style align );
75  
76 my %symbolics = (
77 left => 0.0,
78 centre => 0.5,
79 right => 1.0,
80 );
81  
82 =head1 CONSTRUCTOR
83  
84 =cut
85  
86 =head2 new
87  
88 $vline = Tickit::Widget::VLine->new( %args );
89  
90 Constructs a new C<Tickit::Widget::VLine> object.
91  
92 =cut
93  
94 method lines { 1 }
95 method cols { 1 }
96  
97 method render_to_rb
98 {
99 my ( $rb, $rect ) = @_;
100  
101 $rb->eraserect( $rect );
102  
103 my ( $line_style, $align ) = $self->get_style_values(qw( line_style align ));
104 $align = $symbolics{$align} if exists $symbolics{$align};
105  
106 my $col = int( ( $rb->cols - 1 ) * $align );
107 $rb->vline_at( 0, $rb->lines - 1, $col, $line_style, $self->pen, CAP_BOTH );
108 }
109  
110 =head1 AUTHOR
111  
112 Paul Evans <leonerd@leonerd.org.uk>
113  
114 =cut
115  
116 0x55AA;