Files
gio/io/system/system.go
T
Elias Naur 8d9612f9aa 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 <mail@eliasnaur.com>
2020-05-03 21:04:52 +02:00

103 lines
2.2 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
// Package system contains events usually handled at the top-level
// program level.
package system
import (
"image"
"time"
"gioui.org/io/event"
"gioui.org/op"
"gioui.org/unit"
)
// A FrameEvent requests a new frame in the form of a list of
// operations.
type FrameEvent struct {
Config Config
// Size is the dimensions of the window.
Size image.Point
// Insets is the insets to apply.
Insets Insets
// 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
// the environment.
type Config interface {
// Now returns the current animation time.
Now() time.Time
unit.Converter
}
// DestroyEvent is the last event sent through
// a window event channel.
type DestroyEvent struct {
// Err is nil for normal window closures. If a
// window is prematurely closed, Err is the cause.
Err error
}
// Insets is the space taken up by
// system decoration such as translucent
// system bars and software keyboards.
type Insets struct {
Top, Bottom, Left, Right unit.Value
}
// A StageEvent is generated whenever the stage of a
// Window changes.
type StageEvent struct {
Stage Stage
}
// CommandEvent is a system event.
type CommandEvent struct {
Type CommandType
// Suppress the default action of the command.
Cancel bool
}
// Stage of a Window.
type Stage uint8
// CommandType is the type of a CommandEvent.
type CommandType uint8
const (
// StagePaused is the Stage for inactive Windows.
// Inactive Windows don't receive FrameEvents.
StagePaused Stage = iota
// StateRunning is for active Windows.
StageRunning
)
const (
// CommandBack is the command for a back action
// such as the Android back button.
CommandBack CommandType = iota
)
func (l Stage) String() string {
switch l {
case StagePaused:
return "StagePaused"
case StageRunning:
return "StageRunning"
default:
panic("unexpected Stage value")
}
}
func (FrameEvent) ImplementsEvent() {}
func (StageEvent) ImplementsEvent() {}
func (*CommandEvent) ImplementsEvent() {}
func (DestroyEvent) ImplementsEvent() {}