apple

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for darwin/amd64

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

Constants

This section is empty.

Variables

View Source
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

func AnimateIn(layer objc.ID, a driver.ModalAnimation, distance float64, reduceMotion bool)

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 BundleName

func BundleName(lang string) string

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 Bytes

func Bytes(data objc.ID) []byte

Bytes copies the bytes of an NSData.

func CFString

func CFString(s string) uintptr

CFString returns a new CFString (an NSString) holding s. The caller releases it.

func CGColor

func CGColor(c driver.Color) uintptr

CGColor returns a new CGColor of c. The caller releases it.

func CallBlock

func CallBlock(block objc.ID, args ...uintptr) uintptr

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 Class

func Class(name string) objc.Class

Class returns the class named name, or 0 while none is loaded.

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.

func CommonModes

func CommonModes() objc.ID

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

func DrawTopDown(ctx uintptr, height float64, flip bool, draw func(baseUp bool))

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

func EdgeBlur(s driver.Side, d driver.EdgeEffect) objc.ID

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

func Encode(data []byte, maxPixels int, jpeg bool, quality float32) ([]byte, driver.Size, error)

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

func FadeImage(s driver.Side) uintptr

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 FillRects

func FillRects(ctx uintptr, rects []CGRect, color uintptr)

FillRects fills rects with color, a CGColor.

func FitBackdrop

func FitBackdrop(backdrop objc.ID, vs *driver.ViewStyle, w, h float64)

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

func FollowBounds(layer objc.ID)

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

func Font(f driver.Font) uintptr

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 ForEach

func ForEach(collection objc.ID, fn func(objc.ID))

ForEach calls fn with each object of an NSArray or NSSet.

func ForgetBorders

func ForgetBorders(layer objc.ID)

ForgetBorders forgets the borders of a layer that is going away.

func ForgetDecor

func ForgetDecor(layer objc.ID)

ForgetDecor forgets the decoration of a layer that is going away.

func ForgetTransform

func ForgetTransform(layer objc.ID)

ForgetTransform forgets the transform SetTransform gave a layer that is going away.

func Global

func Global(path, name string) objc.ID

Global reads the global object, such as an NSString constant, that framework at path exports as name; 0 when it has none.

func GoJSON

func GoJSON(o objc.ID) any

GoJSON returns Foundation's object o as Go's decoded JSON: maps, slices, strings, float64, bool or nil.

func GoString

func GoString(ns objc.ID) string

GoString returns the Go string of an NSString.

func HandleBiometric

func HandleBiometric(it *driver.MountItem, dispatch func(driver.Event))

HandleBiometric carries out a biometric request on the main thread and dispatches its answer to the engine.

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

func HeldTransformMethods() []objc.MethodDef

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 ImageInfo

func ImageInfo(it *driver.MountItem, dispatch func(driver.Event))

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

func JSONObject(v any) objc.ID

JSONObject returns v as Foundation's objects, autoreleased, or 0 for nil or a value JSON cannot encode.

func KeyNames

func KeyNames(name string, flags uint) []string

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

func LayoutBorders(layer objc.ID)

LayoutBorders fits a layer's per-side borders to its bounds after its frame changed.

func LayoutDecor

func LayoutDecor(layer objc.ID)

LayoutDecor fits a layer's decoration to its bounds after its frame changed.

func Locale

func Locale() (tag string, rtl bool)

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

func MediaTime() time.Duration

MediaTime returns Core Animation's clock: the time since the system started, on which display links and NSEvent timestamps count too.

func Modifiers

func Modifiers(flags uint) driver.Modifiers

Modifiers returns the modifier keys among the flags AppKit and UIKit share.

func Msg

func Msg(id objc.ID, sel objc.SEL, args ...uintptr) uintptr

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 MsgBool

func MsgBool(id objc.ID, sel objc.SEL, args ...uintptr) bool

MsgBool is Msg for a BOOL result.

func NSData

func NSData(b []byte) objc.ID

NSData returns an autoreleased NSData holding a copy of b.

func NSString

func NSString(s string) objc.ID

NSString returns an autoreleased NSString holding s.

func NotificationPermission

func NotificationPermission(ask bool, answer func(int))

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 Observe

func Observe(center, name objc.ID, fn func(note objc.ID)) (stop func())

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 PNG

func PNG(data []byte) ([]byte, driver.Size, error)

PNG returns data as a PNG and its size in pixels: itself when it is one.

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 PreparePicked

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

func ProcessMemory() (uint64, bool)

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 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

func RasterStep(scale float32) float64

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

func RegisterFont(data []byte) error

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 Release

func Release(ref uintptr)

Release calls CFRelease on a CoreFoundation object.

func RestyleLayer

func RestyleLayer(layer objc.ID, shown, vs *driver.ViewStyle, view objc.ID)

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

func RotateLayer(layer objc.ID, radians float64)

RotateLayer turns layer by radians around its anchor point.

func SaveType

func SaveType(name string) objc.ID

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 Sel

func Sel(name string) objc.SEL

Sel returns the selector named name.

func SendSuper

func SendSuper[T any](self objc.ID, cmd objc.SEL, args ...any) T

SendSuper sends cmd to the superclass of the NSGo class self is an instance of, whatever subclass the runtime gave self since.

func SendSuperPoint

func SendSuperPoint(self objc.ID, cmd objc.SEL, p CGPoint) objc.ID

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

func SetCenterBadge(count uint32) bool

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 SetSublayerTranslation

func SetSublayerTranslation(layer objc.ID, dx, dy float64)

SetSublayerTranslation moves layer's sublayers by (dx, dy) points, as a scroll view shows an offset its bounds do not have yet.

func SetTransform

func SetTransform(layer objc.ID, t driver.Transform)

SetTransform sets a layer's transform to t around its transform origin: its center, moved by its style's Origin.

func ShowNotification

func ShowNotification(n driver.Notification, answer func(bool))

ShowNotification shows n, replacing a notification of its ID, and answers with whether the center took it: not without the permission. answer runs on any goroutine.

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

func StyleLayer(layer objc.ID, was, vs *driver.ViewStyle, view objc.ID)

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 Subviews

func Subviews(view objc.ID) []objc.ID

Subviews returns a view's subviews, back to front.

func Super

func Super(self objc.ID, cmd objc.SEL, args ...any)

Super sends cmd to self's NSGo superclass, discarding the result.

func Tint

func Tint(ctx uintptr, r CGRect, c driver.Color)

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

func TranslateCTM(ctx uintptr, x, y float64)

TranslateCTM moves ctx's origin by x, y.

func UTType

func UTType() objc.ID

UTType is the UTType class, its framework loaded.

func UsesFilters

func UsesFilters(vs *driver.ViewStyle) bool

UsesFilters reports whether vs gives its layer Core Image filters.

func WatchNotifications

func WatchNotifications()

WatchNotifications makes NSGo the center's delegate. Call it as the app starts, before it finishes launching, so the press that launched it is heard.

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.

func Z

func Z(order float64) float64

Z are those orders scaled down, so a child perspective (a sublayer transform that projects by depth) leaves these layers their size.

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

type CGRect struct {
	Origin CGPoint
	Size   CGSize
	// contains filtered or unexported fields
}

func Damaged

func Damaged(before, after []driver.DrawOp) (area CGRect, whole bool)

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

func KeptContent(laid, need CGRect) CGRect

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.

func Rect

func Rect(x, y, w, h float64) CGRect

Rect returns a CGRect.

type CGSize

type CGSize struct {
	Width, Height float64
	// contains filtered or unexported fields
}

type CanvasHost

type CanvasHost struct {
	Ratio  float64
	Redraw func()
	Owner  any
	BaseUp bool
}

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.

func (*GPUProbe) Sample

func (p *GPUProbe) Sample() *float32

Sample returns GPU time over wall time since the previous call, in percent: nil the first time, and while the process has no accelerator client.

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

func NewImageView(host objc.ID) *ImageView

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

func (iv *ImageView) Draw(ctx uintptr)

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

func (iv *ImageView) Layout(size CGSize)

Layout fits the image to the view's new size, decoding the source again when the view outgrows the size it was decoded at.

func (*ImageView) SetStyle

func (iv *ImageView) SetStyle(vs *driver.ViewStyle)

SetStyle applies what of a view's style the image layer draws: the tint and the corners.

func (*ImageView) Start

func (iv *ImageView) Start(ratio float64)

Start loads what Configure or Layout changed, for a screen of ratio pixels per point. Backends call it once a batch has sized the view.

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

func (l *Layout) Attachment(i int) (driver.Bounds, bool)

Attachment implements core.AttachmentLayout.

func (*Layout) CaretRect

func (l *Layout) CaretRect(c driver.Caret) (driver.Bounds, bool)

CaretRect implements driver.TextHitTester.

func (*Layout) ContentFrame

func (l *Layout) ContentFrame(w, h float64, box CGRect) CGRect

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

func (l *Layout) Draw(ctx uintptr, viewHeight float64, box CGRect, baseUp bool)

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

func (l *Layout) DrawBackgrounds(ctx uintptr, at CGRect)

DrawBackgrounds fills the backgrounds of l's spans in box of a flipped context, behind the selection and the glyphs.

func (*Layout) HitTest

func (l *Layout) HitTest(p driver.Point) driver.Caret

HitTest implements driver.TextHitTester.

func (*Layout) IndexAt

func (l *Layout) IndexAt(p CGPoint, box CGRect) int

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

func (l *Layout) OffsetAt(p CGPoint, box CGRect) int

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

func (l *Layout) RangeRects(start, end int, out []driver.Bounds) []driver.Bounds

RangeRects implements driver.TextHitTester.

func (*Layout) Release

func (l *Layout) Release()

Release implements core.TextLayout.

func (*Layout) SelectionRects

func (l *Layout) SelectionRects(start, end int, box CGRect) []CGRect

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.

func (*Layout) TextLines

func (l *Layout) TextLines() []driver.TextLine

TextLines implements core.LineLayout: each line's range, box and its first run's font metrics.

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.

func (*Picture) Take

func (p *Picture) Take(layer objc.ID, x, y, w, h, scale float64, hide objc.ID) bool

Take draws layer's tree into the picture: the rectangle of w by h points from (x, y) in layer's coordinates, at scale pixels a point, hiding hide's layer (0 for none) and lifting layer's mask while it draws. It reports whether it drew.

func (*Picture) Texture

func (p *Picture) Texture() (objc.ID, int, int)

Texture returns the picture's texture and its size in pixels, 0 before it was taken.

type ScrollEdge

type ScrollEdge struct {
	Tint, Line objc.ID
}

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.

func (*ScrollEdge) Release

func (p *ScrollEdge) Release()

Release releases the layers.

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

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.

func NewVideo

func NewVideo(holder objc.ID) *Video

NewVideo returns the video of holder, empty until configured.

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.

func (*Video) Layout

func (v *Video) Layout()

Layout keeps an iOS player layer at the view's size.

func (*Video) Seek

func (v *Video) Seek(position time.Duration)

Seek jumps to position exactly.

func (*Video) View

func (v *Video) View() objc.ID

View returns the AppKit view showing the player (macOS), 0 before one.

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 NewWeb

func NewWeb(holder objc.ID) *Web

NewWeb returns the web view of holder, empty until configured.

func (*Web) Close

func (w *Web) Close()

Close stops the page and lets the WKWebView go.

func (*Web) Command

func (w *Web) Command(c driver.WebCommand, value string)

Command does c, with value for messages and scripts.

func (*Web) Configure

func (w *Web) Configure(c *driver.WebConfig)

Configure applies c, loading the source again when it or the scripts changed.

func (*Web) View

func (w *Web) View() objc.ID

View returns the WKWebView, 0 before the first Configure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL