blib/lib/Term/Fabulous/Viewport.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 100% 53 / 53 CC 5 SCAR 6.2
CC
5
Cov
100%
reveal_range
3.0
scroll_thumb
3.0
BEGIN
1.0
CRAP 1.9
« blib/lib/Term/Fabulous/Widget/XYChart.pm ↑ Summary blib/lib/Term/Fabulous/Termbox/Event.pm »
1 package Term::Fabulous::Viewport;
2  
3 1 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT_OK = qw(max_offset clamp_offset reveal_range scroll_thumb);
12  
13 1 ▶use List::Util qw(max min);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # How far the content can scroll: the part of it the viewport cannot
16 # show at once.
17 31 ▶sub max_offset ( $content, $viewport ) {
Subroutine max_offset: called CC=1 SCAR=0.0
Pod documented
18 31 return max( 0, $content - $viewport );
19 }
20  
21 16 ▶sub clamp_offset ( $content, $viewport, $offset ) {
Subroutine clamp_offset: called CC=1 SCAR=0.0
Pod documented
22 16 return min( max( $offset, 0 ), max_offset( $content, $viewport ) );
23 }
24  
25 # The offset nearest to $offset that shows the range [from, to); a range
26 # taller than the viewport shows its start.
27 10 ▶sub reveal_range ( $content, $viewport, $offset, $from, $to ) {
Subroutine reveal_range: called CC=3 SCAR=11.0
Pod documented
28 10 ▶ my $wanted
Branch: 2 branches
BranchTrueFalseTotal
$from < $offset ? : 2 8 10
$to > $offset + $viewport ? : 4 4 8
29 = $from < $offset ? $from
30 : $to > $offset + $viewport ? min( $from, $to - $viewport )
31 : $offset;
32 10 return clamp_offset( $content, $viewport, $wanted );
33 }
34  
35 # The thumb of a scrollbar track of $track cells: [ first cell, cells ].
36 # Its size is the visible part of the content, at least one cell; its
37 # place is the offset's share of the scrolling distance. Content that
38 # fits fills the track.
39 12 ▶sub scroll_thumb ( $content, $viewport, $offset, $track ) {
Subroutine scroll_thumb: called CC=3 SCAR=11.0
Pod documented
40 12 ▶ return [ 0, max( 0, $track ) ] if $track < 1 || $content <= $viewport;
Branch: 1 branch
BranchTrueFalseTotal
if $track < 1 or $content <= $viewport 3 9 12
Condition100%3/3
$track < 1 or $content <= $viewport
l!l&&r!l&&!r
129
MC/DC100%2/2
$track < 1 or $content <= $viewport
$track < 1 $content <= $viewport
Truth table100%3/3
A or B
A= $track < 1B= $content <= $viewport
ABresult
1X1
011
000
41 9 my $size = max( 1, min( $track, int( $track * $viewport / $content + 0.5 ) ) );
42 9 my $first = int( ( $track - $size ) * $offset / max_offset( $content, $viewport ) + 0.5 );
43 9 return [ max( 0, min( $track - $size, $first ) ), $size ];
44 }
45  
46 1 1;
47  
48 __END__
« blib/lib/Term/Fabulous/Widget/XYChart.pm ↑ Summary blib/lib/Term/Fabulous/Termbox/Event.pm »