-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
132 lines (103 loc) · 3.49 KB
/
window.go
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
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// based on golang.org/x/mobile/event:
//
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package window defines events associated with windows -- including changes
// in the dimensions, physical resolution and orientation of the app's window,
// and iconify, open and close events.
package window
import (
"fmt"
"image"
"github.com/goki/gi/oswin"
"github.com/goki/ki/kit"
)
// window.Event reports on actions taken on a window. The oswin.Window Flags
// and other state information will always be updated prior to this event
// being sent, so those should be consulted directly for the new current
// state.
type Event struct {
oswin.EventBase
// Action taken on the window -- what has changed. Window state fields
// have current values.
Action Actions
}
// Actions is the action taken on the window by the user.
type Actions int32
const (
// Close means that the window is about to close, but has not yet closed.
Close Actions = iota
// Minimize means that the window has been iconified / miniaturized / is no
// longer visible.
Minimize
// Resize means that the window was resized, including changes in DPI
// associated with moving to a new screen. Position may have also changed
// too. Requires a redraw.
Resize
// Move means that the window was moved but NOT resized or changed in any
// other way -- does not require a redraw, but anything tracking positions
// will want to update.
Move
// Focus indicates that the window has been activated for receiving user
// input.
Focus
// DeFocus indicates that the window is no longer activated for
// receiving input.
DeFocus
// Paint indicates a request to repaint the window.
Paint
// Show is for the WindowShow event
Show
// ScreenUpdate occurs when any of the screen information is updated
// This event is sent to the first window on the list of active windows
// and it should then perform any necessary updating
ScreenUpdate
ActionsN
)
//go:generate stringer -type=Actions
var KiT_Actions = kit.Enums.AddEnum(ActionsN, kit.NotBitFlag, nil)
/////////////////////////////
// oswin.Event interface
func (ev *Event) Type() oswin.EventType {
if ev.Action == Resize {
return oswin.WindowResizeEvent
} else if ev.Action == Paint {
return oswin.WindowPaintEvent
} else {
return oswin.WindowEvent
}
}
func (ev *Event) HasPos() bool {
return false
}
func (ev *Event) Pos() image.Point {
return image.ZP
}
func (ev *Event) OnFocus() bool {
return false
}
func (ev *Event) String() string {
return fmt.Sprintf("Type: %v Action: %v Time: %v", ev.Type(), ev.Action, ev.Time())
}
// window.ShowEvent is for synthetic window show event that is sent to widget consumers
// sent only once when window is first created.
// all other window events go from OS to window consumer but are not forwarded.
type ShowEvent struct {
Event
}
func (ev *ShowEvent) Type() oswin.EventType {
return oswin.WindowShowEvent
}
// window.FocusEvent is for synthetic window focus event that is sent to widget consumers
// sent when user focus on window changes (action is Focus or DeFocus)
// all other window events go from OS to window consumer but are not forwarded.
type FocusEvent struct {
Event
}
func (ev *FocusEvent) Type() oswin.EventType {
return oswin.WindowFocusEvent
}