NAME

LibUI::Checkbox - User Checkable Box

SYNOPSIS

use LibUI ':all';
use LibUI::VBox;
use LibUI::Window;
use LibUI::Checkbox;
Init && die;
my $window = LibUI::Window->new( 'Hi', 320, 100, 0 );
$window->setMargined( 1 );
my $box    = LibUI::VBox->new();

sub checked {
    my ( $ctrl, $data ) = @_;
    printf "%s is %schecked\n", $ctrl->text, $ctrl->checked ? '' : 'un';
}
for my $lang (qw[Perl Rust Java C C++ Python Go COBOL]) {
    my $chk = LibUI::Checkbox->new($lang);
    $chk->onToggled( \&checked, undef );
    $box->append( $chk, 0 );
}
$window->setChild($box);
$window->onClosing(
    sub {
        Quit();
        return 1;
    },
    undef
);
$window->show;
Main();

DESCRIPTION

A LibUI::Checkbox object represents a user checkable box accompanied by a text label.

Functions

Not a lot here but... well, it's just a checkbox.

new( ... )

my $chk = LibUI::Checkbox->new( 'Perl' );

Creates a new checkbox.

checked( ... )

if( $chk->checked ) {
    ...;
}

Returns whether or the checkbox is checked.

onToggled( ... )

$chk->onToggled(
sub {
    my ($ctrl, $data) = @_;
    warn $ctrl->text;
}, undef);

Registers a callback for when the checkbox is toggled by the user.

Expected parameters include:

$callback - CodeRef that should expect the following:
$chk - backreference to the instance that initiated the callback
$data - user data registered with the sender instance
$data - user data to be passed to the callback

Note: The callback is not triggered when calling setChecked( ... ).

setChecked( ... )

$chk->setChecked( 1 );

Sets whether or not the checkbox is checked.

setText( ... )

$chk->setText( 'Updated' );

Sets the checkbox label text.

text( ... )

my $label = $chk->text( );

Returns the checkbox label text.

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Sanko Robinson <sanko@cpan.org>