Documentation
¶
Overview ¶
Package svg turns a rendered RGBA byte buffer (the output of any go-widgets/toolkit widget composition) into a portable SVG document that embeds the pixels as a base64-encoded PNG. The wrapper scales crisply at any zoom level and travels well in READMEs, GitHub issues, docs sites, tweet threads and PDF exports.
Why not a "true" vector renderer? Widgets in go-widgets/toolkit are pixel-blitting by design — every draw call writes bytes into a []byte at (x, y). Converting that pipeline to <rect>/<text>/etc. would either double every widget's implementation or lose the exact alignment users see in-browser. Embedding the render as PNG is bit-exact (any pixel you see in the browser is the same pixel in the SVG) while still giving you the "scales to any DPI" benefit + the "one file, no external assets" portability.
Typical use in a doc-generation script:
surface := make([]byte, 4*w*h)
btn := toolkit.NewButton("Click me", nil)
btn.SetBounds(toolkit.Rect{X: 0, Y: 0, W: w, H: h})
btn.Draw(painter.NewPixelPainter(surface, w, h), toolkit.DefaultLight())
f, _ := os.Create("button.svg")
svg.Snapshot(f, surface, w, h, "widget: button")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Snapshot ¶
Snapshot writes an SVG document that wraps the RGBA pixels of a widget render. width + height are the buffer's dimensions; label is a short human-readable string embedded as the SVG's <title>/<desc> for a11y + previewer tooltips (pass "" to omit).
The output is a single, self-contained SVG (no external assets) with a <image> child pointing at data:image/png;base64,… so it pastes cleanly into any Markdown renderer that already accepts SVG images (GitHub, GitLab, mkdocs, Hugo, ...).
Returns the number of bytes written + the first error, mirroring the io.Writer convention.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gallery-render
command
Command gallery-render writes an SVG + PNG snapshot of every go-widgets/toolkit widget kind to a directory.
|
Command gallery-render writes an SVG + PNG snapshot of every go-widgets/toolkit widget kind to a directory. |
|
Package widget wraps the go-widgets/toolkit `Widget` interface with two write-to-io.Writer conveniences:
|
Package widget wraps the go-widgets/toolkit `Widget` interface with two write-to-io.Writer conveniences: |