offscreen

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package offscreen renders a widget.Widget tree into an *image.RGBA without a GPU, window, or running application.

This enables headless widget rendering for screenshot testing, multi-process compositors (e.g. github.com/gogpu/compose), PDF/image export, and CI pipelines.

The renderer uses CPU-only rasterization via github.com/gogpu/gg. A Material 3 light theme is applied by default; override with WithTheme.

Basic usage

r := offscreen.NewRenderer(400, 120)
r.Render(primitives.Text("Hello, World!").FontSize(24))
img := r.Image() // *image.RGBA — ready for png.Encode, testing, compositing

HiDPI rendering

r := offscreen.NewRenderer(800, 240, offscreen.WithScale(2.0))

Custom theme and background

dark := material3.NewDark(widget.Hex(0x00BFA5))
r := offscreen.NewRenderer(400, 120,
    offscreen.WithTheme(dark),
    offscreen.WithBackground(widget.ColorWhite),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Renderer)

Option configures a Renderer.

func WithBackground

func WithBackground(c widget.Color) Option

WithBackground sets the canvas clear color before drawing. The default is transparent (zero alpha).

func WithScale

func WithScale(s float32) Option

WithScale sets the display scale factor for HiDPI rendering. The default is 1.0. A value of 2.0 renders at Retina density.

func WithTheme

func WithTheme(tp widget.ThemeProvider) Option

WithTheme overrides the default Material 3 light theme.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer renders a widget tree into an offscreen image.

Create with NewRenderer. Configure with Option functions. Call Renderer.Render to draw a widget, then Renderer.Image to retrieve the result.

func NewRenderer

func NewRenderer(width, height int, opts ...Option) *Renderer

NewRenderer creates an offscreen renderer with the given pixel dimensions.

Width and height must be positive; they are clamped to a minimum of 1. By default, a Material 3 light theme is applied and the background is transparent. Override with WithTheme, WithBackground, and WithScale.

func (*Renderer) Image

func (r *Renderer) Image() *image.RGBA

Image returns the rendered image, or nil if [Render] has not been called.

func (*Renderer) Render

func (r *Renderer) Render(w widget.Widget)

Render lays out and draws the widget into the offscreen buffer.

The widget receives the full renderer dimensions as loose layout constraints. Calling Render again replaces the previously rendered image.

Jump to

Keyboard shortcuts

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