NAME

LibUI::ColorButton - Color Picker

SYNOPSIS

use LibUI ':all';
use LibUI::Window;
use LibUI::ColorButton;
Init && die;
my $window = LibUI::Window->new( 'Hi', 320, 100, 0 );
$window->setMargined( 1 );
my $cbtn   = LibUI::ColorButton->new();
$cbtn->onChanged(
    sub {
        warn sprintf 'RGBA: #%02X%02X%02X%02X', map { $_ * 255 } $cbtn->color();
    },
    undef
);
$window->setChild($cbtn);
$window->onClosing(
    sub {
        Quit();
        return 1;
    },
    undef
);
$window->show;
Main();

DESCRIPTION

A LibUI::ColorButton object represents control with a color indicator that opens a color chooser when clicked.

The control visually represents a button with a color field representing the selected color.

Clicking on the button opens up a color chooser in form of a color palette.

Functions

Not a lot here but... well, it's just a button with managed utility.

color( )

my ($r, $g, $b, $a) = $cbtn->color( );

Returns the color button color where each is a double in range of 0.0 ... 1.0.

setColor( ... )

$cbtn->setColor( $r, $g, $b, $a );

Sets the color button color.

Expected parameters include:

$r - Red
$g - Green
$b - Blue
$a - Alpha

All parameters are doubles in the range of 0.0 ... 1.0.

onChanged( ... )

$cbtn->onChanged(sub { ... }, undef);

Registers a callback for when the color is changed.

Expected parameters include:

$callback - CodeRef which should expect the following when triggered:
$sender - Colorbutton that triggered callback
$userdata - Userdata as defined by... you
$userdata - Arbitrary data, if defined

Only one callback can be registered at a time. The callback is not triggered when calling setColor( ... ).

new( ... )

my $cbtn = LibUI::ColorButton->new( );

Creates a new LibUI::ColorButton.

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>