Alt-Tickit-Widgets-ObjectPad

 view release on metacpan or  search on metacpan

lib/Tickit/Widget/RadioButton.pm  view on Meta::CPAN


method value { $_value }

=head2 $radiobutton->set_value( $value )

Return or set the scalar value used to identify the radio button to the
group's C<on_changed> callback. This can be any scalar value; it is simply
stored by the button and not otherwise used.

=cut

method set_value
{
   $_value = $_[0];
}

=head1 METHODS

=cut

=head2 $radiobutton->activate

Sets this button as the active member of the group, deactivating the previous
one.

=cut

*key_activate = \&activate;
method activate
{
   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



( run in 0.494 second using v1.01-cache-2.11-cpan-39bf76dae61 )