Alt-Tickit-Widgets-ObjectPad
view release on metacpan or search on metacpan
lib/Tickit/Widget/RadioButton.pm view on Meta::CPAN
if( my $old = $_group->active ) {
$old->set_style_tag( active => 0 );
$old->on_toggle->( $old, 0 ) if $old->on_toggle;
}
$_group->set_active( $self );
$self->set_style_tag( active => 1 );
$_on_toggle->( $self, 1 ) if $_on_toggle;
return 1;
}
=head2 $active = $radiobutton->is_active
Returns true if this button is the active button of the group.
=cut
method is_active
{
return $self->group->active == $self;
}
method reshape
{
my $win = $self->window or return;
my $tick = $self->get_style_values( "tick" );
$win->cursor_at( 0, ( textwidth( $tick )-1 ) / 2 );
}
method render_to_rb
{
my ( $rb, $rect ) = @_;
$rb->clear;
return if $rect->top > 0;
$rb->goto( 0, 0 );
$rb->text( my $tick = $self->get_style_values( "tick" ), $self->get_style_pen( "tick" ) );
$rb->erase( $self->get_style_values( "spacing" ) );
$rb->text( $_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->activate;
}
class Tickit::Widget::RadioButton::Group;
use Scalar::Util qw( weaken refaddr );
=head1 GROUPS
Every C<Tickit::Widget::RadioButton> belongs to a group. Only one button can
be active in a group at any one time. The C<group> accessor returns the group
the button is a member of. The following methods are available on it.
A group can be explicitly created to pass to a button's constructor, or one
will be implicitly created for a button if none is passed.
=cut
=head2 $group = Tickit::Widget::RadioButton::Group->new
Returns a new group.
=cut
has $_active;
has $_on_changed;
=head2 $radiobutton = $group->active
Returns the button which is currently active in the group
=cut
method active { $_active }
method set_active
{
( $_active ) = @_;
$_on_changed->( $self->active, $self->active->value ) if $_on_changed;
}
=head2 $on_changed = $group->on_changed
=cut
method on_changed { $_on_changed }
=head2 $group->set_on_changed( $on_changed )
Return or set the CODE reference to be called when the active member of the
group changes. This may be more convenient than setting the C<on_toggle>
callback of each button in the group.
The callback is passed the currently-active button, and its C<value>.
$on_changed->( $active, $value )
=cut
method set_on_changed
{
( $_on_changed ) = @_;
}
=head1 AUTHOR
( run in 1.843 second using v1.01-cache-2.11-cpan-39bf76dae61 )