Tickit...oButton(3pm)

✨ Tickit::Widget::RadioButton ✨

okay bestie, so this is a Perl manual page β€” it lives in the User Contributed Perl Documentation section (that's the 3pm bit, iykyk) and it's literally all about one lil widget. it's called Tickit::Widget::RadioButton and it's giving "pick one from a bunch of options" energy πŸ’…


🌸 NAME 🌸

Tickit::Widget::RadioButton β€” a widget allowing a selection from multiple options πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

use Tickit;
use Tickit::Widget::RadioButton;
use Tickit::Widget::VBox;

my $group = Tickit::Widget::RadioButton::Group->new;

my $vbox = Tickit::Widget::VBox->new;
$vbox->add( Tickit::Widget::RadioButton->new(
      caption => "Radio button $_",
      group   => $group,
) ) for 1 .. 5;

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

πŸ’– DESCRIPTION πŸ’–

so basically this class hands you a widget that lets you select one value out of a group of related options. classic radio button behavior, no cap. it gives you a clickable area plus a visual lil indication of which button in the group is the currently active one πŸ‘‘

and the best part? when you select a new button within a group, the previously-selected one gets unselected automatically. the way it just... handles that for you. iconic. ✨

real talk though β€” this widget is part of an experiment in evolving the design of the Tickit::Style widget integration code, so the details are subject to change. don't get too attached to the specifics, bestie πŸ™ˆ

πŸŽ€ STYLE πŸŽ€

the default style pen is used as the widget pen. also, these style pen prefixes get used:

  • tick => PEN β€” the pen used to render the tick marker βœ…

and these style keys:

  • tick => STRING β€” the text used to indicate the active button
  • spacing => INT β€” number of columns of spacing between the tick mark and the caption text

these style tags:

  • :active β€” set when this button is the active one of the group πŸ‘‘

and these style actions:

  • activate β€” the main action to activate the on_click handler

🌈 CONSTRUCTOR 🌈

new

$radiobutton = Tickit::Widget::RadioButton->new( %args );

constructs a new Tickit::Widget::RadioButton object, slay 🫢

it takes the following named arguments:

  • label => STRING β€” the label text to display alongside this button.
  • group => Tickit::Widget::RadioButton::Group β€” optional. if you supply it, that's the group the button belongs to. if you don't supply it, a brand new group gets constructed, and you can grab it with the group accessor.
  • value => SCALAR β€” optional. if supplied, it sets the button's identification value, which gets passed along to the group's on_changed callback.

🧚 ACCESSORS 🧚

group

$group = $radiobutton->group;

returns the Tickit::Widget::RadioButton::Group this button belongs to πŸ’œ

label

set_label

$label = $radiobutton->label;

$radiobutton->set_label( $label );

returns or sets the label text of the button. get it, set it, live ur truth ✨

on_toggle

$on_toggle = $radiobutton->on_toggle;

set_on_toggle

$radiobutton->set_on_toggle( $on_toggle );

return or set the CODE reference to be called when the button state changes.

$on_toggle->( $radiobutton, $active );
heads up: when the radio tick mark moves from one button to another, the old button is marked unactive before the new one is marked active. order matters, bestie πŸ’€

value

$value = $radiobutton->value;

set_value

$radiobutton->set_value( $value );

return or set the scalar value used to identify the radio button to the group's on_changed callback. this can be any scalar value β€” the button literally just stores it and does nothing else with it. it's giving "not my job, I'm just holding it" πŸ™ˆ


πŸ”₯ METHODS πŸ”₯

activate

$radiobutton->activate;

sets this button as the active member of the group, and deactivates the previous one. main character moment, fr fr πŸ‘‘

is_active

$active = $radiobutton->is_active;

returns true if this button is the active button of the group βœ…


πŸ‘‘ GROUPS πŸ‘‘

every Tickit::Widget::RadioButton belongs to a group. only one button can be active in a group at any one time β€” that's the whole vibe. the group accessor returns the group the button is a member of. and here's what you can do with it ⬇️

a group can be explicitly created and passed to a button's constructor, or one will be implicitly created for a button if you don't pass one. no pressure, it's got you 🫢

new

$group = Tickit::Widget::RadioButton::Group->new;

returns a new group ✨

active

$radiobutton = $group->active;

returns the button which is currently active in the group πŸ‘‘

on_changed

$on_changed = $group->on_changed;

set_on_changed

$group->set_on_changed( $on_changed );

return or set the CODE reference to be called when the active member of the group changes. ngl this may be way more convenient than setting the on_toggle callback of every single button in the group β€” imagine doing all that manually 😭

the callback gets passed the currently-active button, and its value:

$on_changed->( $active, $value );

🌸 AUTHOR 🌸

Paul Evans <leonerd@leonerd.org.uk> πŸ’–


and that's the whole page, bestie!! no cap, you now know everything about Tickit::Widget::RadioButton πŸŽ€ this absolute bop of a doc came from perl v5.40.0, dated 2024-09-16 β€” periodt πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from