| 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build darwin |
| 6 | |
| 7 | // Package appkit provides access to Apple's AppKit API |
| 8 | // (https://developer.apple.com/documentation/appkit). |
| 9 | // |
| 10 | // This package is in very early stages of development. |
| 11 | // It's a minimal implementation with scope limited to |
| 12 | // supporting mtldriver. |
| 13 | // |
| 14 | // It was copied from dmitri.shuralyov.com/gpu/mtl/example/movingtriangle/internal/appkit. |
| 15 | package appkit |
| 16 | |
| 17 | import ( |
| 18 | "unsafe" |
| 19 | |
| 20 | "golang.org/x/exp/shiny/driver/mtldriver/internal/coreanim" |
| 21 | ) |
| 22 | |
| 23 | /* |
| 24 | #include <stdbool.h> |
| 25 | #include "appkit.h" |
| 26 | */ |
| 27 | import "C" |
| 28 | |
| 29 | // Window is a window that an app displays on the screen. |
| 30 | // |
| 31 | // Reference: https://developer.apple.com/documentation/appkit/nswindow. |
| 32 | type Window struct { |
| 33 | window unsafe.Pointer |
| 34 | } |
| 35 | |
| 36 | // NewWindow returns a Window that wraps an existing NSWindow * pointer. |
| 37 | func NewWindow(window unsafe.Pointer) Window { |
| 38 | return Window{window} |
| 39 | } |
| 40 | |
| 41 | // ContentView returns the window's content view, the highest accessible View |
| 42 | // in the window's view hierarchy. |
| 43 | // |
| 44 | // Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview. |
| 45 | func (w Window) ContentView() View { |
| 46 | return View{C.Window_ContentView(w.window)} |
| 47 | } |
| 48 | |
| 49 | // View is the infrastructure for drawing, printing, and handling events in an app. |
| 50 | // |
| 51 | // Reference: https://developer.apple.com/documentation/appkit/nsview. |
| 52 | type View struct { |
| 53 | view unsafe.Pointer |
| 54 | } |
| 55 | |
| 56 | // SetLayer sets v.layer to l. |
| 57 | // |
| 58 | // Reference: https://developer.apple.com/documentation/appkit/nsview/1483298-layer. |
| 59 | func (v View) SetLayer(l coreanim.Layer) { |
| 60 | C.View_SetLayer(v.view, l.Layer()) |
| 61 | } |
| 62 | |
| 63 | // SetWantsLayer sets v.wantsLayer to wantsLayer. |
| 64 | // |
| 65 | // Reference: https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer. |
| 66 | func (v View) SetWantsLayer(wantsLayer bool) { |
| 67 | C.View_SetWantsLayer(v.view, C.bool(wantsLayer)) |
| 68 | } |