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