From 8d9612f9aa462cb5ef571518694a3def64bc9e50 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 3 May 2020 20:48:35 +0200 Subject: [PATCH] layout,app,io/system: move Queue from app.Window to FrameEvent Change gioui.org/commit/0e70fbc1262920a69c60409285795b6bb8701b09 added a note that app.Window.Queue must only be used during the processing of a FrameEvent. The change was added because a Gio user took the existence of app.Window.Queue to mean it was always available. This change reduces the scope of window Queues by moving it from Window to FrameEvent, and minimizes the risk of misuse by not offering Window.Queue at all. Note that the gioui.org/commit/a937a7653439333b8c6fc30c7a6039b717339766 change moved Window's Frame method (named Update) to FrameEvent for the same reason. Signed-off-by: Elias Naur --- app/window.go | 19 +++++-------------- io/system/system.go | 9 ++++++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app/window.go b/app/window.go index 3c0e1702..4af06280 100644 --- a/app/window.go +++ b/app/window.go @@ -44,7 +44,7 @@ type Window struct { nextFrame time.Time delayedDraw *time.Timer - queue Queue + queue queue callbacks callbacks } @@ -53,9 +53,9 @@ type callbacks struct { w *Window } -// Queue is an event.Queue implementation that distributes system events +// queue is an event.Queue implementation that distributes system events // to the input handlers declared in the most recent frame. -type Queue struct { +type queue struct { q router.Router } @@ -107,16 +107,6 @@ func (w *Window) Events() <-chan event.Event { return w.out } -// Queue returns the Window's event queue. The queue contains the events -// received since the last frame. -// -// Note: the Queue may only be used after receiving a FrameEvent and before the -// next event is received, or the FrameEvent.Frame method is called, whichever -// comes first. -func (w *Window) Queue() *Queue { - return &w.queue -} - // update updates the Window. Paint operations updates the // window contents, input operations declare input handlers, // and so on. The supplied operations list completely replaces @@ -274,6 +264,7 @@ func (w *Window) run(opts *window.Options) { frameStart := time.Now() w.hasNextFrame = false e2.Frame = w.update + e2.Queue = &w.queue w.out <- e2.FrameEvent if w.loop != nil { if e2.Sync { @@ -353,7 +344,7 @@ func (w *Window) run(opts *window.Options) { } } -func (q *Queue) Events(k event.Key) []event.Event { +func (q *queue) Events(k event.Key) []event.Event { return q.q.Events(k) } diff --git a/io/system/system.go b/io/system/system.go index fe672653..52cf45fe 100644 --- a/io/system/system.go +++ b/io/system/system.go @@ -8,11 +8,12 @@ import ( "image" "time" + "gioui.org/io/event" "gioui.org/op" "gioui.org/unit" ) -// A FrameEvent asks for a new frame in the form of a list of +// A FrameEvent requests a new frame in the form of a list of // operations. type FrameEvent struct { Config Config @@ -20,9 +21,11 @@ type FrameEvent struct { Size image.Point // Insets is the insets to apply. Insets Insets - // Frame replaces the window's frame with the new - // frame. + // Frame is the callback to supply the list of + // operations to complete the FrameEvent. Frame func(frame *op.Ops) + // Queue supplies the events for event handlers. + Queue event.Queue } // Config defines the essential properties of