render

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 2 modules, 2 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

Overview

Package render provides a small, framework-neutral drawing protocol over display.Box.

Walk streams visible path and rule commands without copying transformed path geometry. The path template in each command borrows storage from the box and is valid only for the duration of its callback invocation. ResolvePath is the explicit allocating escape hatch for hosts that need standalone geometry.

Fit computes a uniform transform that places all certified box bounds, including overflow, inside a host viewport.

Index

Constants

View Source
const (
	AlignStart  = display.AlignStart
	AlignCenter = display.AlignCenter
	AlignEnd    = display.AlignEnd
)

Variables

View Source
var (
	// ErrInvalidViewport reports a nil, non-finite, or non-positive viewport.
	ErrInvalidViewport = errors.New("render: invalid viewport")
	// ErrInvalidFitOptions reports invalid padding or alignment.
	ErrInvalidFitOptions = errors.New("render: invalid fit options")
)
View Source
var (
	// ErrInvalidBox reports malformed input needed by the drawing protocol.
	ErrInvalidBox = errors.New("render: invalid box")
	// ErrInvalidCallback reports a nil Walk callback.
	ErrInvalidCallback = errors.New("render: invalid callback")
	// ErrInvalidCommand reports a command that cannot be resolved as a path.
	ErrInvalidCommand = errors.New("render: invalid command")
)

Functions

func ResolvePath

func ResolvePath(command Command) (geometry.Path, error)

ResolvePath materializes one path command in box coordinates.

ResolvePath allocates a new geometry.Path. Hosts that can draw directly from segments should use Walk and transform points to box coordinates themselves. ResolvePath does not mutate the borrowed template.

func Walk

func Walk(box *display.Box, visit func(Command) error) error

Walk visits visible path and rule items in box item order.

ItemGlyphRef records are cache metadata and are skipped. Walk does not validate the complete box, materialize path geometry, or allocate command storage. A callback error is returned unchanged and stops the walk.

Types

type Align

type Align = display.Align

Align is horizontal placement inside the padded viewport. It aliases the display alignment enum so host render and layout policies cannot drift.

type Command

type Command struct {
	Kind  CommandKind
	Paint display.Paint
	Bound geometry.Rect

	Path display.PathTemplate
	At   geometry.Point
	Em   float32

	Rect geometry.Rect
	// Snap is non-none only for conservative thin-rule snapping candidates.
	// Its presence does not imply Style.PixelGrid changed the geometry.
	Snap display.SnapAxis
}

Command is one visible drawing operation in box coordinates.

Path aliases Box.Paths storage. Callers must not mutate Path or retain it after the Walk callback returns. Rule commands use Rect and leave Path empty.

type CommandKind

type CommandKind uint8

CommandKind identifies one visible drawing operation.

const (
	// CommandPath fills a shared path template placed by At and Em.
	CommandPath CommandKind = iota
	// CommandRule fills Rect.
	CommandRule
)

type FitOptions

type FitOptions struct {
	Padding float32
	Align   Align
}

FitOptions controls placement inside a viewport. Padding is applied equally on every side. The box is always centered vertically.

type Transform

type Transform struct {
	Scale  float32
	Offset geometry.Point
}

Transform maps box coordinates into viewport coordinates as offset + point*scale.

func Fit

func Fit(box *display.Box, viewport geometry.Rect, options FitOptions) (Transform, error)

Fit returns a uniform transform that tightly fits Box.Bounds(), including certified overflow, inside viewport after padding.

Fit may enlarge small boxes. A box with zero width and height uses scale 1. The viewport must have finite positive dimensions, and padding must leave a finite positive content area.

func (Transform) Apply

func (t Transform) Apply(point geometry.Point) geometry.Point

Apply maps one point from box coordinates into viewport coordinates.

func (Transform) ApplyRect

func (t Transform) ApplyRect(rect geometry.Rect) geometry.Rect

ApplyRect maps an axis-aligned rectangle from box coordinates into viewport coordinates.

Jump to

Keyboard shortcuts

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