window

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package window presents a ggplot figure in a native desktop GPU window via gogpu + ggcanvas, the zero-copy GPU rendering integration. Drawing goes through gg.Context (GPU-accelerated), and ggcanvas.Canvas presents via RenderDirect (zero-copy to surface) with automatic fallback to CPU upload.

Pan (mouse drag) and zoom (mouse wheel) are handled through gogpu's event system, translated to ggplot's platform-neutral output.Controller.

Show blocks until the window closes and must be called from the main goroutine (GPU/windowing requires the main OS thread).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Show

func Show(ctx context.Context, src output.Source, opts ...Opt) error

Show builds src into a figure and presents it in a native window, processing pan/zoom and other interactions until the window is closed. It blocks and must be called from the main goroutine.

Show automatically pins the calling goroutine to its OS thread (runtime.LockOSThread) because Win32 and Cocoa require the window event loop to run on the thread that created the window.

Types

type Opt

type Opt func(*Options)

Opt functionally configures Options.

func WithController

func WithController(c output.Controller) Opt

WithController overrides the default pan/wheel-zoom controller.

func WithFPS

func WithFPS() Opt

WithFPS enables an FPS counter overlay in the top-right corner of the window. Uses an exponential moving average for smooth readings.

func WithPprof

func WithPprof() Opt

WithPprof enables a pprof HTTP server on localhost:6060 for the lifetime of the window. While the window is open and you are interacting, capture a CPU profile with:

go tool pprof http://localhost:6060/debug/pprof/profile?seconds=5

Or open http://localhost:6060/debug/pprof/ in a browser for all profiles.

func WithRebuildDelay

func WithRebuildDelay(d time.Duration) Opt

WithRebuildDelay enables async, debounced rebuilds. When set, rapid rebuild requests (e.g. repeated zoom-past-extent) are coalesced: the rebuild fires only after delay elapses with no new request. The last good figure keeps drawing until the background build completes. Zero (default) means synchronous.

func WithRebuildError

func WithRebuildError(fn func(error)) Opt

WithRebuildError sets a handler invoked when an async rebuild fails. The last good figure is kept on screen; the error is non-fatal. Nil (default) means async rebuild errors are silent (but the first fatal error still stops Show).

func WithSize

func WithSize(w, h int) Opt

WithSize sets the initial window size in logical pixels.

func WithTitle

func WithTitle(title string) Opt

WithTitle sets the window title.

type Options

type Options struct {
	Title        string
	Width        int
	Height       int
	Controller   output.Controller
	RebuildDelay time.Duration // 0 = synchronous rebuild (default)
	OnRebuildErr func(error)   // called when an async rebuild fails (nil = silent)
	ShowFPS      bool          // show FPS counter overlay
	PprofAddr    string        // if non-empty, start pprof HTTP server on this address
}

Options configures a window opened by Show.

Jump to

Keyboard shortcuts

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