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 ¶
WithBackground sets the canvas clear color before drawing. The default is transparent (zero alpha).
func WithScale ¶
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 ¶
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.