~eliasnaur/gio

ref: 173d56a67a600ec89568789f86f450e8f1f442b8 gio/ui/app/app.go -rw-r--r-- 2.3 KiB
173d56a6Elias Naur ui/app: (ios) relay system focus events 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: Unlicense OR MIT

package app

import (
	"image"
	"os"
	"strings"

	"gioui.org/ui"
)

type Event interface {
	ImplementsEvent()
}

type Draw struct {
	Config *ui.Config
	Size   image.Point
	// Whether this draw is system generated
	// and needs to a complete frame before
	// proceeding.
	sync bool
}

type ChangeStage struct {
	Stage Stage
}

// Command is a system event.
type Command struct {
	Type CommandType
	// Suppress the default action of the command.
	Cancel bool
}

type Stage uint8
type CommandType uint8

type Input interface {
	ImplementsInput()
}

const (
	StageDead Stage = iota
	StagePaused
	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
	// monitorScale is the extra scale applied to
	// monitor outputs to compensate for the extra
	// viewing distance compared to phone and tables.
	monitorScale = 1.50
	// minDensity is the minimum pixels per dp to
	// ensure font and ui legibility on low-dpi
	// screens.
	minDensity = 1.25
)

// extraArgs contains extra arguments to append to
// os.Args. The arguments are separated with |.
// Useful for running programs on mobiles where the
// command line is not available.
// Set it with the go tool linker flag -X.
var extraArgs string

var windows = make(chan *Window)

// CreateWindow creates a new window for a set of window
// options. The options are hints; the platform is free to
// ignore or adjust them.
// CreateWindow is not supported on iOS and Android.
func CreateWindow(opts *WindowOptions) error {
	if opts == nil {
		opts = &WindowOptions{
			Width:  ui.Dp(800),
			Height: ui.Dp(600),
			Title:  "Gio program",
		}
	}
	if opts.Width.V <= 0 || opts.Height.V <= 0 {
		panic("window width and height must be larger than 0")
	}
	return createWindow(opts)
}

func Windows() <-chan *Window {
	return windows
}

func (l Stage) String() string {
	switch l {
	case StageDead:
		return "StageDead"
	case StagePaused:
		return "StagePaused"
	case StageRunning:
		return "StageRunning"
	default:
		panic("unexpected Stage value")
	}
}

func (_ Draw) ImplementsEvent()        {}
func (_ ChangeStage) ImplementsEvent() {}
func (_ *Command) ImplementsEvent()    {}

func init() {
	args := strings.Split(extraArgs, "|")
	os.Args = append(os.Args, args...)
}