NAME

LibUI::RadioButtons - Multiple Choice Array of Check Buttons

SYNOPSIS

use LibUI ':all';
use LibUI::VBox;
use LibUI::Window;
use LibUI::RadioButtons;
Init && die;
my $window = LibUI::Window->new( 'Age range', 320, 100, 0 );
$window->setMargined( 1 );
my $box    = LibUI::VBox->new();
my $radio  = LibUI::RadioButtons->new();
my @range  = qw[0-5 6-12 13-18 19-25 26-35 36-45 46-60 60+];
$radio->append($_) for @range;
$box->append( $radio, 0 );
$radio->onSelected( sub { warn 'Aged: ' . $range[ shift->selected ] }, undef );
$window->setChild($box);
$window->onClosing(
    sub {
        Quit();
        return 1;
    },
    undef
);
$window->show;
Main();

DESCRIPTION

A LibUI::RadioButtons object represents a multiple choice control of check buttons from which only one can be selected at a time.

Functions

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

new( )

my $lst = LibUI::RadioButtons->new( );

Creates a new radio buttons instance.

append( )

$lst->append( 'English' );

Appends a radio button.

onSelected( ... )

$lst->onSelected(
sub {
    my ($ctrl, $data) = @_;
    warn $ctrl->selected;
}, undef);

Registers a callback for when radio button is selected.

Expected parameters include:

$callback - CodeRef that should expect the following:
$lst - 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 setSelected( ... ).

selected( ... )

if( $lst->selected == 3 ) {
    ...;
}

Returns the index of the item selected or -1 if there is no selected element.

setSelected( ... )

$lst->setSelected( 3 );

Sets the item selected. Pass -1 to clear selection.

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>