mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
app,io/system: extract system events to separate package
Package app is the only package that depends on native libraries and Cgo. Minimize its API, thereby minimizing Gio clients' dependency on it. In the future, a headless, testing or remote "Window" should be very easy to replace app.Window. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+4
-86
@@ -4,66 +4,14 @@ package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image"
|
||||
"math"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gioui.org/op"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
// A FrameEvent asks for 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 replaces the window's frame with the new
|
||||
// frame.
|
||||
Frame func(frame *op.Ops)
|
||||
// Whether this draw is system generated and needs a complete
|
||||
// frame before proceeding.
|
||||
sync bool
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
type windowRendezvous struct {
|
||||
in chan windowAndOptions
|
||||
out chan windowAndOptions
|
||||
@@ -75,20 +23,6 @@ type windowAndOptions struct {
|
||||
opts *windowOptions
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
const (
|
||||
inchPrDp = 1.0 / 160
|
||||
mmPrDp = 25.4 / 160
|
||||
@@ -109,17 +43,6 @@ const (
|
||||
// Set with the go linker flag -X.
|
||||
var extraArgs string
|
||||
|
||||
func (l Stage) String() string {
|
||||
switch l {
|
||||
case StagePaused:
|
||||
return "StagePaused"
|
||||
case StageRunning:
|
||||
return "StageRunning"
|
||||
default:
|
||||
panic("unexpected Stage value")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
if extraArgs != "" {
|
||||
args := strings.Split(extraArgs, "|")
|
||||
@@ -149,8 +72,8 @@ func Main() {
|
||||
main()
|
||||
}
|
||||
|
||||
// Config implements the layout.Config interface.
|
||||
type Config struct {
|
||||
// config implements the system.Config interface.
|
||||
type config struct {
|
||||
// Device pixels per dp.
|
||||
pxPerDp float32
|
||||
// Device pixels per sp.
|
||||
@@ -158,11 +81,11 @@ type Config struct {
|
||||
now time.Time
|
||||
}
|
||||
|
||||
func (c *Config) Now() time.Time {
|
||||
func (c *config) Now() time.Time {
|
||||
return c.now
|
||||
}
|
||||
|
||||
func (c *Config) Px(v unit.Value) int {
|
||||
func (c *config) Px(v unit.Value) int {
|
||||
var r float32
|
||||
switch v.U {
|
||||
case unit.UnitPx:
|
||||
@@ -202,8 +125,3 @@ func newWindowRendezvous() *windowRendezvous {
|
||||
}()
|
||||
return wr
|
||||
}
|
||||
|
||||
func (_ FrameEvent) ImplementsEvent() {}
|
||||
func (_ StageEvent) ImplementsEvent() {}
|
||||
func (_ *CommandEvent) ImplementsEvent() {}
|
||||
func (_ DestroyEvent) ImplementsEvent() {}
|
||||
|
||||
Reference in New Issue
Block a user