Selkie--Widget--RadioGroup

NAME

Selkie::Widget::RadioGroup - Focusable single-selection list

SYNOPSIS

use Selkie::Widget::RadioGroup;
use Selkie::Sizing;

my $radio = Selkie::Widget::RadioGroup.new(sizing => Sizing.fixed(3));
$radio.set-items(<Small Medium Large>);
$radio.on-change.tap: -> UInt $idx {
    say "Selected: {$radio.selected-label}";
};

DESCRIPTION

A vertical list with (ā—)/( ) indicators showing which option is selected. Cursor navigation (Up/Down) is decoupled from selection — the user can browse without committing. Enter or Space commits the cursor position as the new selection.

Across set-items calls, selection is preserved by label when possible: if the previously-selected label is still in the new list, the selection follows it to its new index. Falls back to index clamp otherwise.

Includes a scrollbar on the right edge if the item count exceeds the viewport height.

EXAMPLES

Sync with store state

$app.store.subscribe-with-callback(
    'sync-density',
    -> $s { ($s.get-in('settings', 'density') // 0).Int },
    -> Int $v { $radio.select-index($v) },  # no-op if unchanged — safe
    $radio,
);
$radio.on-change.tap: -> $v {
    $app.store.dispatch('settings/set', field => 'density', value => $v);
};

SEE ALSO

method items

method items() returns List

The current option labels as a List.

method cursor

method cursor() returns UInt

Index of the cursor (the row Up / Down has navigated to). The cursor and the selection are tracked separately — moving the cursor with arrow keys does not change the selection until the user presses Enter or Space.

method selected

method selected() returns UInt

Index of the currently-selected option. Stable across cursor movement; only changes on commit (Enter / Space / mouse click).

method selected-label

method selected-label() returns Str

Label of the currently-selected option, or the Str type object if there are no items.

method on-change

method on-change() returns Supply

Supply that emits the new selected index whenever the selection changes. Does not fire on cursor-only movement.

method set-items

method set-items(
    @new-items
) returns Mu

Replace the option labels. Preserves the current selection by label if it's still present in the new list (so a re-build of the same options doesn't snap selection back to 0); otherwise clamps to the new bounds. Does not emit on on-change — the selection is considered unchanged from the user's perspective when the same label is still selected. Mark-dirties only.

method select-index

method select-index(
    Int $idx where { ... }
) returns Mu

Commit a new selection. $idx is clamped to the last item; the cursor jumps to match. Emits on on-change only when the selection actually changed (idempotent on no-ops). No-op when the list is empty.

Selkie v0.10.0

High-level TUI framework built on Notcurses

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Notcurses::Native:ver<0.4.0+>:auth<zef:apogee>

Test Dependencies

Provides

  • Selkie
  • Selkie::App
  • Selkie::App::Internal::Dispatch
  • Selkie::App::Internal::ErrorLog
  • Selkie::App::Internal::FocusTree
  • Selkie::App::Internal::HitTest
  • Selkie::App::Internal::IdleBudget
  • Selkie::App::Internal::OverlayTree
  • Selkie::App::Internal::RenderLoop
  • Selkie::App::Internal::ScreenModalLifecycle
  • Selkie::App::Internal::Terminal
  • Selkie::App::Internal::TerminalSequences
  • Selkie::Container
  • Selkie::EffectiveBounds
  • Selkie::Event
  • Selkie::Layout::Allocate
  • Selkie::Layout::HBox
  • Selkie::Layout::Split
  • Selkie::Layout::VBox
  • Selkie::Plot::Palette
  • Selkie::Plot::Scaler
  • Selkie::Plot::Ticks
  • Selkie::ScreenManager
  • Selkie::Sizing
  • Selkie::Store
  • Selkie::Style
  • Selkie::Test::Focus
  • Selkie::Test::Keys
  • Selkie::Test::Snapshot
  • Selkie::Test::Snapshot::Harness
  • Selkie::Test::Store
  • Selkie::Test::Supply
  • Selkie::Test::Tree
  • Selkie::Theme
  • Selkie::Trace
  • Selkie::Tree
  • Selkie::Widget
  • Selkie::Widget::Axis
  • Selkie::Widget::BarChart
  • Selkie::Widget::Border
  • Selkie::Widget::Button
  • Selkie::Widget::CardList
  • Selkie::Widget::Checkbox
  • Selkie::Widget::CommandPalette
  • Selkie::Widget::ConfirmModal
  • Selkie::Widget::FileBrowser
  • Selkie::Widget::FocusableByDefault
  • Selkie::Widget::Heatmap
  • Selkie::Widget::HelpOverlay
  • Selkie::Widget::Histogram
  • Selkie::Widget::Image
  • Selkie::Widget::Legend
  • Selkie::Widget::LineChart
  • Selkie::Widget::ListView
  • Selkie::Widget::Modal
  • Selkie::Widget::MultiLineInput
  • Selkie::Widget::PasswordStrength
  • Selkie::Widget::Plot
  • Selkie::Widget::ProgressBar
  • Selkie::Widget::RadioGroup
  • Selkie::Widget::RichText
  • Selkie::Widget::RichText::Span
  • Selkie::Widget::ScatterPlot
  • Selkie::Widget::ScrollView
  • Selkie::Widget::Select
  • Selkie::Widget::Sparkline
  • Selkie::Widget::Spinner
  • Selkie::Widget::TabBar
  • Selkie::Widget::Table
  • Selkie::Widget::Text
  • Selkie::Widget::TextInput
  • Selkie::Widget::TextInput::HighlightSpan
  • Selkie::Widget::TextStream
  • Selkie::Widget::Toast
  • Selkie::Widget::ViewportedCardList

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.