render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BilinearColor

func BilinearColor(g *GradientColors, u, v float64) sg.Color

BilinearColor computes the bilinearly interpolated color at normalized coordinates (u, v) given the four corner colors of a GradientColors.

func LayoutNineSlice

func LayoutNineSlice(nodes *NineSliceNodes, ns *NineSlice, w, h float64)

LayoutNineSlice positions and scales the 9 sprites to fill the given dimensions (w, h). Corners keep their natural pixel size; edges stretch along one axis; center stretches both.

func LerpColor

func LerpColor(a, b sg.Color, t float64) sg.Color

LerpColor linearly interpolates between two colors by t in [0,1].

func RoundedRectBorderMesh

func RoundedRectBorderMesh(w, h, r, bw float64, segments int) ([]engine.Vertex, []uint16)

RoundedRectBorderMesh generates a triangle-strip ring between an outer rounded rect and an inner rounded rect (inset by bw on all sides). Returns raw vertices and indices for use with willow.NewMesh. All vertices use white pixel UV (SrcX=0.5, SrcY=0.5) and full white color (tinted by node.Color at render time).

func RoundedRectGradientMesh

func RoundedRectGradientMesh(w, h, cornerRadius float64, segments int, g *GradientColors) ([]engine.Vertex, []uint16)

RoundedRectGradientMesh creates a mesh of vertices and indices for a gradient-filled rounded rectangle. cornerRadius can be 0 for sharp corners. The gradient colors are bilinearly interpolated across the rectangle using per-vertex coloring. The mesh uses fan triangulation from the centroid.

func RoundedRectGradientMeshPerCorner

func RoundedRectGradientMeshPerCorner(w, h float64, rTL, rTR, rBR, rBL float64, segments int, g *GradientColors) ([]engine.Vertex, []uint16)

RoundedRectGradientMeshPerCorner creates a gradient-filled mesh with independent corner radii (top-left, top-right, bottom-right, bottom-left).

func RoundedRectPoints

func RoundedRectPoints(w, h, r float64, segments int) []sg.Vec2

RoundedRectPoints generates the outline of a rounded rectangle as a closed polygon. Each corner is an arc of segments line segments. The radius r is clamped to min(w/2, h/2) to prevent overlap. Corners are generated clockwise: top-right, bottom-right, bottom-left, top-left.

func RoundedRectPointsPerCorner

func RoundedRectPointsPerCorner(w, h float64, rTL, rTR, rBR, rBL float64, segments int) []sg.Vec2

RoundedRectPointsPerCorner generates a rounded rectangle outline with independent radii for each corner: top-left, top-right, bottom-right, bottom-left. A radius of 0 produces a sharp corner.

func SubRegion

func SubRegion(base sg.TextureRegion, x, y, w, h uint16) sg.TextureRegion

SubRegion computes a sub-region within a base TextureRegion. x, y, w, h are in pixel coordinates relative to the base region's origin.

Types

type Gradient

type Gradient struct {
	Mode   GradientMode
	Colors GradientColors
}

Gradient is the value type produced by GradientEditor. Colors always carries all four corners; H and V modes keep linked corners in sync.

type GradientColors

type GradientColors struct {
	TopLeft, TopRight, BottomRight, BottomLeft sg.Color
}

GradientColors defines per-corner colors for gradient backgrounds. Colors are interpolated bilinearly across the rectangle.

type GradientMode

type GradientMode int

GradientMode selects which corners are independently editable.

const (
	GradientModeH          GradientMode = iota // horizontal: TL=BL, TR=BR
	GradientModeV                              // vertical:   TL=TR, BL=BR
	GradientModeFourCorner                     // all 4 corners independent
)

type Insets

type Insets struct {
	Top, Right, Bottom, Left float64
}

Insets represents spacing on four sides (top, right, bottom, left).

func (Insets) Horizontal

func (i Insets) Horizontal() float64

Horizontal returns Left + Right.

func (Insets) IsAuto

func (i Insets) IsAuto() bool

IsAuto reports whether i is the AutoPadding sentinel (any field is -1).

func (Insets) Vertical

func (i Insets) Vertical() float64

Vertical returns Top + Bottom.

type NineSlice

type NineSlice struct {
	Region      sg.TextureRegion
	Insets      Insets
	InnerRegion Rect
	CenterFill  *GradientColors
}

NineSlice describes a nine-slice image for use as a component background. Region is the base texture region; Insets define the non-stretched border widths (top, right, bottom, left) in pixels. InnerRegion defines the content area within the grid, in local coordinates relative to Region. Components use this for padding reference point. CenterFill, when non-nil, replaces the center cell's texture with a gradient fill.

type NineSliceNodes

type NineSliceNodes struct {
	TL, T, TR *sg.Node
	L, C, R   *sg.Node
	BL, B, BR *sg.Node
}

NineSliceNodes holds the 9 sprite nodes that make up a nine-slice background. The naming convention follows CSS-style corners and edges:

TL  T  TR
L   C   R
BL  B  BR

func CreateNineSliceNodes

func CreateNineSliceNodes(name string, container *sg.Node, ns *NineSlice) *NineSliceNodes

CreateNineSliceNodes creates 9 sprite nodes as children of the given container, each using the correct sub-region of the nine-slice image.

type Rect

type Rect struct {
	X, Y, Width, Height float64
}

Rect describes a rectangle with position and dimensions.

Jump to

Keyboard shortcuts

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