ui/shortcut.go

43 lines
795 B
Go
Raw Permalink Normal View History

2024-03-30 17:45:07 +01:00
package ui
import "fyne.io/fyne/v2"
// Shortcut represents a shortcut composed of a modifier + key combination
// Implements: fyne.Shortcut
type Shortcut struct {
key fyne.KeyName
modifier fyne.KeyModifier
name string
}
// Create a new shortcut
func NewShortcut(
name string,
key fyne.KeyName,
modifier ...fyne.KeyModifier,
) *Shortcut {
sc := &Shortcut{
key: key,
name: name,
}
for _, mod := range modifier {
sc.modifier |= mod
}
return sc
}
// Key returns the shortcut key
func (s *Shortcut) Key() fyne.KeyName {
return s.key
}
// Mod returns the shortcut modifier combination
func (s *Shortcut) Mod() fyne.KeyModifier {
return s.modifier
}
// ShortcutName returs the modifier shortcut combination
func (s *Shortcut) ShortcutName() string {
return s.name
}