| 1 | package TUI::Menus::MenuBar; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TMenuBar object manages the menu bar across the top of the app. | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 62 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 62 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 62 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 62 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 62 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 62 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 62 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 62 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TMenuBar | ||||||||||||||||||||||||||||
| 15 | new_TMenuBar | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 62 | ▶ | use Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 62 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 62 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | Maybe | ||||||||||||||||||||||||||||
| 22 | :is | ||||||||||||||||||||||||||||
| 23 | :types | ||||||||||||||||||||||||||||
| 24 | 62 | ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 62 | ▶ | use TUI::Drivers::Util qw( cstrlen ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 62 | ▶ | use TUI::Menus::Menu; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 62 | ▶ | use TUI::Menus::MenuView; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 62 | ▶ | use TUI::Menus::SubMenu; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 62 | ▶ | use TUI::Views::DrawBuffer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 62 | ▶ | use TUI::Objects::Rect; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 62 | ▶ | use TUI::Views::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | gfGrowHiX | ||||||||||||||||||||||||||||
| 34 | ofPreProcess | ||||||||||||||||||||||||||||
| 35 | 62 | ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub TMenuBar() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 38 | sub name() { 'TMenuBar' } | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub new_TMenuBar { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TMenuBar: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 62 | extends TMenuView; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 45 | method => 1, | ||||||||||||||||||||||||||||
| 46 | named => [ | ||||||||||||||||||||||||||||
| 47 | bounds => Object, | ||||||||||||||||||||||||||||
| 48 | menu => Maybe[Object], { alias => 'aMenu' }, | ||||||||||||||||||||||||||||
| 49 | ], | ||||||||||||||||||||||||||||
| 50 | caller_level => +1, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 53 | 0 | return { %$args }; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | assert ( is_HashRef $args ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | my $menu = $args->{menu}; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->{menu} = ref $menu && $menu->isa(TSubMenu) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $menu and $menu->isa("TUI::Menus::SubMenu")
MC/DC0%0/2
ref $menu and $menu->isa("TUI::Menus::SubMenu")
ref $menu
$menu->isa("TUI::Menus::SubMenu")
Truth table0%0/3
A and B
A= ref $menuB= $menu->isa("TUI::Menus::SubMenu")
| |||||||||||||||||||||||||||||
| 63 | ? TMenu->new( items => $menu ) | ||||||||||||||||||||||||||||
| 64 | : $menu; | ||||||||||||||||||||||||||||
| 65 | 0 | $self->{growMode} = gfGrowHiX; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{options} |= ofPreProcess; | |||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub from { # $obj ($bounds, $aMenu) | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 72 | method => 1, | ||||||||||||||||||||||||||||
| 73 | pos => [Object, Maybe[Object]], | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | 0 | my ( $class, @args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 76 | 0 | return $class->new( bounds => $args[0], menu => $args[1] ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | undef $self->{menu}; | |||||||||||||||||||||||||||
| 84 | 0 | return; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub draw { # void () | ||||||||||||||||||||||||||
|
Subroutine
draw: not called CC=8 SCAR=40.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 89 | method => Object, | ||||||||||||||||||||||||||||
| 90 | pos => [], | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 93 | 0 | my $color; | |||||||||||||||||||||||||||
| 94 | 0 | my ( $x, $l ); | |||||||||||||||||||||||||||
| 95 | 0 | my $p; | |||||||||||||||||||||||||||
| 96 | 0 | my $b = TDrawBuffer->new(); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $cNormal = $self->getColor( 0x0301 ); | |||||||||||||||||||||||||||
| 99 | 0 | my $cSelect = $self->getColor( 0x0604 ); | |||||||||||||||||||||||||||
| 100 | 0 | my $cNormDisabled = $self->getColor( 0x0202 ); | |||||||||||||||||||||||||||
| 101 | 0 | my $cSelDisabled = $self->getColor( 0x0505 ); | |||||||||||||||||||||||||||
| 102 | 0 | $b->moveChar( 0, ' ', $cNormal, $self->{size}{x} ); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( $self->{menu} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $x = 1; | |||||||||||||||||||||||||||
| 105 | 0 | $p = $self->{menu}{items}; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | while ( $p ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( $p->{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | $l = cstrlen( $p->{name} ); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $x + $l < $self->{size}{x} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 62 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $p->{disabled} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | $color = ( $p == $self->{current} ) | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | ? $cSelDisabled | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | : $cNormDisabled; | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||
| 117 | $color = ( $p == $self->{current} ) | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | ? $cSelect | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | : $cNormal; | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | $b->moveChar( $x, ' ', $color, 1 ); | |||||||||||||||||||||||||||
| 122 | 0 | $b->moveCStr( $x + 1, $p->{name}, $color ); | |||||||||||||||||||||||||||
| 123 | 0 | $b->moveChar( $x + $l + 1, ' ', $color, 1 ); | |||||||||||||||||||||||||||
| 124 | } #/ if ( $x + $l < $self->...) | ||||||||||||||||||||||||||||
| 125 | 0 | $x += $l + 2; | |||||||||||||||||||||||||||
| 126 | } #/ if ( $p->{name} ) | ||||||||||||||||||||||||||||
| 127 | 0 | $p = $p->{next}; | |||||||||||||||||||||||||||
| 128 | } #/ while ( $p ) | ||||||||||||||||||||||||||||
| 129 | } #/ if ( $self->{menu} ) | ||||||||||||||||||||||||||||
| 130 | 0 | $self->writeBuf( 0, 0, $self->{size}{x}, 1, $b ); | |||||||||||||||||||||||||||
| 131 | } #/ sub draw | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub getItemRect { # $rect ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
getItemRect: not called CC=3 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 135 | method => Object, | ||||||||||||||||||||||||||||
| 136 | pos => [Maybe[Object]], | ||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||
| 138 | 0 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 139 | 0 | my $r = TRect->new( ax => 1, ay => 0, bx => 1, by => 1 ); | |||||||||||||||||||||||||||
| 140 | 0 | my $p = $self->{menu}{items}; | |||||||||||||||||||||||||||
| 141 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||
| 142 | 0 | $r->{a}{x} = $r->{b}{x}; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ( $p->{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | $r->{b}{x} += cstrlen( $p->{name} ) + 2; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $r | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | if $p == $item; | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 0 | $p = $p->{next}; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub build { # $obj () | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | 0 | my ( $class ) = @_; | |||||||||||||||||||||||||||
| 157 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | assert ( is_Str $class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | return $class->new( | |||||||||||||||||||||||||||
| 161 | bounds => TRect->new(), | ||||||||||||||||||||||||||||
| 162 | menu => undef, | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 62 | 1 | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||