Documentation
¶
Overview ¶
Package apple holds what the AppKit and UIKit backends share, called through purego without cgo: CoreFoundation strings, CoreGraphics colors and canvases, layer styles and transitions, the CoreText text engine, which prepares and lays text out on the engine goroutine for the main thread to draw, and image views, which load and decode off it.
Index ¶
- Variables
- func AnimateIn(layer objc.ID, a driver.ModalAnimation, distance float64, reduceMotion bool)
- func AppleSignInAvailable() bool
- func BackdropFilters(filters []driver.Filter) objc.ID
- func BundleName(lang string) string
- func Bytes(data objc.ID) []byte
- func CFString(s string) uintptr
- func CGColor(c driver.Color) uintptr
- func CallBlock(block objc.ID, args ...uintptr) uintptr
- func Class(name string) objc.Class
- func ClipHolder(layer objc.ID, vs *driver.ViewStyle, scrolls bool)
- func CloseNotification(id string)
- func CommonModes() objc.ID
- func ContentTypes(r driver.FilesRequest) objc.ID
- func DrawTopDown(ctx uintptr, height float64, flip bool, draw func(baseUp bool))
- func EdgeBlur(s driver.Side, d driver.EdgeEffect) objc.ID
- func Encode(data []byte, maxPixels int, jpeg bool, quality float32) ([]byte, driver.Size, error)
- func FadeImage(s driver.Side) uintptr
- func FillRects(ctx uintptr, rects []CGRect, color uintptr)
- func FitBackdrop(backdrop objc.ID, vs *driver.ViewStyle, w, h float64)
- func FollowBounds(layer objc.ID)
- func Font(f driver.Font) uintptr
- func ForEach(collection objc.ID, fn func(objc.ID))
- func ForgetBorders(layer objc.ID)
- func ForgetDecor(layer objc.ID)
- func ForgetHolder(layer objc.ID)
- func ForgetTransform(layer objc.ID)
- func GaussianBackdrop(radius float64) objc.ID
- func Global(path, name string) objc.ID
- func GoJSON(o objc.ID) any
- func GoString(ns objc.ID) string
- func HandleAppleSignIn(it *driver.MountItem, anchor objc.ID, dispatch func(driver.Event))
- func HandleAuthSession(id uint32, r driver.AuthRequest, anchor func() objc.ID, ...)
- func HandleBiometric(it *driver.MountItem, dispatch func(driver.Event))
- func HandlePurchase(it *driver.MountItem, dispatch func(driver.Event))
- func HandleSpeak(id uint32, r driver.SpeakRequest, dispatch func(driver.Event))
- func HandleSpeech(id uint32, r driver.SpeechRequest, dispatch func(driver.Event))
- func HeldTransformMethods() []objc.MethodDef
- func HolderMask(layer objc.ID) objc.ID
- func ImageInfo(it *driver.MountItem, dispatch func(driver.Event))
- func ImageSize(image uintptr) (width, height int)
- func JSONObject(v any) objc.ID
- func KeyEvent(kind, flags uint, timestamp float64, window int, chars, ignoring string, ...) objc.ID
- func KeyNames(name string, flags uint) []string
- func LayoutBorders(layer objc.ID)
- func LayoutDecor(layer objc.ID)
- func Locale() (tag string, rtl bool)
- func LocaleSettings() driver.LocaleSettings
- func MediaTime() time.Duration
- func Modifiers(flags uint) driver.Modifiers
- func Msg(id objc.ID, sel objc.SEL, args ...uintptr) uintptr
- func MsgBool(id objc.ID, sel objc.SEL, args ...uintptr) bool
- func NSData(b []byte) objc.ID
- func NSString(s string) objc.ID
- func NeedsClipHolder(vs *driver.ViewStyle) bool
- func NotificationPermission(ask bool, answer func(int))
- func NotificationsAvailable() bool
- func NotificationsUsed() bool
- func Observe(center, name objc.ID, fn func(note objc.ID)) (stop func())
- func OnMain(fn func())
- func PNG(data []byte) ([]byte, driver.Size, error)
- func PNGImage(image uintptr) ([]byte, error)
- func PinLanguage(lang string)
- func Play(ctx uintptr, ops []driver.DrawOp, host CanvasHost)
- func PlayOver(ctx uintptr, ops []driver.DrawOp, split driver.CanvasSplit, host CanvasHost)
- func PointerMatrix(layer objc.ID) driver.Matrix3D
- func PreparePicked(r driver.PickRequest, f driver.PickedFile) driver.PickedFile
- func ProcessMemory() (uint64, bool)
- func PurchasesAvailable() bool
- func RaiseThread()
- func RasterStep(scale float32) float64
- func RegisterClass(name string, super objc.Class, protocols []*objc.Protocol, ...) objc.Class
- func RegisterFont(data []byte) error
- func RegisterFonts(paths []string)
- func Release(ref uintptr)
- func RestyleLayer(layer objc.ID, shown, vs *driver.ViewStyle, view objc.ID)
- func RotateLayer(layer objc.ID, radians float64)
- func SaveType(name string) objc.ID
- func Sel(name string) objc.SEL
- func SendSuper[T any](self objc.ID, cmd objc.SEL, args ...any) T
- func SendSuperPoint(self objc.ID, cmd objc.SEL, p CGPoint) objc.ID
- func SetCenterBadge(count uint32) bool
- func SetNotificationPress(press func(id string))
- func SetPurchaseUpdates(fn func(driver.Event))
- func SetSublayerTranslation(layer objc.ID, dx, dy float64)
- func SetTransform(layer objc.ID, t driver.Transform)
- func SetWebCookies(id uint32, r driver.WebCookiesRequest, dispatch func(driver.Event))
- func ShapedCorners(vs *driver.ViewStyle) bool
- func ShowNotification(n driver.Notification, answer func(bool))
- func SpeakAvailable() bool
- func SpeechAvailable() bool
- func StyleLayer(layer objc.ID, was, vs *driver.ViewStyle, view objc.ID)
- func Subviews(view objc.ID) []objc.ID
- func Super(self objc.ID, cmd objc.SEL, args ...any)
- func Tint(ctx uintptr, r CGRect, c driver.Color)
- func TranslateCTM(ctx uintptr, x, y float64)
- func UTType() objc.ID
- func UsesFilters(vs *driver.ViewStyle) bool
- func WatchNotifications()
- func WithoutAnimation(fn func())
- func YieldFrame()
- func Z(order float64) float64
- type CGPoint
- type CGRect
- type CGSize
- type CanvasHost
- type CanvasLayer
- type GPUProbe
- type ImageView
- type Keychain
- type Layout
- func (l *Layout) Attachment(i int) (driver.Bounds, bool)
- func (l *Layout) CaretRect(c driver.Caret) (driver.Bounds, bool)
- func (l *Layout) ContentFrame(w, h float64, box CGRect) CGRect
- func (l *Layout) Draw(ctx uintptr, viewHeight float64, box CGRect, baseUp bool)
- func (l *Layout) DrawBackgrounds(ctx uintptr, at CGRect)
- func (l *Layout) HitTest(p driver.Point) driver.Caret
- func (l *Layout) IndexAt(p CGPoint, box CGRect) int
- func (l *Layout) OffsetAt(p CGPoint, box CGRect) int
- func (l *Layout) RangeRects(start, end int, out []driver.Bounds) []driver.Bounds
- func (l *Layout) Release()
- func (l *Layout) SelectionRects(start, end int, box CGRect) []CGRect
- func (l *Layout) TextLines() []driver.TextLine
- type NSRange
- type Picture
- type ScrollEdge
- type Sensors
- type ShaderLayer
- type TextEngine
- type Video
- type Web
Constants ¶
This section is empty.
Variables ¶
var HoldTransforms func(layer objc.ID)
HoldTransforms, when a backend sets it, gives layer the class of HeldTransformMethods as SetTransform first holds a transform for it. Only layers that hold one take that class: AppKit sets each layer's transform as it places its view, and the override's call into Go cost every frame change a few microseconds.
Functions ¶
func AnimateIn ¶
AnimateIn presents a modal's layer as a asks: sliding up from distance points below, or fading in. Reduced motion fades instead of sliding.
func AppleSignInAvailable ¶ added in v0.2.0
func AppleSignInAvailable() bool
AppleSignInAvailable is Environment.SignInWithApple: every macOS, iOS and tvOS NSGo runs on has AuthenticationServices, which loads only once a request starts.
func BackdropFilters ¶ added in v0.2.0
BackdropFilters returns a CABackdropLayer's filters for filters: their widest blur, then their color filters as one matrix, the order Windows draws them in; 0 when they change nothing. CAFilter's colorMatrix reads the matrix as a CAColorMatrix under inputColorMatrix and ignores Core Image's inputRVector keys. Drop shadows are left out, as CSS's backdrop-filter has no shadow to draw. The array is autoreleased.
func BundleName ¶
BundleName returns the app's name in lang as its bundle's InfoPlist.strings says it, in the localization that suits lang best; "" when the bundle names it in none.
func CallBlock ¶
CallBlock calls a block another language made, such as a Swift closure Objective-C passed NSGo, with up to six object, pointer or integer arguments, and returns its result's register. purego's Block.Invoke calls only the blocks it made.
func ClipHolder ¶ added in v0.2.0
ClipHolder clips layer, the layer of the view holding a view's children, to the box and corners of vs, the view's style; nil or a style that does not clip leaves the children unclipped, or clipped to the holder's bounds for a scroll view's container (scrolls), as NSClipView clips. Corners of different radii take a shape mask, laid over the bounds as they are now, so a holder whose bounds scroll takes none (ShapedCorners). A mask an effect set in its place, hiding the children, stays until the effect puts back HolderMask. A holder that is not a scroll view's container also takes the view's perspective (ChildPerspective), clipping or not, which would otherwise stop at the holder.
func CloseNotification ¶
func CloseNotification(id string)
CloseNotification removes the notification called id, shown or still to show, and every one the app's notification center holds when id is empty, those earlier runs left included. A macOS app that never used notifications has none to close, and closing leaves its center untouched, as an app clearing them each time it comes to the front would otherwise make its Dock badge wait for the user to allow badges.
func CommonModes ¶
CommonModes returns NSRunLoopCommonModes. Run loop sources compare modes by identity, so an equal string of another object is a mode of its own that never runs.
func ContentTypes ¶
func ContentTypes(r driver.FilesRequest) objc.ID
ContentTypes returns the UTTypes of the files r offers, for NSOpenPanel and UIDocumentPickerViewController: every file, as public.data, when r names none or one the system has no type for.
func DrawTopDown ¶
DrawTopDown runs draw with ctx's state saved and its y axis pointing down over a layer height tall; flip turns a y-up context, which Core Animation gives a layer whose contents are not flipped, top down. Core Graphics offsets shadows in the context's base space, which points down when Core Animation flipped the context and up when flip did: draw learns which as baseUp.
func EdgeBlur ¶
EdgeBlur returns a CABackdropLayer's filters for effect d at side s: a blur growing toward a soft side, or an even one.
func Encode ¶
Encode decodes data upright, scales it so its longer side has at most maxPixels (0: its size) and encodes it as a PNG, or as a JPEG of quality when jpeg. It returns the bytes and their size in pixels.
func FadeImage ¶
FadeImage returns a new CGImage of a soft edge's fade at side s, 64 pixels along the band and 1 across: opaque at the side, clear at the other end, for a variable blur to stretch over its band as its mask. The caller releases it.
func FitBackdrop ¶
FitBackdrop lays backdrop, the blur of a view of style vs and size w by h, under the rim, on the view's curve: inside the border by whole points, as a blur on a fraction of a point lands between pixels, the fill closing the seam.
func FollowBounds ¶
FollowBounds keeps a layer's decoration on its box after its bounds origin moved, as a scroll view's does when it scrolls.
func Font ¶
Font returns a CTFont (an NSFont or UIFont) for f: the system face unless f names a family. The caller releases it.
Fonts are immutable and few, so they are built once and handed out again by reference. Building one is seven CoreText calls through purego; a frame of a table asks for the same font forty times.
func ForgetBorders ¶
ForgetBorders forgets the borders of a layer that is going away.
func ForgetDecor ¶
ForgetDecor forgets the decoration of a layer that is going away.
func ForgetHolder ¶ added in v0.2.0
ForgetHolder releases what ClipHolder made for a holder going away.
func ForgetTransform ¶
ForgetTransform forgets the transform SetTransform gave a layer that is going away.
func GaussianBackdrop ¶ added in v0.2.0
GaussianBackdrop returns a CABackdropLayer's filters for an even blur of radius points, the standard deviation as CSS's blur() has it: hard scroll edges and macOS's backdrop blurs. The array is autoreleased.
func Global ¶
Global reads the global object, such as an NSString constant, that framework at path exports as name; 0 when it has none.
func GoJSON ¶
GoJSON returns Foundation's object o as Go's decoded JSON: maps, slices, strings, float64, bool or nil.
func HandleAppleSignIn ¶ added in v0.2.0
HandleAppleSignIn carries out an ItemSignInWithApple, its sheet shown over anchor, the window of the surface that asked, or an ItemAppleCredentialState, on the main thread, answering through dispatch.
func HandleAuthSession ¶ added in v0.2.0
func HandleAuthSession(id uint32, r driver.AuthRequest, anchor func() objc.ID, dispatch func(driver.Event))
HandleAuthSession carries out r for auth session id on the main thread: a start checks the session can catch the redirect and reports it, an open shows the URL over the window anchor returns, and a cancel ends it. dispatch runs on any goroutine.
func HandleBiometric ¶
HandleBiometric carries out a biometric request on the main thread and dispatches its answer to the engine.
func HandlePurchase ¶ added in v0.2.0
HandlePurchase carries out an ItemPurchase, answering through dispatch.
func HandleSpeak ¶ added in v0.2.0
func HandleSpeak(id uint32, r driver.SpeakRequest, dispatch func(driver.Event))
HandleSpeak carries out an ItemSpeak of utterance or request id, on the main thread, reporting EventSpeak through dispatch.
func HandleSpeech ¶
func HandleSpeech(id uint32, r driver.SpeechRequest, dispatch func(driver.Event))
HandleSpeech carries out an ItemSpeech for session id, on the main thread, reporting EventSpeech through dispatch.
func HeldTransformMethods ¶
HeldTransformMethods are the methods of a CALayer subclass that keeps the transform SetTransform gave it: AppKit sets its views' layers back to its own transform whenever it syncs their geometry.
func HolderMask ¶ added in v0.2.0
HolderMask is the mask ClipHolder keeps on layer, 0 for none: what an effect that hid the holder's children puts back.
func ImageInfo ¶
ImageInfo answers an ItemImageInfo on a goroutine of its own: it loads the source, keeping its bytes for the views that show it next, and dispatches EventImageInfo with the size ImageIO reads, upright, or an SVG's in whole points.
func JSONObject ¶
JSONObject returns v as Foundation's objects, autoreleased, or 0 for nil or a value JSON cannot encode.
func KeyEvent ¶ added in v0.2.0
func KeyEvent(kind, flags uint, timestamp float64, window int, chars, ignoring string, repeat bool, code uint16) objc.ID
KeyEvent makes an AppKit key event of kind (NSEventTypeKeyDown or NSEventTypeKeyUp) for window, typing chars and ignoring without modifiers. AppKit must be loaded.
isARepeat and keyCode are the selector's last arguments and go on the stack, past the integer registers. Apple's arm64 ABI packs them by their natural size into one word, isARepeat in its low byte and keyCode from its third, which purego, giving each variadic argument a word of its own, would not; the x86-64 ABI gives each its own word, as purego does.
func KeyNames ¶
KeyNames returns the names core.NormalizeKey gives a key press: the key named name with the modifier flags AppKit and UIKit share, first with Command as "mod", then as "meta".
func LayoutBorders ¶
LayoutBorders fits a layer's per-side borders to its bounds after its frame changed.
func LayoutDecor ¶
LayoutDecor fits a layer's decoration to its bounds after its frame changed.
func Locale ¶
Locale returns the user's locale as a BCP 47 tag, and whether their first preferred language is written right to left.
NSLocale says the languages the process launched with, which a language PinLanguage kept replaces until the next launch; the user's languages are read from their defaults instead, so following them again takes effect at once. A language the user chose for the app in System Settings stays theirs.
func LocaleSettings ¶
func LocaleSettings() driver.LocaleSettings
LocaleSettings returns the regional preferences the user set in Language & Region: the first day of the week (NSCalendar's), the hours of NSDateFormatter's format for the j template, which 24-hour time changes, and NSLocale's measurement system.
func MediaTime ¶
MediaTime returns Core Animation's clock: the time since the system started, on which display links and NSEvent timestamps count too.
func Msg ¶
Msg sends sel to id with up to six arguments and a result that are objects, selectors, pointers, integers or booleans, through purego.SyscallN. objc.Send and ID.Send work each call out with reflection, which costs several times the message itself; what runs for every changed view of every frame sends with Msg.
func NeedsClipHolder ¶ added in v0.2.0
NeedsClipHolder reports whether a view that clips also draws outside its box: an outer shadow, a React Native shadow or an outline. Core Animation clips those with the children when a layer sets masksToBounds or a mask, so the backends clip such a view's children in a holder view of their own and leave the styled layer unclipped, as CSS keeps a box's own shadows and outline outside its overflow clip.
func NotificationPermission ¶
NotificationPermission answers with whether the app may show notifications (driver.NotificationsNotAsked, ...), asking the user first when ask is set and the user was not asked yet. answer runs on any goroutine.
func NotificationsAvailable ¶ added in v0.2.0
func NotificationsAvailable() bool
NotificationsAvailable reports whether the process has a notification center, which also shows the notifications it schedules after the process ends: Environment.ScheduledNotifications. It leaves the center untouched, as the environment is read before the app uses notifications.
func NotificationsUsed ¶ added in v0.2.0
func NotificationsUsed() bool
NotificationsUsed reports whether the app checked or asked for the notification permission or showed a notification, in this run or an earlier one, without touching the center: a bundled macOS app whose process touched it has its Dock badge shown only while the user allows its badges.
func Observe ¶
Observe calls fn on the main thread each time center posts name, until stop is called.
func OnMain ¶
func OnMain(fn func())
OnMain runs fn on the main thread after what is queued there already. It never waits, so any goroutine may call it.
func PNGImage ¶ added in v0.2.0
PNGImage encodes an already composited CGImage as a PNG. The caller keeps ownership of image; this function does not retain or release it.
func PinLanguage ¶
func PinLanguage(lang string)
PinLanguage keeps lang, the language the app forces, for what the system says in the app from its next launch: the bundle's name in the menu bar, the items it adds to menus, its panels and its controls' words, which follow the languages of the launch and not the app's. "" lets them follow the user's languages again, unless the user chose the app's language in System Settings since. A pseudo locale has no localization of the system's, and pins nothing; neither does a process outside a bundle.
func Play ¶
func Play(ctx uintptr, ops []driver.DrawOp, host CanvasHost)
Play draws ops into ctx, a view's context with its y axis pointing down, as a web canvas would: CoreGraphics adds path points through the transform current when they are added, as the canvas does, and a fill, stroke or clip keeps the path.
func PlayOver ¶
func PlayOver(ctx uintptr, ops []driver.DrawOp, split driver.CanvasSplit, host CanvasHost)
PlayOver plays ops as Play does, but over their static part drawn already (a CanvasLayer): the ops before split.At that split skips set only the state.
func PointerMatrix ¶ added in v0.2.0
PointerMatrix returns the transform currently drawn by layer, around its top left. Presentation values include style transitions and additive keyframes, which a view's layout coordinates do not know.
func PreparePicked ¶
func PreparePicked(r driver.PickRequest, f driver.PickedFile) driver.PickedFile
PreparePicked returns f as r asks for it: its type and size as it shows filled in, encoded again as PNG or JPEG when r needs it.
func ProcessMemory ¶
ProcessMemory returns the process' physical footprint in bytes: the dirty and compressed memory it owns, what Activity Monitor shows and what the system judges it by under memory pressure (unlike the resident size, it leaves out the frameworks' clean pages every process maps).
func PurchasesAvailable ¶ added in v0.2.0
func PurchasesAvailable() bool
PurchasesAvailable is Environment.Purchases: whether the bundle has the library, which loads on macOS 12, iOS 15 and tvOS 15 and later. Loading it starts listening to Transaction.updates, as StoreKit asks apps to from their launch.
func RaiseThread ¶
func RaiseThread()
RaiseThread gives the calling OS thread the main thread's quality of service, as NSH gives its engine thread. The engine's thread turns input into frames; at the default class the system may run it on efficiency cores, and the quotes benchmark's commits took about 15% longer and varied with the machine's load.
func RasterStep ¶
RasterStep is how many times its pixels a layer scaled by scale draws its content at: 1 up to its own size, then in steps of a half up to 4, so its text and drawings stay sharp while a zoom redraws them only as it passes a step.
func RegisterClass ¶
func RegisterClass(name string, super objc.Class, protocols []*objc.Protocol, methods []objc.MethodDef) objc.Class
RegisterClass registers an Objective-C class whose methods may call SendSuper.
func RegisterFont ¶
RegisterFont registers font file data with CoreText for the process, as the app runs: text prepared from then on finds its families.
func RegisterFonts ¶
func RegisterFonts(paths []string)
RegisterFonts registers the app's font files, paths under its resources, with CoreText for the process, so text finds them by their families. Call it before the first view.
func RestyleLayer ¶
RestyleLayer draws vs with a layer that shows shown, the style StyleLayer last drew there; with none it draws vs at once. When the two differ only in opacity and transform, as an animation's frames do, it sets just those: drawing every property again remade its colors, shadow, filters and gradients each frame, and the window server drew them all again.
func RotateLayer ¶
RotateLayer turns layer by radians around its anchor point.
func SaveType ¶
SaveType returns the UTType of a file named name, for a save dialog to keep its extension, or 0 for a name without one.
func SendSuper ¶
SendSuper sends cmd to the superclass of the NSGo class self is an instance of, whatever subclass the runtime gave self since.
func SendSuperPoint ¶
SendSuperPoint is SendSuper for a method that takes one point and returns an object, as hitTest: does. SendSuper registers a function and works the point's layout out with reflection at every call, several times what the method costs, and a hit test calls it for every view under the pointer. This sends through one function registered once, with the point as the two doubles every 64-bit Apple target passes it as.
func SetCenterBadge ¶
SetCenterBadge sets the badge through the center, as iOS 16 and later do, and reports whether it could.
func SetNotificationPress ¶
func SetNotificationPress(press func(id string))
SetNotificationPress sends the presses of notifications to press, those heard before it first.
func SetPurchaseUpdates ¶ added in v0.2.0
SetPurchaseUpdates has fn hear the transactions the store updates outside a purchase, as EventPurchaseUpdate, those it delivered before first.
func SetSublayerTranslation ¶
SetSublayerTranslation moves layer's sublayers by (dx, dy) points, as a scroll view shows an offset its bounds do not have yet.
func SetTransform ¶
SetTransform sets a layer's transform to t around its transform origin: its center, moved by its style's Origin.
func SetWebCookies ¶ added in v0.2.0
func SetWebCookies(id uint32, r driver.WebCookiesRequest, dispatch func(driver.Event))
SetWebCookies carries out an ItemWebCookies: it sets each cookie in WKWebsiteDataStore's default store, whose WKHTTPCookieStore every web view but an Incognito one reads, and answers once WebKit has taken them all. The store exists without a web view, and WebKit writes it to disk, so a cookie with an expiry outlives the app. A target without WebKit, tvOS, has no store.
func ShapedCorners ¶ added in v0.2.0
ShapedCorners reports whether vs's rounded corners differ in radius, which a layer's own corner radius cannot draw and a shape mask does.
func ShowNotification ¶
func ShowNotification(n driver.Notification, answer func(bool))
ShowNotification shows n, or schedules it for its At, replacing a notification of its ID, delivered or pending, and answers with whether the center took it: not without the permission. answer runs on any goroutine.
func SpeakAvailable ¶ added in v0.2.0
func SpeakAvailable() bool
SpeakAvailable is Environment.Speak: every macOS, iOS and tvOS NSGo runs on has AVSpeechSynthesizer, which loads only once the app speaks.
func SpeechAvailable ¶
func SpeechAvailable() bool
SpeechAvailable is Environment.Speech: every macOS and iOS NSGo runs on has the Speech framework, which loads only once a session starts.
func StyleLayer ¶
StyleLayer draws vs with a view's CALayer. An NSView whose layer it is takes the layer's shadow, as AppKit copies a view's shadow onto its layer. A style with a transition animates what it lists from the values shown; was is the style last drawn, nil for none.
func Tint ¶
Tint paints c over what ctx holds in r, where it holds anything: a text's bound color over all of its glyphs.
func TranslateCTM ¶
TranslateCTM moves ctx's origin by x, y.
func UsesFilters ¶
UsesFilters reports whether vs gives its layer Core Image filters.
func WatchNotifications ¶
func WatchNotifications()
WatchNotifications makes NSGo the center's delegate; calling it again changes nothing. Call it as the app starts, before it finishes launching, so the press that launched it is heard; macOS calls it then only for an app that used notifications before (NotificationsUsed), so one that only sets a Dock badge never touches the center.
func WithoutAnimation ¶
func WithoutAnimation(fn func())
WithoutAnimation runs fn with Core Animation's implicit animations off, so layers a backend adds itself change at once.
func YieldFrame ¶
func YieldFrame()
YieldFrame passes the main goroutine through Go's scheduler. A frame clock calls it once a tick, on the main thread, which is enough for frames up to yieldWithin apart; between slower ones, a 60 Hz display's or a slowed animation's, a timer yields every yieldEvery until frames come that close again or stop.
Types ¶
type CGPoint ¶
type CGPoint struct {
X, Y float64
// contains filtered or unexported fields
}
CGPoint, CGSize and CGRect match CoreGraphics' layouts on 64-bit Apple platforms.
type CGRect ¶
func Damaged ¶
Damaged is the area of a canvas to draw again after its animated arguments played before now play after (driver.CanvasDamage), 2 points wider for anti-aliasing and rounded out to whole points; whole is set where only drawing all of it is right. An empty area draws nothing.
func KeptContent ¶
KeptContent returns the frame for the content layer of a text, laid at laid, whose content needs need (ContentFrame): laid grown to hold need while that is no more than four times need's area, else need. Core Animation makes a new backing store for each new size of a layer, and a number changing every frame changes its width with it.
type CGSize ¶
type CGSize struct {
Width, Height float64
// contains filtered or unexported fields
}
type CanvasHost ¶
CanvasHost is the view a drawing plays in: the screen's pixels a point, what draws it again once an image it waits for loads, which Owner names so it waits once, and whether the context's base space points up (DrawTopDown).
type CanvasLayer ¶
type CanvasLayer struct {
// Drawing, Width and Height (in pixels) are what it was made for.
Drawing *driver.Drawing
Width, Height int
// contains filtered or unexported fields
}
CanvasLayer is what a drawing's static part (driver.CanvasSplit) paints, rasterized once into a CGLayer made for the contexts it is drawn into, as NSH's macOS Prefix: a frame then draws the layer and plays only the painting after it (PlayOver).
func NewCanvasLayer ¶
func NewCanvasLayer(ctx uintptr, d *driver.Drawing, ops []driver.DrawOp, split driver.CanvasSplit, w, h, scale float64, host CanvasHost) *CanvasLayer
NewCanvasLayer rasterizes what ops paint before split.At into a layer made for ctx, w × h points at scale pixels each. It reports nil when an image the part draws has not loaded yet, which the layer would miss.
func (*CanvasLayer) Draw ¶
func (l *CanvasLayer) Draw(ctx uintptr, w, h float64)
Draw draws the layer over ctx's top-down w × h points.
func (*CanvasLayer) Release ¶
func (l *CanvasLayer) Release()
Release lets the layer go; l may be nil.
type GPUProbe ¶
type GPUProbe struct {
// contains filtered or unexported fields
}
GPUProbe reads the process' GPU use from the accumulatedGPUTime its accelerator clients report in the IO registry, the counter behind Activity Monitor's GPU column.
func NewGPUProbe ¶
func NewGPUProbe() *GPUProbe
NewGPUProbe returns a probe, or nil when the machine has no accelerator.
type ImageView ¶
type ImageView struct {
// Dispatch reports an event to the engine if the view listens for it.
Dispatch func(driver.Event)
// contains filtered or unexported fields
}
ImageView shows an image view's source, and its placeholder until the source arrives, in a picture layer framed at the fitted rectangle inside a clipping layer it adds to the view's own, as NSH's does (the tint and its mask inside the picture). It loads them with imageload and decodes them with ImageIO on goroutines, at the size the view shows them. Its methods run on the main thread.
func NewDrawnImage ¶
func NewDrawnImage(changed func()) *ImageView
NewDrawnImage is an ImageView with no layer, for a backend that draws it itself (Draw): changed runs on the main thread each time what it shows changes.
func NewImageView ¶
NewImageView adds an image layer to host, a view's layer.
func (*ImageView) Close ¶
func (iv *ImageView) Close()
Close stops loading and lets the image go; the view is being deleted.
func (*ImageView) Configure ¶
func (iv *ImageView) Configure(c *driver.ImageConfig)
Configure sets the view's source and look. Start loads what changed.
func (*ImageView) Draw ¶
Draw draws a drawn image's picture into ctx, a context of the view's box with its y axis down: fitted, clipped to the view's corners, and filled with the tint through its alpha where the style tints it.
func (*ImageView) Layout ¶
Layout fits the image to the view's new size, decoding the source again when the view outgrows the size it was decoded at.
type Keychain ¶ added in v0.2.0
type Keychain struct{}
Keychain keeps an app's secrets as generic passwords of the keychain through Security.framework, in the process, as the item's access control trusts the binary that wrote it: kSecClassGenericPassword with the item's kSecAttrService and kSecAttrAccount, labeled with the service, as MyGo's App.Secrets and keytar keep them, so an app keeps reading what they wrote.
macOS keeps them in the login keychain, which needs no entitlement; an AccessGroup takes them to the data protection keychain instead, which needs a signed app with the keychain-access-groups entitlement (unsigned builds get errSecMissingEntitlement), and only there does Accessible apply. iOS, tvOS and watchOS have only the data protection keychain.
func (Keychain) DeleteSecret ¶ added in v0.2.0
func (Keychain) DeleteSecret(item driver.SecretItem) (err error)
func (Keychain) ReadSecret ¶ added in v0.2.0
func (Keychain) WriteSecret ¶ added in v0.2.0
func (Keychain) WriteSecret(item driver.SecretItem, value string) (err error)
type Layout ¶
type Layout struct {
// contains filtered or unexported fields
}
Layout is text CoreText laid out on the engine goroutine, drawn on the main thread.
func (*Layout) Attachment ¶
Attachment implements core.AttachmentLayout.
func (*Layout) ContentFrame ¶
ContentFrame is the frame of the layer a text view of size w by h draws l into, its text in box: the view's bounds, grown to hold the decoration lines, backgrounds and shadow that reach past them, as a browser draws a text's ink outside its box. It is in whole points.
func (*Layout) Draw ¶
Draw draws l in box of a flipped context of a view viewHeight tall, whose base space points up when baseUp is set (DrawTopDown).
func (*Layout) DrawBackgrounds ¶
DrawBackgrounds fills the backgrounds of l's spans in box of a flipped context, behind the selection and the glyphs.
func (*Layout) IndexAt ¶
IndexAt returns the UTF-8 byte offset of the character at p, a point of the view Draw drew l in at box, or -1 when no character is there.
func (*Layout) OffsetAt ¶
OffsetAt returns the UTF-16 offset of the caret nearest p, a point of the view Draw drew l in at box: on the line nearest p, before the line's break.
func (*Layout) RangeRects ¶
RangeRects implements driver.TextHitTester.
func (*Layout) SelectionRects ¶
SelectionRects returns the boxes of the UTF-16 range from start to end in the view Draw draws l in at box: per line, a box per run of adjacent characters. A range that goes on past a line covers the rest of it.
type NSRange ¶
type NSRange struct {
Location, Length uint
// contains filtered or unexported fields
}
NSRange is Foundation's range of UTF-16 units.
type Picture ¶
type Picture struct {
// contains filtered or unexported fields
}
Picture is what a shader effect or transition reads of views: a layer tree drawn with renderInContext: into a bitmap it keeps, made again only when its size changes, and the Metal texture the bitmap goes into. renderInContext: draws no Metal layer, video, web page, backdrop blur or glass.
func (*Picture) Release ¶
func (p *Picture) Release()
Release lets the picture's bitmap and texture go.
type ScrollEdge ¶
ScrollEdge is what macOS and iOS draw of a scroll edge effect over their blur, alike: the tint of the background the content scrolls over and a hard edge's hairline. Its layers are in the band's own space; the platform puts them over its blur.
func (*ScrollEdge) Paint ¶
func (p *ScrollEdge) Paint(e *driver.ScrollEdge, s driver.Side, w, h float64)
Paint lays the layers out for edge e at side s, in a band of w by h points, y growing down.
type Sensors ¶ added in v0.2.0
type Sensors struct {
// contains filtered or unexported fields
}
Sensors owns a surface's providers, on the main thread. Core Motion's handlers only copy samples into bounded packets; app code runs in core.
type ShaderLayer ¶
type ShaderLayer struct {
// Layer is the CAMetalLayer.
Layer objc.ID
// Ready is called when the program compiled after Set, to draw.
Ready func()
// contains filtered or unexported fields
}
ShaderLayer draws a shader view with Metal: a CAMetalLayer the view's layer holds below its children, drawn when the uniforms, the size or the animated lanes change, never on a timer of its own. Metal loads with the first shader, and each program compiles once for the process on a goroutine of its own, as Metal takes a tenth of a second for a library; the layer draws once it is ready.
The main thread only writes the uniforms (Draw); a render goroutine of the layer's own waits for a drawable, encodes and presents. Waiting for a drawable blocks until the display frees one, a whole refresh when frames come faster, so the main thread must never wait for it.
func NewShaderLayer ¶
func NewShaderLayer(scale float64) *ShaderLayer
NewShaderLayer returns a shader view's layer at scale pixels a point, or nil where the machine has no Metal device: the view stays empty.
func (*ShaderLayer) Draw ¶
func (l *ShaderLayer) Draw(animated func(lanes []float64))
Draw has the render goroutine draw the shader with its uniforms, animated writing the lanes animated nodes drive over them. It never waits.
func (*ShaderLayer) Drawable ¶
func (l *ShaderLayer) Drawable() bool
Drawable reports whether the layer has a program ready to draw.
func (*ShaderLayer) Release ¶
func (l *ShaderLayer) Release()
Release lets the layer go, with the view holding it, once its render goroutine finished the frame it draws.
func (*ShaderLayer) Resize ¶
func (l *ShaderLayer) Resize(w, h, scale float64)
Resize sizes the layer's drawable for w by h points at scale.
func (*ShaderLayer) Set ¶
func (l *ShaderLayer) Set(sh *driver.Shader)
Set gives the layer what it draws, compiling its program the first time a view shows it.
func (*ShaderLayer) SetPictures ¶
func (l *ShaderLayer) SetPictures(p [4]*Picture)
SetPictures gives a WGSL program the pictures it reads; a nil one, or one not taken yet, reads as transparent.
type TextEngine ¶
type TextEngine struct{}
TextEngine implements core.TextEngine with CoreText. Strikethrough and span backgrounds, which CoreText has no attributes for, are drawn from the lines' offsets; attachments' placeholders are sized by run delegates.
func (TextEngine) Prepare ¶
func (TextEngine) Prepare(t *driver.AttributedText) driver.PreparedText
Prepare implements core.TextEngine. It is safe off the main thread.
type Video ¶
type Video struct {
// Dispatch reports the video's events.
Dispatch func(driver.Event)
// Parent is the view controller an iOS player's controls join when
// the view is not in one yet.
Parent objc.ID
// contains filtered or unexported fields
}
Video is a video's AVPlayer, filling the view that holds it: in an AVPlayerLayer, or with the platform's controls in an AVPlayerView (macOS) or an AVPlayerViewController (iOS). AVFoundation and AVKit load on the first video, so apps without one do not pay for them. The layer is not opaque, so HEVC with alpha shows what is behind it; a local WebM file with alpha, which AVFoundation cannot open, reports EventError saying so.
func (*Video) Close ¶
func (v *Video) Close()
Close stops the player. The view keeps the last frame while it still shows.
func (*Video) Configure ¶
func (v *Video) Configure(c *driver.VideoConfig)
Configure applies c, opening the source again when it changed.
type Web ¶
type Web struct {
// Dispatch reports the web view's events.
Dispatch func(driver.Event)
// contains filtered or unexported fields
}
Web is a web view's WKWebView, filling the view that holds it. WebKit loads on the first web view, so apps without one do not pay for it. The WKWebView is made on the first Configure.
func (*Web) Command ¶
func (w *Web) Command(c driver.WebCommand, value string, data any)
Command does c, with value for messages and scripts.
Source Files
¶
- apple.go
- applesignin.go
- audiosession_other.go
- authsession.go
- biometric.go
- border.go
- cache.go
- canvas.go
- canvaslayer.go
- clip.go
- decor.go
- edge.go
- encode.go
- files.go
- fonts.go
- http.go
- image.go
- inline.go
- json.go
- keyevent_macos.go
- layer.go
- memory.go
- names.go
- notifications.go
- perf.go
- picture.go
- purchases.go
- secrets.go
- sensors.go
- shader.go
- speak.go
- speak_macos.go
- speech.go
- speech_macos.go
- super.go
- system.go
- text.go
- timezone.go
- video.go
- videoplay.go
- web.go
- webcookie.go
- yield.go