io/input: [API] introduce Source, the interface between a Router and widgets

This change gets rid of the event.Queue interface by replacing it with
input.Source values. Source provides the interface to Router necessary
to implement interface widgets.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-08 17:56:03 -05:00
parent c319f3c214
commit 6027517949
31 changed files with 106 additions and 127 deletions
+5 -19
View File
@@ -5,7 +5,7 @@ package layout
import (
"time"
"gioui.org/io/event"
"gioui.org/io/input"
"gioui.org/io/system"
"gioui.org/op"
"gioui.org/unit"
@@ -20,9 +20,6 @@ type Context struct {
Constraints Constraints
Metric unit.Metric
// By convention, a nil Source is a signal to widgets to draw themselves
// in a disabled state.
Source event.Queue
// Now is the animation time.
Now time.Time
@@ -31,6 +28,7 @@ type Context struct {
// Interested users must look up and populate these values manually.
Locale system.Locale
input.Source
*op.Ops
}
@@ -44,21 +42,9 @@ func (c Context) Sp(v unit.Sp) int {
return c.Metric.Sp(v)
}
// Events returns the events available for the key. If no
// queue is configured, Events returns nil.
func (c Context) Events(k event.Tag) []event.Event {
if c.Source == nil {
return nil
}
return c.Source.Events(k)
}
// Disabled returns a copy of this context with a nil Queue,
// blocking events to widgets using it.
//
// By convention, a nil Queue is a signal to widgets to draw themselves
// in a disabled state.
// Disabled returns a copy of this context with a disabled Source,
// blocking widgets from changing its state and receiving events.
func (c Context) Disabled() Context {
c.Source = nil
c.Source = input.Source{}
return c
}
+1 -1
View File
@@ -144,7 +144,7 @@ func (l *List) Dragging() bool {
}
func (l *List) update(gtx Context) {
d := l.scroll.Update(gtx.Metric, gtx, gtx.Now, gesture.Axis(l.Axis))
d := l.scroll.Update(gtx.Metric, gtx.Source, gtx.Now, gesture.Axis(l.Axis))
l.scrollDelta = d
l.Position.Offset += d
}
+1 -1
View File
@@ -70,7 +70,7 @@ func TestListPosition(t *testing.T) {
Constraints: Constraints{
Max: image.Pt(20, 10),
},
Source: r,
Source: r.Source(),
}
el := func(gtx Context, idx int) Dimensions {
return Dimensions{Size: image.Pt(10, 10)}