The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

LibUI::Spinbox - Control to Display and Modify Integer Values via a Text Field or +/- Buttons

SYNOPSIS

    use LibUI ':all';
    use LibUI::VBox;
    use LibUI::Window;
    use LibUI::Spinbox;
    Init( { Size => 1024 } ) && die;
    my $window = LibUI::Window->new( 'Hi', 320, 100, 0 );
    my $box    = LibUI::VBox->new();
    my $count  = LibUI::Spinbox->new( 1, 100 );
    $box->append( $count, 0 );
    $count->onChanged( sub { warn shift->value }, undef );
    $window->setChild($box);
    $window->onClosing(
        sub {
            Quit();
            return 1;
        },
        undef
    );
    $window->show;
    Main();

DESCRIPTION

A LibUI::Spinbox object represents a control to display and modify integer values via a text field or +/- buttons.

This is a convenient control for having the user enter integer values. Values are guaranteed to be within the specified range.

The + button increases the held value by 1.

The - button decreased the held value by 1.

Entering a value out of range will clamp to the nearest value in range.

Functions

Not a lot here but... well, it's just a text box with some little buttons.

new( ... )

    my $count = LibUI::Spinbox->new( 1, 100 );

Creates a new spinbox.

Expected parameters include:

$min - minimum value
$max - maximum value

The initial spinbox value equals the $minimum value.

In the current upstream implementation, $min and $max are swapped if $min is greater than $max. This may change in the future though.

onChanged( ... )

    $count->onChanged(
    sub {
        my ($ctrl, $data) = @_;
        warn $ctrl->value;
    }, undef);

Registers a callback for when the spinbox value is changed by the user.

Expected parameters include:

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

setValue( ... )

    $count->setValue( 50 );

Sets the spinbox value.

value( ... )

    warn $count->value( );

Returns the spinbox value.

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>