Selkie--Widget--Button

NAME

Selkie::Widget::Button - Focusable clickable button

SYNOPSIS

use Selkie::Widget::Button;
use Selkie::Sizing;

my $ok = Selkie::Widget::Button.new(label => 'OK', sizing => Sizing.fixed(1));
$ok.on-press.tap: -> $ { $app.store.dispatch('form/save') };

DESCRIPTION

Emits on its on-press Supply when the user presses Enter or Space while focused, or when they primary-click anywhere on the button. User activation is debounced by default so duplicate terminal press events from one physical click do not fire the action twice. Highlights visually while focused. The click path also takes focus first (via Selkie::App's click-to-focus), so a mouse-driven press leaves the button in the same state a keyboard press would.

Focusable by default (no need to pass focusable = True>). The label is immutable after construction — build a new button if you need different text.

Debouncing accidental double-clicks

Mouse drivers and the terminal layer occasionally deliver two presses for a single physical click. Buttons default to 120ms of activation debounce. Pass :debounce-ms to tune or disable it:

my $add = Selkie::Widget::Button.new(
    label       => '+ Add row',
    sizing      => Sizing.fixed(14),
    debounce-ms => 200,    # collapse press emits within 200ms
);

Pass debounce-ms = 0> only when every repeated press must emit.

EXAMPLES

A button row

my $row = Selkie::Layout::HBox.new(sizing => Sizing.fixed(1));
my $save = Selkie::Widget::Button.new(label => 'Save',   sizing => Sizing.flex);
my $undo = Selkie::Widget::Button.new(label => 'Undo',   sizing => Sizing.flex);
$row.add($save);
$row.add($undo);

$save.on-press.tap: -> $ { $app.store.dispatch('doc/save') };
$undo.on-press.tap: -> $ { $app.store.dispatch('doc/undo') };

SEE ALSO

has Str $.label

The text shown on the button. Required at construction; use set-label to change afterwards (e.g. for counters).

has UInt $.debounce-ms

Reject press emits that arrive within this many milliseconds of the previous emit. Defaults to 120ms to collapse duplicate terminal press events and repeat-key bursts. Set to 0 to let every press through. Applies uniformly to mouse and keyboard activation paths.

method emit-press

method emit-press() returns Nil

Single chokepoint for emit. Centralises the debounce check so the mouse path and the keyboard path can't drift apart.

method on-press

method on-press() returns Supply

Supply that emits each time the user activates the button (Enter or Space while focused).

method set-label

method set-label(
    Str:D $l
) returns Mu

Replace the displayed label. Marks the widget dirty.

method set-focused

method set-focused(
    Bool $f
) returns Mu

Called by Selkie::App.focus. You don't usually call this yourself.

method is-focused

method is-focused() returns Bool

True if the button currently has focus.

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.