diff options
Diffstat (limited to 'vendor/gioui.org/io/key/key.go')
-rw-r--r-- | vendor/gioui.org/io/key/key.go | 105 |
1 files changed, 85 insertions, 20 deletions
diff --git a/vendor/gioui.org/io/key/key.go b/vendor/gioui.org/io/key/key.go index 5729ae4..b6af2a4 100644 --- a/vendor/gioui.org/io/key/key.go +++ b/vendor/gioui.org/io/key/key.go @@ -10,25 +10,35 @@ events. package key import ( + "fmt" "strings" - "gioui.org/internal/opconst" + "gioui.org/internal/ops" "gioui.org/io/event" "gioui.org/op" ) // InputOp declares a handler ready for key events. // Key events are in general only delivered to the -// focused key handler. Set the Focus flag to request -// the focus. +// focused key handler. type InputOp struct { - Tag event.Tag - Focus bool + Tag event.Tag + Hint InputHint } -// HideInputOp request that any on screen text input -// be hidden. -type HideInputOp struct{} +// SoftKeyboardOp shows or hide the on-screen keyboard, if available. +// It replaces any previous SoftKeyboardOp. +type SoftKeyboardOp struct { + Show bool +} + +// FocusOp sets or clears the keyboard focus. It replaces any previous +// FocusOp in the same frame. +type FocusOp struct { + // Tag is the new focus. The focus is cleared if Tag is nil, or if Tag + // has no InputOp in the same frame. + Tag event.Tag +} // A FocusEvent is generated when a handler gains or loses // focus. @@ -46,6 +56,8 @@ type Event struct { Name string // Modifiers is the set of active modifiers when the key was pressed. Modifiers Modifiers + // State is the state of the key when the event was fired. + State State } // An EditEvent is generated when text is input. @@ -53,6 +65,38 @@ type EditEvent struct { Text string } +// InputHint changes the on-screen-keyboard type. That hints the +// type of data that might be entered by the user. +type InputHint uint8 + +const ( + // HintAny hints that any input is expected. + HintAny InputHint = iota + // HintText hints that text input is expected. It may activate auto-correction and suggestions. + HintText + // HintNumeric hints that numeric input is expected. It may activate shortcuts for 0-9, "." and ",". + HintNumeric + // HintEmail hints that email input is expected. It may activate shortcuts for common email characters, such as "@" and ".com". + HintEmail + // HintURL hints that URL input is expected. It may activate shortcuts for common URL fragments such as "/" and ".com". + HintURL + // HintTelephone hints that telephone number input is expected. It may activate shortcuts for 0-9, "#" and "*". + HintTelephone +) + +// State is the state of a key during an event. +type State uint8 + +const ( + // Press is the state of a pressed key. + Press State = iota + // Release is the state of a key that has been released. + // + // Note: release events are only implemented on the following platforms: + // macOS, Linux, Windows, WebAssembly. + Release +) + // Modifiers type Modifiers uint32 @@ -88,6 +132,7 @@ const ( NamePageUp = "⇞" NamePageDown = "⇟" NameTab = "⇥" + NameSpace = "Space" ) // Contain reports whether m contains all modifiers @@ -97,16 +142,25 @@ func (m Modifiers) Contain(m2 Modifiers) bool { } func (h InputOp) Add(o *op.Ops) { - data := o.Write(opconst.TypeKeyInputLen, h.Tag) - data[0] = byte(opconst.TypeKeyInput) - if h.Focus { + if h.Tag == nil { + panic("Tag must be non-nil") + } + data := ops.Write1(&o.Internal, ops.TypeKeyInputLen, h.Tag) + data[0] = byte(ops.TypeKeyInput) + data[1] = byte(h.Hint) +} + +func (h SoftKeyboardOp) Add(o *op.Ops) { + data := ops.Write(&o.Internal, ops.TypeKeySoftKeyboardLen) + data[0] = byte(ops.TypeKeySoftKeyboard) + if h.Show { data[1] = 1 } } -func (h HideInputOp) Add(o *op.Ops) { - data := o.Write(opconst.TypeHideInputLen) - data[0] = byte(opconst.TypeHideInput) +func (h FocusOp) Add(o *op.Ops) { + data := ops.Write1(&o.Internal, ops.TypeKeyFocusLen, h.Tag) + data[0] = byte(ops.TypeKeyFocus) } func (EditEvent) ImplementsEvent() {} @@ -114,25 +168,36 @@ func (Event) ImplementsEvent() {} func (FocusEvent) ImplementsEvent() {} func (e Event) String() string { - return "{" + string(e.Name) + " " + e.Modifiers.String() + "}" + return fmt.Sprintf("%v %v %v}", e.Name, e.Modifiers, e.State) } func (m Modifiers) String() string { var strs []string if m.Contain(ModCtrl) { - strs = append(strs, "ModCtrl") + strs = append(strs, "Ctrl") } if m.Contain(ModCommand) { - strs = append(strs, "ModCommand") + strs = append(strs, "Command") } if m.Contain(ModShift) { - strs = append(strs, "ModShift") + strs = append(strs, "Shift") } if m.Contain(ModAlt) { - strs = append(strs, "ModAlt") + strs = append(strs, "Alt") } if m.Contain(ModSuper) { - strs = append(strs, "ModSuper") + strs = append(strs, "Super") } return strings.Join(strs, "|") } + +func (s State) String() string { + switch s { + case Press: + return "Press" + case Release: + return "Release" + default: + panic("invalid State") + } +} |