app: rename UpdateEvent to FrameEvent and add Frame field

While "DrawEvent" was too specific (op.Ops contains non-draw events),
"Update" is too vague: it's a common word, and could be misunderstood
to mean update parts of a window, not replace it.

"FrameEvent" is more specific, and is the usual way to refer to immediate
mode drawing.

While we're here, unexport Window.Update and add a Frame function to
FrameEvent, to emphasize that updating the window frame is only
appropriate during the handling of a FrameEvent.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-10 12:15:04 +02:00
parent e49df512f6
commit a937a76534
9 changed files with 29 additions and 25 deletions
+11 -8
View File
@@ -10,20 +10,23 @@ import (
"strings" "strings"
"time" "time"
"gioui.org/op"
"gioui.org/unit" "gioui.org/unit"
) )
// An UpdateEvent is generated when a Window's Update // A FrameEvent asks for a new frame in the form of a list of
// method must be called. // operations.
type UpdateEvent struct { type FrameEvent struct {
Config Config Config Config
// Size is the dimensions of the window. // Size is the dimensions of the window.
Size image.Point Size image.Point
// Insets is the insets to apply. // Insets is the insets to apply.
Insets Insets Insets Insets
// Whether this draw is system generated // Frame replaces the window's frame with the new
// and needs a complete frame before // frame.
// proceeding. Frame func(frame *op.Ops)
// Whether this draw is system generated and needs a complete
// frame before proceeding.
sync bool sync bool
} }
@@ -74,7 +77,7 @@ type windowAndOptions struct {
const ( const (
// StagePaused is the Stage for inactive Windows. // StagePaused is the Stage for inactive Windows.
// Inactive Windows don't receive UpdateEvents. // Inactive Windows don't receive FrameEvents.
StagePaused Stage = iota StagePaused Stage = iota
// StateRunning is for active Windows. // StateRunning is for active Windows.
StageRunning StageRunning
@@ -200,7 +203,7 @@ func newWindowRendezvous() *windowRendezvous {
return wr return wr
} }
func (_ UpdateEvent) ImplementsEvent() {} func (_ FrameEvent) ImplementsEvent() {}
func (_ StageEvent) ImplementsEvent() {} func (_ StageEvent) ImplementsEvent() {}
func (_ *CommandEvent) ImplementsEvent() {} func (_ *CommandEvent) ImplementsEvent() {}
func (_ DestroyEvent) ImplementsEvent() {} func (_ DestroyEvent) ImplementsEvent() {}
+3 -3
View File
@@ -13,7 +13,7 @@ is embedded in another project, NewWindow merely connects with a previously
created window. created window.
A Window is run by receiving events from its Events channel. The most A Window is run by receiving events from its Events channel. The most
important event is UpdateEvent that prompts an update of the window important event is FrameEvent that prompts an update of the window
contents and state. contents and state.
For example: For example:
@@ -22,7 +22,7 @@ For example:
w := app.NewWindow() w := app.NewWindow()
for e := range w.Events() { for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok { if e, ok := e.(app.FrameEvent); ok {
ops.Reset() ops.Reset()
// Add operations to ops. // Add operations to ops.
... ...
@@ -60,7 +60,7 @@ For example, to display a blank but otherwise functional window:
Event queue Event queue
A Window's Queue method returns an event.Queue implementation that distributes A Window's Queue method returns an event.Queue implementation that distributes
incoming events to the event handlers declared in the latest call to Update. incoming events to the event handlers declared in the latest frame.
See the gioui.org/ui package for more information about event handlers. See the gioui.org/ui package for more information about event handlers.
*/ */
+1 -1
View File
@@ -296,7 +296,7 @@ func (w *window) draw(sync bool) {
return return
} }
ppdp := float32(w.dpi) * inchPrDp ppdp := float32(w.dpi) * inchPrDp
w.event(UpdateEvent{ w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: int(width), X: int(width),
Y: int(height), Y: int(height),
+1 -1
View File
@@ -80,7 +80,7 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int, to
if sync != 0 { if sync != 0 {
isSync = true isSync = true
} }
w.w.event(UpdateEvent{ w.w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: int(width + .5), X: int(width + .5),
Y: int(height + .5), Y: int(height + .5),
+1 -1
View File
@@ -345,7 +345,7 @@ func (w *window) draw(sync bool) {
w.scale = float32(scale) w.scale = float32(scale)
w.mu.Unlock() w.mu.Unlock()
cfg.now = time.Now() cfg.now = time.Now()
w.w.event(UpdateEvent{ w.w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
+1 -1
View File
@@ -198,7 +198,7 @@ func (w *window) draw(sync bool) {
cfg := configFor(w.ppdp, w.scale) cfg := configFor(w.ppdp, w.scale)
cfg.now = time.Now() cfg.now = time.Now()
w.setStage(StageRunning) w.setStage(StageRunning)
w.w.event(UpdateEvent{ w.w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
+1 -1
View File
@@ -1018,7 +1018,7 @@ func (w *window) draw(sync bool) {
C.gio_wl_callback_add_listener(w.lastFrameCallback, unsafe.Pointer(w.surf)) C.gio_wl_callback_add_listener(w.lastFrameCallback, unsafe.Pointer(w.surf))
} }
cfg.now = time.Now() cfg.now = time.Now()
w.w.event(UpdateEvent{ w.w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
+1 -1
View File
@@ -407,7 +407,7 @@ func (w *window) draw(sync bool) {
w.height = int(r.bottom - r.top) w.height = int(r.bottom - r.top)
cfg := configForDC(w.hdc) cfg := configForDC(w.hdc)
cfg.now = time.Now() cfg.now = time.Now()
w.w.event(UpdateEvent{ w.w.event(FrameEvent{
Size: image.Point{ Size: image.Point{
X: w.width, X: w.width,
Y: w.height, Y: w.height,
+9 -8
View File
@@ -47,7 +47,7 @@ type Window struct {
} }
// 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 call to Update. // to the input handlers declared in the most recent frame.
type Queue struct { type Queue struct {
q input.Router q input.Router
} }
@@ -62,7 +62,7 @@ type driverEvent struct {
// of a Window. // of a Window.
var _ interface { var _ interface {
// setAnimating sets the animation flag. When the window is animating, // setAnimating sets the animation flag. When the window is animating,
// UpdateEvents are delivered as fast as the display can handle them. // FrameEvents are delivered as fast as the display can handle them.
setAnimating(anim bool) setAnimating(anim bool)
// showTextInput updates the virtual keyboard state. // showTextInput updates the virtual keyboard state.
showTextInput(show bool) showTextInput(show bool)
@@ -110,16 +110,16 @@ func (w *Window) Events() <-chan event.Event {
} }
// Queue returns the Window's event queue. The queue contains // Queue returns the Window's event queue. The queue contains
// the events received since the last UpdateEvent. // the events received since the last frame.
func (w *Window) Queue() *Queue { func (w *Window) Queue() *Queue {
return &w.queue return &w.queue
} }
// Update updates the Window. Paint operations updates the // update updates the Window. Paint operations updates the
// window contents, input operations declare input handlers, // window contents, input operations declare input handlers,
// and so on. The supplied operations list completely replaces // and so on. The supplied operations list completely replaces
// the window state from previous calls. // the window state from previous calls.
func (w *Window) Update(frame *op.Ops) { func (w *Window) update(frame *op.Ops) {
w.frames <- frame w.frames <- frame
} }
@@ -153,7 +153,7 @@ func (w *Window) draw(size image.Point, frame *op.Ops) {
w.updateAnimation() w.updateAnimation()
} }
// Invalidate the window such that a UpdateEvent will be generated // Invalidate the window such that a FrameEvent will be generated
// immediately. If the window is inactive, the event is sent when the // immediately. If the window is inactive, the event is sent when the
// window becomes active. // window becomes active.
// Invalidate is safe for concurrent use. // Invalidate is safe for concurrent use.
@@ -253,7 +253,7 @@ func (w *Window) run(opts *windowOptions) {
w.updateAnimation() w.updateAnimation()
w.out <- e w.out <- e
w.waitAck() w.waitAck()
case UpdateEvent: case FrameEvent:
if e2.Size == (image.Point{}) { if e2.Size == (image.Point{}) {
panic(errors.New("internal error: zero-sized Draw")) panic(errors.New("internal error: zero-sized Draw"))
} }
@@ -263,7 +263,8 @@ func (w *Window) run(opts *windowOptions) {
} }
w.drawStart = time.Now() w.drawStart = time.Now()
w.hasNextFrame = false w.hasNextFrame = false
w.out <- e e2.Frame = w.update
w.out <- e2
var frame *op.Ops var frame *op.Ops
// Wait for either a frame or the ack event, // Wait for either a frame or the ack event,
// which meant that the client didn't draw. // which meant that the client didn't draw.