mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
ui/input: support single stepping through events
Change input.Events interface to return one event at a time until the queue is empty. Change text.Editor and gestures to match. Re-add Editor.Submit while we're here; we don't want to enable submit mode always. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+12
-4
@@ -83,8 +83,12 @@ func (c *Click) Add(ops *ui.Ops) {
|
|||||||
|
|
||||||
func (c *Click) Update(q input.Events) []ClickEvent {
|
func (c *Click) Update(q input.Events) []ClickEvent {
|
||||||
var events []ClickEvent
|
var events []ClickEvent
|
||||||
for _, e := range q.For(c) {
|
for {
|
||||||
e, ok := e.(pointer.Event)
|
evt, ok := q.Next(c)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
e, ok := evt.(pointer.Event)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -135,8 +139,12 @@ func (s *Scroll) Update(cfg *ui.Config, q input.Events, axis Axis) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
total := 0
|
total := 0
|
||||||
for _, e := range q.For(s) {
|
for {
|
||||||
e, ok := e.(pointer.Event)
|
evt, ok := q.Next(s)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
e, ok := evt.(pointer.Event)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ package input
|
|||||||
// Events maps an event handler key to the events
|
// Events maps an event handler key to the events
|
||||||
// available to the handler.
|
// available to the handler.
|
||||||
type Events interface {
|
type Events interface {
|
||||||
For(k Key) []Event
|
Next(k Key) (Event, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key is the stable identifier for an event handler. For a handler h, the
|
// Key is the stable identifier for an event handler. For a handler h, the
|
||||||
|
|||||||
+8
-2
@@ -19,8 +19,14 @@ type Queue struct {
|
|||||||
|
|
||||||
type handlerEvents map[Key][]Event
|
type handlerEvents map[Key][]Event
|
||||||
|
|
||||||
func (q *Queue) For(k Key) []Event {
|
func (q *Queue) Next(k Key) (Event, bool) {
|
||||||
return q.handlers[k]
|
events := q.handlers[k]
|
||||||
|
if len(events) == 0 {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
e := events[0]
|
||||||
|
q.handlers[k] = events[1:]
|
||||||
|
return e, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queue) Frame(ops *ui.Ops) {
|
func (q *Queue) Frame(ops *ui.Ops) {
|
||||||
|
|||||||
+7
-2
@@ -25,6 +25,7 @@ type Editor struct {
|
|||||||
Face Face
|
Face Face
|
||||||
Alignment Alignment
|
Alignment Alignment
|
||||||
SingleLine bool
|
SingleLine bool
|
||||||
|
Submit bool
|
||||||
|
|
||||||
oldCfg ui.Config
|
oldCfg ui.Config
|
||||||
blinkStart time.Time
|
blinkStart time.Time
|
||||||
@@ -103,7 +104,11 @@ func (e *Editor) Next() (EditorEvent, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stop := (sdist > 0 && soff >= smax) || (sdist < 0 && soff <= smin)
|
stop := (sdist > 0 && soff >= smax) || (sdist < 0 && soff <= smin)
|
||||||
for _, ke := range e.Inputs.For(e) {
|
for {
|
||||||
|
ke, ok := e.Inputs.Next(e)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
e.blinkStart = e.Config.Now
|
e.blinkStart = e.Config.Now
|
||||||
switch ke := ke.(type) {
|
switch ke := ke.(type) {
|
||||||
case key.Focus:
|
case key.Focus:
|
||||||
@@ -112,7 +117,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
|
|||||||
if !e.focused {
|
if !e.focused {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if ke.Name == key.NameReturn || ke.Name == key.NameEnter {
|
if e.Submit && (ke.Name == key.NameReturn || ke.Name == key.NameEnter) {
|
||||||
if !ke.Modifiers.Contain(key.ModShift) {
|
if !ke.Modifiers.Contain(key.ModShift) {
|
||||||
return Submit{}, true
|
return Submit{}, true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user