app: [API] make ViewEvent an interface on all platforms

A uniform type allows convenient nil checks and for future window
backends on platforms other than Linux (which already had ViewEvent
as an interface).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-12-15 16:52:38 -06:00
parent 5e5d164929
commit f3fc0d62b8
7 changed files with 34 additions and 29 deletions
+5 -4
View File
@@ -93,7 +93,7 @@ import (
"gioui.org/unit"
)
type ViewEvent struct {
type UIKitViewEvent struct {
// ViewController is a CFTypeRef for the UIViewController backing a Window.
ViewController uintptr
}
@@ -139,7 +139,7 @@ func onCreate(view, controller C.CFTypeRef) {
C.gio_viewSetHandle(view, C.uintptr_t(cgo.NewHandle(w)))
w.Configure(wopts.options)
w.ProcessEvent(StageEvent{Stage: StageRunning})
w.ProcessEvent(ViewEvent{ViewController: uintptr(controller)})
w.ProcessEvent(UIKitViewEvent{ViewController: uintptr(controller)})
}
func viewFor(h C.uintptr_t) *window {
@@ -203,7 +203,7 @@ func onStart(h C.uintptr_t) {
//export onDestroy
func onDestroy(h C.uintptr_t) {
w := viewFor(h)
w.ProcessEvent(ViewEvent{})
w.ProcessEvent(UIKitViewEvent{})
w.ProcessEvent(DestroyEvent{})
w.displayLink.Close()
w.displayLink = nil
@@ -398,4 +398,5 @@ func gio_runMain() {
runMain()
}
func (_ ViewEvent) ImplementsEvent() {}
func (UIKitViewEvent) implementsViewEvent() {}
func (UIKitViewEvent) ImplementsEvent() {}