Alt-Tickit-Widgets-ObjectPad
view release on metacpan or search on metacpan
lib/Tickit/Widget/CheckButton.pm view on Meta::CPAN
$on_toggle->( $checkbutton, $active )
=cut
method set_on_toggle
{
$_on_toggle = $_[0];
}
=head1 METHODS
=cut
=head2 $checkbutton->activate
Sets this button's active state to true.
=cut
method activate
{
$_active = 1;
$self->set_style_tag( active => 1 );
$_on_toggle->( $self, 1 ) if $_on_toggle;
}
=head2 $checkbutton->deactivate
Sets this button's active state to false.
=cut
method deactivate
{
$_active = 0;
$self->set_style_tag( active => 0 );
$_on_toggle->( $self, 0 ) if $_on_toggle;
}
*key_toggle = \&toggle;
method toggle
{
$self->is_active ? $self->deactivate : $self->activate;
return 1;
}
=head2 $active = $checkbutton->is_active
Returns this button's active state.
=cut
method is_active { !!$_active }
method reshape
{
my $win = $self->window or return;
my $check = $self->get_style_values( "check" );
$win->cursor_at( 0, ( textwidth( $check )-1 ) / 2 );
}
method render_to_rb
{
my ( $rb, $rect ) = @_;
$rb->clear;
return if $rect->top > 0;
$rb->goto( 0, 0 );
$rb->text( my $check = $self->get_style_values( "check" ), $self->get_style_pen( "check" ) );
$rb->erase( $self->get_style_values( "spacing" ) );
$rb->text( $self->label );
$rb->erase_to( $rect->right );
}
method on_mouse
{
my ( $args ) = @_;
return unless $args->type eq "press" and $args->button == 1;
return 1 unless $args->line == 0;
$self->toggle;
}
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
( run in 0.605 second using v1.01-cache-2.11-cpan-39bf76dae61 )