shortcut

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package shortcut provides keyboard shortcut management for guigui/ebiten application.

Register every action with Set. The chord on the action is the default. A Store holds the user's replacements: a missing id keeps the default, and the value Unbound clears the chord. Dispatch runs the first matching action. If two actions still share a chord, the earlier one wins.

Index

Constants

View Source
const Unbound = "-"

Unbound is the stored chord text that means "this action has no key".

Variables

This section is empty.

Functions

func Assign

func Assign(store Store, id string, chord Chord)

Assign stores chord for id. Another action that already uses chord becomes unbound. A chord equal to the action default removes the override.

func Dispatch

func Dispatch(store Store) bool

Dispatch runs the first action whose chord was just pressed. It returns true when an action ran.

func Display

func Display(store Store, id string) string

Display is the chord text shown for id. A cleared action is "Not set". Text that does not parse is shown unchanged.

func Reset

func Reset(store Store, id string)

Reset gives id its default chord again. If another action uses that chord, Reset takes it back.

func Set

func Set(actions []Action)

Set replaces the process-wide action list. Call it once at startup. Duplicate ids, empty ids, and two actions with the same default chord panic.

func Unbind

func Unbind(store Store, id string)

Unbind clears the chord for id. The action does not fall back to its default.

Types

type Action

type Action struct {
	ID      string
	Label   string
	Default Chord
	Enabled func() bool
	Run     func()
}

Action is one command the user can bind to a chord.

func Actions

func Actions() []Action

Actions returns the registered actions.

type Chord

type Chord struct {
	Key   ebiten.Key
	Ctrl  bool
	Alt   bool
	Shift bool
	Meta  bool
	// contains filtered or unexported fields
}

Chord is one key plus the modifiers that must be held with it. The zero Chord is not a binding. ebiten.KeyA is numeric zero, so a missing valid flag is what marks an empty chord.

func FromPress

func FromPress(key ebiten.Key, ctrl, alt, shift, meta bool) (Chord, bool)

FromPress builds a chord from a key and the modifiers held with it. Modifier keys themselves are not chords.

func Key

func Key(k ebiten.Key) Chord

Key returns a chord for a single key and no modifiers.

func Parse

func Parse(s string) (Chord, error)

Parse reads a chord such as "O" or "Ctrl+Shift+O". Modifier words are Ctrl/Control, Alt/Option, Shift, and Meta/Cmd/Super. The key is an ebiten key name, case-insensitive. Modifier keys cannot be the key.

func (Chord) String

func (c Chord) String() string

String returns the canonical chord text. An invalid chord is empty.

type Editor

type Editor struct {
	guigui.DefaultWidget
	// contains filtered or unexported fields
}

Editor is a widget for the management of keyboard shortcuts. It lists registered shortcut actions and allows the user to capture new chords.

func (*Editor) Bind

func (e *Editor) Bind(v any)

func (*Editor) Build

func (e *Editor) Build(context *guigui.Context, adder *guigui.ChildAdder) error

func (*Editor) Layout

func (e *Editor) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)

func (*Editor) Measure

func (e *Editor) Measure(context *guigui.Context, constraints guigui.Constraints) image.Point

func (*Editor) WriteStateKey

func (e *Editor) WriteStateKey(context *guigui.Context, w *guigui.StateKeyWriter)

type Store

type Store interface {
	Get(id string) (string, bool)
	Set(id, value string)
}

Store is the user's chord overrides, keyed by action id. Set(id, "") deletes the override. Set(id, Unbound) clears the chord.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL