Alt-Tickit-Widgets-ObjectPad
view release on metacpan or search on metacpan
lib/Tickit/Widget/Button.pm view on Meta::CPAN
=cut
=head2 $label = $button->label
=cut
method label { $_label }
=head2 $button->set_label( $label )
Return or set the text to display in the button area.
=cut
method set_label
{
( $_label ) = @_;
$self->redraw;
}
=head2 $on_click = $button->on_click
=cut
method on_click { $_on_click }
=head2 $button->set_on_click( $on_click )
Return or set the CODE reference to be called when the button area is clicked.
$on_click->( $button )
=cut
method set_on_click
{
( $_on_click ) = @_;
}
=head2 $button->click
Behave as if the button has been clicked; running its C<on_click> handler.
This is provided for convenience of activating its handler programmatically
via other parts of code.
=cut
method click
{
$_on_click->( $self );
}
# Activation by key should "flash" the button briefly on the screen as a
# visual feedback
method key_click
{
$self->click;
if( my $window = $self->window ) {
$self->set_style_tag( active => 1 );
$window->tickit->timer( after => 0.1, sub { $self->set_style_tag( active => 0 ) } );
}
return 1;
}
method _activate
{
my ( $active ) = @_;
$self->{active} = $active;
$self->set_style_tag( active => $active );
}
=head2 $align = $button->align
=head2 $button->set_align( $align )
=head2 $valign = $button->valign
=head2 $button->set_valign( $valign )
Accessors for the horizontal and vertical alignment of the label text within
the button area. See also L<Tickit::WidgetRole::Alignable>.
=cut
use Tickit::WidgetRole::Alignable name => "align", style => "h";
use Tickit::WidgetRole::Alignable name => "valign", style => "v";
method reshape
{
my $win = $self->window or return;
my $lines = $win->lines;
my $cols = $win->cols;
my $width = textwidth $self->label;
my $has_border = ( $self->get_style_values( "linetype" ) ) ne "none";
my ( $lines_before, undef, $lines_after ) = $self->_valign_allocation( 1, $lines - (2 * $has_border) );
my ( $cols_before, undef, $cols_after ) = $self->_align_allocation( $width + 2, $cols - 2 );
$self->{label_line} = $lines_before + $has_border;
$self->{label_col} = $cols_before + 2;
$self->{label_end} = $cols_before + $width + 2;
$win->cursor_at( $self->{label_line}, $self->{label_col} );
}
method render_to_rb
{
my ( $rb, $rect ) = @_;
my $win = $self->window or return;
my $lines = $win->lines;
my $cols = $win->cols;
my ( $linetype, $marker_left, $marker_right ) =
$self->get_style_values(qw( linetype marker_left marker_right ));
my $linestyle = $linetype eq "single" ? LINE_SINGLE :
$linetype eq "double" ? LINE_DOUBLE :
( run in 1.389 second using v1.01-cache-2.11-cpan-39bf76dae61 )