AAC-Pvoice
view release on metacpan or search on metacpan
lib/AAC/Pvoice/Row.pm view on Meta::CPAN
package AAC::Pvoice::Row;
use strict;
use warnings;
use Wx qw(:everything);
use Wx::Perl::Carp;
use AAC::Pvoice::Bitmap;
use base qw(Wx::Panel);
our $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $=~/(\d+)\.(\d+)/);
#----------------------------------------------------------------------
sub new
{
my $class = shift;
my ($parent,$maxitems,$items,
$wxPos,$wxSize, $itemmaxX, $itemmaxY,
$itemspacing, $background, $style,$name) = @_;
my $self = $class->SUPER::new( $parent,
Wx::NewId,
$wxPos || wxDefaultPosition,
$wxSize || wxDefaultSize,
$style || 0,
$name || '');
$self->{maxitems} = $maxitems;
my $sizer = Wx::GridSizer->new(1,0);
$self->{items} = [];
$self->{actions} = [];
my ($maxX, $maxY) = ($itemmaxX, $itemmaxY);
# Add the defined keys for this row
for (@$items)
{
if (not defined $_)
{
my $empty = Wx::BitmapButton->new( $self,
Wx::NewId,
wxNullBitmap,
wxDefaultPosition,
[$maxX, $maxY],
wxSUNKEN_BORDER);
$empty->SetBackgroundColour($background);
$sizer->Add($empty,0, wxALIGN_CENTRE|wxALL, $itemspacing);
next;
}
my ($id, $img, $sub) = @$_;
my $button = Wx::BitmapButton->new ($self, # parent
$id, # id
$img, # image
wxDefaultPosition, # position
[$maxX, $maxY],# size
wxSUNKEN_BORDER); # style
$button->SetBackgroundColour($background);
$sizer->Add($button, 0, wxALIGN_CENTRE|wxALL, $itemspacing);
push @{$self->{items}}, $button;
push @{$self->{actions}}, $sub;
push @{$self->{ids}}, $id;
}
my $totalitems = scalar(@$items);
$self->{totalitems} = scalar(@{$self->{items}});
for (0..($self->{maxitems} - $totalitems -1))
{
my $empty = Wx::BitmapButton->new( $self,
Wx::NewId,
wxNullBitmap,
wxDefaultPosition,
[$maxX, $maxY],
wxSUNKEN_BORDER);
$empty->SetBackgroundColour($background);
$sizer->Add($empty,0, wxALIGN_CENTRE|wxALL, $itemspacing);
}
$self->SetBackgroundColour($background);
$self->SetSizer($sizer);
$self->SetAutoLayout(1);
$sizer->Fit($self);
return $self;
}
1;
__END__
=pod
=head1 NAME
AAC::Pvoice::Row - A row of selectable items
=head1 SYNOPSIS
use AAC::Pvoice::Row;
use Wx;
my $panel = Wx::Panel->new($self, -1);
my $items = [ [Wx::NewId, $SomeWxBitmap, sub{ print "do something useful here"} ],
[Wx::NewId, $SomeOtherWxBitmap, sub{ print "do something else here"} ]];
my $row = AAC::Pvoice::Row->new($panel, # parent
scalar(@$items), # max
$items, # items
wxDefaultPosition,# pos
wxDefaultSize, # size
50, # maxX
75, # maxY
5, # spacing
wxWHITE) # background colour
=head1 DESCRIPTION
AAC::Pvoice::Row is a subclass of Wx::Panel. It will typically be placed
on an AAC::Pvoice::Panel, and contains selectable Wx::Bitmap-s, which,
when selected, will invoke a callback.
( run in 1.092 second using v1.01-cache-2.11-cpan-bbc515a03b3 )