render

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package render produces SVG button faces for Stream Deck keys.

Index

Constants

View Source
const Canvas = 144

Canvas is the edge length (in SVG user units) of a Stream Deck button face.

Variables

This section is empty.

Functions

func ContentFitBBoxTransform added in v0.7.1

func ContentFitBBoxTransform(bb BBox, tx, ty, tw, th float64) string

ContentFitBBoxTransform returns an SVG transform string that scales and centers a bounding box into a target rectangle.

func ContentFitGlyphTransform added in v0.7.1

func ContentFitGlyphTransform(g *ProviderGlyph, tx, ty, tw, th float64) string

ContentFitGlyphTransform returns an SVG transform string that scales and centers a provider glyph into a target rectangle. Multi-path glyphs prefer their declared viewBox so source stroke widths and arrowheads keep the same visual framing as the original SVG.

func ContentFitTransform

func ContentFitTransform(d string, tx, ty, tw, th float64) string

ContentFitTransform returns an SVG transform string that scales and centers a path's actual content into a target rectangle.

func FormatCountdown

func FormatCountdown(seconds float64) string

FormatCountdown formats seconds into a human-readable countdown. Carries the next-smaller unit when it carries information, but skips trailing zeros so "1d 0h" / "1h 0m" never appear. When the immediate secondary unit is zero, falls through to the next non-zero adjacent unit so e.g. 1d 0h 30m → "1d 30m" (not "1d 0h" or just "1d").

30s, 5m, 5m 30s, 5h, 5h 30m, 1d, 1d 5h, 1d 30m, 4d 12h.

func IsValidHexColor

func IsValidHexColor(s string) bool

IsValidHexColor checks if a string is a valid hex color.

func RenderButton

func RenderButton(in ButtonInput) string

RenderButton produces an SVG string for a Stream Deck key face.

func RenderLoading

func RenderLoading(glyph *ProviderGlyph, fillColor, bgColor, fgColor string, showBorder *bool, starfield bool) string

RenderLoading produces a loading face with just the provider glyph.

Types

type BBox

type BBox struct {
	MinX, MinY, MaxX, MaxY float64
}

BBox is an axis-aligned bounding box.

func PathBBox

func PathBBox(d string) BBox

PathBBox computes the approximate bounding box of an SVG path's d attribute. Includes bezier control points (conservative estimate).

func ViewBoxBBox added in v0.7.1

func ViewBoxBBox(viewBox string) (BBox, bool)

ViewBoxBBox parses an SVG viewBox into a BBox.

func (BBox) Height

func (b BBox) Height() float64

Height returns the bounding box height.

func (BBox) Union added in v0.7.1

func (b BBox) Union(other BBox) BBox

Union returns the smallest BBox containing b and other.

func (BBox) Width

func (b BBox) Width() float64

Width returns the bounding box width.

type ButtonInput

type ButtonInput struct {
	Label        string
	Value        string
	Subvalue     string
	Ratio        *float64 // nil = reference card
	Direction    string   // "up"|"down"|"right"|"left"
	Fill         string   // hex — meter fill
	Bg           string   // hex
	Fg           string   // hex
	Border       *bool    // nil = true
	ValueSize    string   // "small"|"medium"|"large"
	SubvalueSize string
	Stale        *bool
	Glyph        *ProviderGlyph
	GlyphMode    string // "watermark"|"centered"|"corner"|"none"
	ShowGlyph    *bool  // nil = true
	// SmartContrast enables the dual-layer contrast auto-flip for text
	// and the watermark glyph's back layer. The zero value (false)
	// renders fg exactly as provided — callers opt in per-render.
	// Application-level defaults live in GlobalSettings.SmartContrast
	// (default on), and main.go threads that runtime decision into
	// this field at each render site.
	SmartContrast bool
	// Starfield, when true, paints the animated xAI-style starfield
	// (orbital drift + per-star twinkle + a periodic shooting-star
	// streak) BEHIND the watermark glyph and text layers (paint order:
	// bg → starfield → glyph → meter fill → text). Currently set only
	// for Grok buttons (settings.StarfieldEnabled is provider-gated).
	// Animation requires a frame driver — see starfieldAnimationLoop
	// in cmd/plugin/main.go — because Stream Deck rasterizes each
	// SetImage SVG to a static PNG.
	Starfield bool
}

ButtonInput configures a button face render.

type GlyphPath added in v0.7.1

type GlyphPath struct {
	// D is the SVG path data for this glyph element.
	D string
	// Stroke renders this path as a stroked outline instead of a fill.
	Stroke bool
	// StrokeWidth preserves source SVG stroke widths for stroked paths.
	StrokeWidth float64
}

GlyphPath is one path in a provider glyph.

type ProviderGlyph

type ProviderGlyph struct {
	// ViewBox is the SVG viewBox attribute for the glyph path.
	ViewBox string
	// Markup holds raw inner SVG elements for glyphs that are not plain
	// path-only marks. Elements should use currentColor for brand-colored
	// fills/strokes so each render layer can recolor them safely.
	Markup string
	// D is the SVG path `d` attribute for the glyph geometry.
	D string
	// Paths holds multi-path glyph geometry. When set, Paths is rendered
	// instead of D so mixed fill/stroke logos can keep their source shape.
	Paths []GlyphPath
	// Stroke renders the glyph as an outline (stroke + fill:none +
	// vector-effect:non-scaling-stroke) instead of the default filled
	// silhouette — lets outline marks (Tabler, Lucide, etc.) sit
	// alongside solid brand glyphs without reshaping each path to a
	// closed fill region.
	Stroke bool
}

ProviderGlyph holds an SVG path for a provider logo.

Jump to

Keyboard shortcuts

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