Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI/Checkbox.pm view on Meta::CPAN
KEY_BTAB() => 'loose-focus',
CUI_SPACE() => 'toggle',
'0' => 'uncheck',
'n' => 'uncheck',
'1' => 'check',
'y' => 'check',
);
=head1 STANDARD OPTIONS
-x -y -width -height
-pad -padleft -padright -padtop -padbottom
-ipad -ipadleft -ipadright -ipadtop -ipadbottom
-title -titlefullwidth -titlereverse
-onfocus -onblur
-parent
See L<Curses::UI::Widget|Curses::UI::Widget> for an explanation of
these.
=head1 WIDGET-SPECIFIC OPTIONS
=head2 -label
Sets the initial label for the checkbox widget to the passed string or
value.
=head2 -checked
Takes a boolean argument. Determines if the widget's initial state is
checked or unchecked. The default is false (unchecked).
=head2 -onchange
Expects a coderef and sets it as a callback for the widget. When the
checkbox's state is changed, the given code will be executed.
=cut
sub new () {
my $class = shift;
my %userargs = @_;
keys_to_lowercase(\%userargs);
my %args = ( -parent => undef, # the parent window
-width => undef, # the width of the checkbox
-x => 0, # the horizontal pos. rel. to parent
-y => 0, # the vertical pos. rel. to parent
-checked => 0, # checked or not?
-label => '', # the label text
-onchange => undef, # event handler
-bg => -1,
-fg => -1,
%userargs,
-bindings => {%bindings},
-routines => {%routines},
-focus => 0, # value init
-nocursor => 0, # this widget uses a cursor
);
# The windowscr height should be 1.
$args{-height} = height_by_windowscrheight(1, %args);
# No width given? Then make the width the same size as the label +
# checkbox.
$args{-width} = width_by_windowscrwidth(4 + length($args{-label}),%args)
unless defined $args{-width};
my $this = $class->SUPER::new( %args );
# Create the label on the widget.
$this->add( 'label', 'Label',
-text => $this->{-label},
-x => 4,
-y => 0,
-intellidraw => 0,
-bg => $this->{-bg},
-fg => $this->{-fg},
) if $this->{-label};
$this->layout;
$this->set_mouse_binding('mouse-button1', BUTTON1_CLICKED())
if ($Curses::UI::ncurses_mouse);
return $this;
}
=head1 STANDARD METHODS
layout draw intellidraw
focus onFocus onBlur
See L<Curses::UI::Widget|Curses::UI::Widget> for an explanation of
these.
=cut
sub event_onblur() {
my $this = shift;
$this->SUPER::event_onblur;
$this->{-focus} = 0;
$this->draw();
return $this;
}
sub layout() {
my $this = shift;
my $label = $this->getobj('label');
if (defined $label) {
my $lh = $label->{-height};
$lh = 1 if $lh <= 0;
$this->{-height} = $lh;
}
( run in 0.667 second using v1.01-cache-2.11-cpan-39bf76dae61 )