Tickit...Button(3pm)

✨ Tickit::Widget::Button ✨

okay bestie, gather round, because we're talking about Tickit::Widget::Button from the Tickit widget fam πŸ’– this is a whole widget that shows a clickable button. you click it, a callback goes off. that's the vibe. it's giving interactive terminal glamour πŸ’…

(also, lowkey, this page lives in the User Contributed Perl Documentation section of the manual, in case you were wondering where you wandered into 🫢)


🌸 SYNOPSIS 🌸

here's the whole thing in action, no cap:

use Tickit;
use Tickit::Widget::Button;

my $button = Tickit::Widget::Button->new(
   label => "Click Me!",
   on_click => sub {
      my ( $self ) = @_;

      # Do something!
   },
);

Tickit->new( root => $button )->run;

look at her. iconic. the label says hi, the on_click does the thing, and Tickit->new( root => $button )->run sets her loose πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically this class hands you a widget: a clickable area with a label on it. when someone clicks that area, a callback gets invoked. that's the entire plot, and honestly? it ate. πŸ’–


πŸŽ€ STYLE πŸŽ€

the default style pen is used as the widget pen β€” that's just how she shows up to the party. here's what style stuff gets used:

the following style keys are used:

  • linetype => STRING β€” what kind of border to draw around the button, and it has to be one of these four besties:
none single double thick
  • marker_left => STRING β€” a two-character string placed just before the button label 🫢
  • marker_right => STRING β€” a two-character string placed just after the button label πŸ’«

the following style tags are used:

  • :active β€” set when the mouse is being held over the button, before it is released πŸ‘‘

the following style actions are used:

  • click β€” the main action, and the one that activates the on_click handler. periodt.

πŸ’œ CONSTRUCTOR πŸ’œ

new

$button = Tickit::Widget::Button->new( %args );

constructs a brand new Tickit::Widget::Button object. main character entrance, honestly.

takes the following named arguments:

  • label => STR β€” the text to display in the button area ✨
  • on_click => CODE β€” optional! the callback function to invoke when the button is clicked. skip it if you want a button that just... exists. valid.

🌈 ACCESSORS 🌈

label

$label = $button->label;

set_label

$button->set_label( $label );

return or set the text to display in the button area. that's it, that's the whole job πŸ’…

on_click

$on_click = $button->on_click;

set_on_click

$button->set_on_click( $on_click );

return or set the CODE reference that gets called when the button area is clicked:

$on_click->( $button );

note the $button gets passed in, iykyk 🎁

click

$button->click;

behaves as if the button has been clicked, running its on_click handler. it's here for convenience, so other parts of your code can activate that handler programmatically. fake it till you make it, but make it correct ✨

align

set_align

valign

set_valign

$align = $button->align;

$button->set_align( $align );

$valign = $button->valign;

$button->set_valign( $valign );

accessors for the horizontal and vertical alignment of the label text inside the button area. and if you want the full lore, go see Tickit::WidgetRole::Alignable πŸ¦‹


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk> β€” thank you for the gift, we are obsessed 🫢


cute lil sign-off: this page is Tickit...Button(3pm) from the User Contributed Perl Documentation, and it's tagging along with perl v5.40.0, dated 2024-09-16. stay clickable bestie πŸ’–βœ¨
πŸ“¦ where this page comes from