package Tk::ColorChoice;

use Tk;
use Tk::Font;
use base 'Tk::Frame';

use strict;
use warnings;

Construct Tk::Widget 'ColorChoice';

sub ClassInit
{
        my ($class, $mw) = @_;
        $class->SUPER::ClassInit($mw);
}

sub Populate
{
    my ($self, $args) = @_;
    $self->SUPER::Populate($args);

    $self->after(10, [$self, "init"]);
}

sub init
{
        my ($self) = @_;

        my (@colors) = qw(red pink purple blue green yellow orange red brown
black white);

        while(@colors)
        {
                my @currow;
                while(@colors and @currow < 4)
                {
                        my $color = shift @colors;
						my $button = $self->Button(-background => $color, -activebackground =>
							$color, -text => '     ');
						$button->configure(-command => [\&on_click, $self, $button]);
                        push @currow, $button;
                }
                last unless @currow;
                (shift @currow)->grid(@currow);
        }
}

sub on_click
{
    my ($self, $button) = @_;
	$self->{color} = $button->cget(-background);    
}


1;