Skip to content

Bindings

Classes in the Phui\Bindings namespace. A binding pairs an input with a handler, and is returned from a component's bindings().

Binding

final readonly class Phui\Bindings\Binding

php
static keypress(
    Keypress|array|null $keys,
    ?Closure $handler = null,
    array $modifiers = [],
    string $description = '',
    bool $global = false,
): self

Binds one or more Keypress values. $global matches regardless of which component holds focus. $description is the text shown in a Keymap.

php
Binding::keypress(
    Keypress::ENTER,
    fn () => $this->submit(),
    description: 'Submit',
)
php
static focus(
    Keypress|array $keys,
    array $modifiers = [],
    string $description = '',
    bool $global = true,
): self

Binds keys that move focus to the declaring component. Global by default.

php
static paste(Closure $handler): self
static mouseDown(Closure $handler): self
static mouseUp(Closure $handler): self
static scroll(Closure $handler): self

Bind a handler to a paste, mouse-button press, mouse-button release or scroll event.

php
static none(
    Keypress|array|null $keys = null,
    array $modifiers = [],
): self

Removes a binding that a component declared, used from a parent's bindings() override.

php
label(): string

Returns the binding's keys as display text, each prefixed with its modifiers joined by +, and alternatives separated by /.

Keymap

final readonly class Phui\Bindings\Keymap

The bindings a keypress would currently resolve against, returned by $this->keymaps->active().

php
__construct(public array $entries = [])

Creates a keymap from an array of entries.

php
isEmpty(): bool

Returns whether the keymap has no entries.

FrameworkBindings

final class Phui\Bindings\FrameworkBindings

The bindings the framework supplies itself, configured on the Screen.

php
__construct(
    public ?Binding $focusNext = null,
    public ?Binding $focusPrevious = null,
    public ?Binding $toggleDebug = null,
    public ?Binding $quit = null,
)

Creates a set of framework bindings. A null entry keeps the default.

Keypress

enum Phui\Events\Keyboard\Keypress: string

Every key the runtime recognises.

php
label(): string

Returns the case's display text.

php
static fromCharacter(string $char): ?self

Returns the case matching $char, or null when none does.

Cases

GroupCases
ModifiersSHIFT, CTRL, ALT, META, CMD
Lettersa to z, A to Z
DigitsZERO to NINE
NavigationARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, HOME, END, PAGE_UP, PAGE_DOWN
FunctionF1 to F20
EditingENTER, TAB, BACKSPACE, DELETE, INSERT, ESCAPE, SPACE
PunctuationPERIOD, COMMA, SEMICOLON, COLON, SLASH, BACKSLASH, QUOTE, DOUBLE_QUOTE, BACKTICK, TILDE, MINUS, UNDERSCORE, PLUS, EQUALS, PIPE, QUESTION, EXCLAMATION
SymbolsAT, HASH, DOLLAR, PERCENT, CARET, AMPERSAND, ASTERISK, LESS_THAN, GREATER_THAN
BracketsPAREN_LEFT, PAREN_RIGHT, BRACKET_LEFT, BRACKET_RIGHT, BRACE_LEFT, BRACE_RIGHT

Released under the MIT License.