Documentation
¶
Overview ¶
Package instructions provides primitives for grouping and drawing bounded shapes together.
Package instructions provides primitives for drawing raster images with fitting, flipping, rotation, mask support, effects, and global opacity.
Index ¶
- type AlignItems
- type AlignText
- type AutoLayout
- type Boundable
- type BoundedShape
- type Circle
- func (c *Circle) AddEffect(e effects.Effect) *Circle
- func (c *Circle) AddEffects(es ...effects.Effect) *Circle
- func (c *Circle) Draw(base, overlay *image.RGBA)
- func (c *Circle) Position() (int, int)
- func (c *Circle) SetFillColor(col patterns.Color) *Circle
- func (c *Circle) SetFillPattern(p patterns.Pattern) *Circle
- func (c *Circle) SetLineWidth(width float64) *Circle
- func (c *Circle) SetPosition(x, y int)
- func (c *Circle) SetRadius(r float64) *Circle
- func (c *Circle) SetSteps(steps int) *Circle
- func (c *Circle) SetStrokeColor(col patterns.Color) *Circle
- func (c *Circle) SetStrokePattern(p patterns.Pattern) *Circle
- func (c *Circle) SetStrokePosition(pos StrokePosition) *Circle
- func (c *Circle) Size() *geom.Size
- type ContainerStyle
- type Display
- type FillRule
- type FitMode
- type FlexDirection
- type Group
- func (g *Group) AddInstruction(s BoundedShape)
- func (g *Group) AddInstructions(shapes ...BoundedShape)
- func (g *Group) Clear()
- func (g *Group) Draw(base, overlay *image.RGBA)
- func (g *Group) Position() (int, int)
- func (g *Group) SetClip(clip bool) *Group
- func (g *Group) SetFrameSize(w, h int) *Group
- func (g *Group) SetPosition(x, y int)
- func (g *Group) SetPositionChain(x, y int) *Group
- func (g *Group) Size() *geom.Size
- type Image
- func (im *Image) AddEffect(e effects.Effect) *Image
- func (im *Image) AddEffects(es ...effects.Effect) *Image
- func (im *Image) ClearMask() *Image
- func (im *Image) Draw(_, overlay *image.RGBA)
- func (im *Image) Mirror(h, v bool) *Image
- func (im *Image) Position() (int, int)
- func (im *Image) Rotate(deg float64) *Image
- func (im *Image) SetBackground(c patterns.Color) *Image
- func (im *Image) SetExpand(b bool) *Image
- func (im *Image) SetFit(f FitMode) *Image
- func (im *Image) SetFlip(h, v bool) *Image
- func (im *Image) SetMaskFromShape(s Shape) *Image
- func (im *Image) SetMaskImage(m *image.RGBA) *Image
- func (im *Image) SetOpacity(o float64) *Image
- func (im *Image) SetPosition(x, y int)
- func (im *Image) SetSize(w, h int) *Image
- func (im *Image) Size() *geom.Size
- type ItemStyle
- type JustifyContent
- type Layer
- func (l *Layer) AddLayer(layer *Layer, x, y int) *Layer
- func (l *Layer) Draw(_, overlay *image.RGBA)
- func (l *Layer) Export(path string) error
- func (l *Layer) ExportBytes(level png.CompressionLevel) ([]byte, error)
- func (l *Layer) ExportJPEG(path string, quality int) error
- func (l *Layer) ExportPNG(path string, level png.CompressionLevel) error
- func (l *Layer) Image() *image.RGBA
- func (l *Layer) LoadInstruction(shape Shape)
- func (l *Layer) LoadInstructions(shapes ...Shape)
- func (l *Layer) Position() (int, int)
- func (l *Layer) SetBounds(x, y, width, height int)
- func (l *Layer) SetBoundsChain(x, y, width, height int) *Layer
- func (l *Layer) SetPosition(x, y int)
- func (l *Layer) SetPositionChain(x, y int) *Layer
- func (l *Layer) SetSize(w, h int)
- func (l *Layer) SetSizeChain(w, h int) *Layer
- func (l *Layer) Size() *geom.Size
- type Line
- func (l *Line) ClearPath() *Line
- func (l *Line) ClipPreserve() *Line
- func (l *Line) ClosePath() *Line
- func (l *Line) CubicTo(x1, y1, x2, y2, x3, y3 float64) *Line
- func (l *Line) Draw(base, overlay *image.RGBA)
- func (l *Line) Fill() *Line
- func (l *Line) FillPreserve() *Line
- func (l *Line) LineTo(x, y float64) *Line
- func (l *Line) MoveTo(x, y float64) *Line
- func (l *Line) NewSubPath() *Line
- func (l *Line) QuadraticTo(x1, y1, x2, y2 float64) *Line
- func (l *Line) ResetMask() *Line
- func (l *Line) ResetMatrix() *Line
- func (l *Line) SetDashOffset(off float64) *Line
- func (l *Line) SetDashes(d []float64) *Line
- func (l *Line) SetFillPattern(p patterns.Pattern) *Line
- func (l *Line) SetFillRule(r FillRule) *Line
- func (l *Line) SetLineCap(c LineCap) *Line
- func (l *Line) SetLineJoin(j LineJoin) *Line
- func (l *Line) SetLineWidth(w float64) *Line
- func (l *Line) SetStrokePattern(p patterns.Pattern) *Line
- func (l *Line) Stroke() *Line
- func (l *Line) StrokePreserve() *Line
- func (l *Line) WithMatrix(m geom.Matrix) *Line
- type LineCap
- type LineJoin
- type Point
- func (p *Point) Add(q Point) Point
- func (p *Point) Angle(q Point) float64
- func (p *Point) Color() patterns.Color
- func (p *Point) Distance(q *Point) float64
- func (p *Point) Dot(q Point) float64
- func (p *Point) Draw(_, overlay *image.RGBA)
- func (p *Point) Fixed() fixed.Point26_6
- func (p *Point) Interpolate(q *Point, t float64) *Point
- func (p *Point) Length() float64
- func (p *Point) Midpoint(q Point) Point
- func (p *Point) Normalize() Point
- func (p *Point) Rotate(angle float64) *Point
- func (p *Point) Scale(factor float64) Point
- func (p *Point) SetColor(c patterns.Color) *Point
- func (p *Point) Sub(q Point) Point
- type PositionType
- type Rectangle
- func (r *Rectangle) AddEffect(e effects.Effect) *Rectangle
- func (r *Rectangle) AddEffects(es ...effects.Effect) *Rectangle
- func (r *Rectangle) Draw(base, overlay *image.RGBA)
- func (r *Rectangle) Position() (int, int)
- func (r *Rectangle) SetCornerRadii(tl, tr, br, bl float64) *Rectangle
- func (r *Rectangle) SetFillColor(c patterns.Color) *Rectangle
- func (r *Rectangle) SetFillPattern(p patterns.Pattern) *Rectangle
- func (r *Rectangle) SetLineWidth(width float64) *Rectangle
- func (r *Rectangle) SetPosition(x, y int)
- func (r *Rectangle) SetRadius(radius float64) *Rectangle
- func (r *Rectangle) SetRoundedSteps(steps int) *Rectangle
- func (r *Rectangle) SetSize(width, height float64) *Rectangle
- func (r *Rectangle) SetStrokeColor(c patterns.Color) *Rectangle
- func (r *Rectangle) SetStrokePattern(p patterns.Pattern) *Rectangle
- func (r *Rectangle) SetStrokePosition(pos StrokePosition) *Rectangle
- func (r *Rectangle) Size() *geom.Size
- type Resizable
- type Shape
- type StrokePosition
- type Text
- func (t *Text) AddEffect(e effects.Effect) *Text
- func (t *Text) AddEffects(es ...effects.Effect) *Text
- func (t *Text) Draw(base, overlay *image.RGBA)
- func (t *Text) Position() (int, int)
- func (t *Text) SetAlign(a AlignText) *Text
- func (t *Text) SetColorPattern(p patterns.Pattern) *Text
- func (t *Text) SetLineSpacing(percent float64) *Text
- func (t *Text) SetMaxLines(n int) *Text
- func (t *Text) SetMaxWidth(w float64) *Text
- func (t *Text) SetPosition(x, y int)
- func (t *Text) SetScaleStep(pt float64) *Text
- func (t *Text) SetSolidColor(c patterns.Color) *Text
- func (t *Text) SetStrokeWithColor(c patterns.Color, width float64) *Text
- func (t *Text) SetStrokeWithPattern(p patterns.Pattern, width float64) *Text
- func (t *Text) SetWrap(mode WrapMode, symbol string) *Text
- func (t *Text) SetWrapMode(mode WrapMode) *Text
- func (t *Text) SetWrapSymbol(sym string) *Text
- func (t *Text) Size() *geom.Size
- type Vector2
- type WrapMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlignItems ¶
type AlignItems int
AlignItems controls cross-axis alignment of items within each line.
const ( AlignItemsStart AlignItems = iota // Align items to the start of the cross axis AlignItemsCenter // Align items to the cross-axis center AlignItemsEnd // Align items to the end of the cross axis AlignItemsStretch // Stretch items to fill the line’s cross size )
type AlignText ¶
type AlignText int
AlignText defines the horizontal alignment behavior of rendered lines.
type AutoLayout ¶
type AutoLayout struct {
// contains filtered or unexported fields
}
AutoLayout is a flexible container that arranges child shapes according to Flexbox-like rules and draws them to an overlay image. It never modifies the base layer.
func NewAutoLayout ¶
func NewAutoLayout(x, y int, style ContainerStyle) *AutoLayout
NewAutoLayout constructs a new flex container anchored at (x, y). If Display is not DisplayFlex, it is forced to DisplayFlex.
func (*AutoLayout) Add ¶
func (al *AutoLayout) Add(s Shape, st ItemStyle) *AutoLayout
Add registers a child Shape with an optional ItemStyle. If the shape implements BoundedShape, its size and position are queried/updated automatically.
func (*AutoLayout) Draw ¶
func (al *AutoLayout) Draw(base, overlay *image.RGBA)
Draw performs layout, sorts children by ZIndex, and draws each one in order. Shapes implementing Boundable receive SetBounds; else Position/Size are propagated if available.
func (*AutoLayout) SetStyle ¶
func (al *AutoLayout) SetStyle(style ContainerStyle)
SetStyle replaces the container style and invalidates the current layout.
func (*AutoLayout) Size ¶
func (al *AutoLayout) Size() *geom.Size
Size returns the outer dimensions of the container including padding. Triggers layout if needed.
type Boundable ¶
type Boundable interface {
SetBounds(x, y, w, h int)
}
Boundable is an optional capability: layout passes x,y,w,h in one call.
type BoundedShape ¶
type BoundedShape interface {
Shape
// Size returns the intended width and height of the shape as a *geom.Size.
// A zero value for either axis typically indicates that the shape should
// determine its size automatically from its content or intrinsic geometry.
Size() *geom.Size
// Position returns the current top-left coordinate of the shape in
// integer pixel units. This defines the anchor point used for rendering
// and layout alignment.
Position() (int, int)
// SetPosition updates the shape’s anchor point to the given (x, y)
// coordinate. This does not automatically trigger a redraw; the new
// position is applied the next time Draw() is called.
SetPosition(x, y int)
}
BoundedShape extends Shape with positional and dimensional metadata.
It introduces the concept of a rectangular bounding box, which defines both the size of the drawable object and its placement within a two-dimensional scene. This interface allows layout managers, compositors, and spatial algorithms to arrange and interact with multiple shapes consistently.
type Circle ¶
type Circle struct {
// contains filtered or unexported fields
}
Circle represents a drawable circle with fill, stroke, and optional effects.
func (*Circle) AddEffects ¶
AddEffects adds multiple visual effects.
func (*Circle) SetFillColor ¶
SetFillColor sets solid fill color.
func (*Circle) SetFillPattern ¶
SetFillPattern sets custom fill pattern.
func (*Circle) SetLineWidth ¶
SetLineWidth sets stroke width.
func (*Circle) SetPosition ¶
SetPosition sets top-left position of circle bounding box.
func (*Circle) SetStrokeColor ¶
SetStrokeColor sets solid stroke color.
func (*Circle) SetStrokePattern ¶
SetStrokePattern sets custom stroke pattern.
func (*Circle) SetStrokePosition ¶
func (c *Circle) SetStrokePosition(pos StrokePosition) *Circle
SetStrokePosition defines stroke alignment: inside, center, outside.
type ContainerStyle ¶
type ContainerStyle struct {
Display Display
Direction FlexDirection
Wrap bool
Padding [4]int // top, right, bottom, left
Gap Vector2 // gap.X = horizontal spacing, gap.Y = vertical spacing
Justify JustifyContent
AlignItems AlignItems
AlignContent AlignItems // cross-axis packing across multiple lines: Start/Center/End/Stretch
Width, Height int // container outer dimensions; 0 = auto by content
}
ContainerStyle defines CSS-like layout properties for an AutoLayout container. All numeric units are pixels. Width/Height of 0 mean "auto-size by content".
type Display ¶
type Display int
Display describes the layout model used by a container. Only DisplayFlex is currently implemented but the enum allows future extensions.
type FitMode ¶
type FitMode int
FitMode defines how the source image is resized to the target width/height.
const ( // FitStretch stretches to exactly W×H. Aspect ratio is ignored. FitStretch FitMode = iota // FitContain preserves aspect ratio and fits fully inside W×H. // May leave empty space (letterbox/pillarbox). No cropping. FitContain // FitCover preserves aspect ratio and fills W×H completely. // Crops overflow. Good for thumbnails and covers. FitCover )
type FlexDirection ¶
type FlexDirection int
FlexDirection defines the orientation of the main axis in the flex container.
const ( // Row lays out items horizontally, left-to-right by default. Row FlexDirection = iota // Column lays out items vertically, top-to-bottom by default. Column )
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a frame-like container of drawable shapes rendered as a composite. Children use local coordinates and are offset by (x, y). Optional clipping to the frame.
func NewGroup ¶
func NewGroup() *Group
NewGroup creates a new Group with frame semantics by default.
func (*Group) AddInstruction ¶
func (g *Group) AddInstruction(s BoundedShape)
AddInstruction adds a single shape.
func (*Group) AddInstructions ¶
func (g *Group) AddInstructions(shapes ...BoundedShape)
AddInstructions adds multiple shapes.
func (*Group) SetFrameSize ¶
SetFrameSize sets explicit frame size. Zero means auto from content.
func (*Group) SetPositionChain ¶
SetPositionChain sets position and returns the group for chaining.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image draws a raster with resize, flips, any-angle rotation, optional canvas expansion, effects, global opacity, and optional mask.
Fields are intentionally unexported. Use setters to keep state consistent.
func NewImage ¶
NewImage creates a new Image at (x, y) with safe defaults:
- FitContain
- opacity = 1
- bg = Transparent
- empty effects chain
func (*Image) AddEffects ¶
AddEffects appends multiple effects.
func (*Image) SetBackground ¶
SetBackground sets the color sampled outside source bounds during rotation.
func (*Image) SetMaskFromShape ¶
SetMaskFromShape renders a Shape into an RGBA mask matching the target size. If target size is zero, uses source bounds.
func (*Image) SetMaskImage ¶
SetMaskImage assigns a mask image in destination space.
func (*Image) SetOpacity ¶
SetOpacity sets global alpha in [0..1]. Values are clamped.
func (*Image) SetPosition ¶
SetPosition moves the layer to (x, y).
type ItemStyle ¶
type ItemStyle struct {
Margin [4]int // top, right, bottom, left
Width int // fixed width; 0 = auto
Height int // fixed height; 0 = auto
FlexGrow float64
FlexShrink float64 // defaults to 1 if 0 and negative free space exists
FlexBasis int // preferred main size in px; 0 = auto → width/height/intrinsic
AlignSelf *AlignItems
// Positioning properties for absolute items.
Position PositionType
Top *int
Right *int
Bottom *int
Left *int
// Painting order (higher values drawn later).
ZIndex int
// IgnoreGapBefore skips the container gap directly before this item.
// Affects line construction, wrapping, and final positioning.
IgnoreGapBefore bool
}
ItemStyle defines layout behavior of a single child within a flex container.
type JustifyContent ¶
type JustifyContent int
JustifyContent controls how free space is distributed along the main axis.
const ( JustifyStart JustifyContent = iota // Items packed at the start (default) JustifyCenter // Items centered along main axis JustifyEnd // Items packed at the end JustifySpaceBetween // Even spacing between items, none at ends JustifySpaceAround // Equal spacing around items, half-space at edges JustifySpaceEvenly // Equal spacing including container edges )
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer represents a 2D drawable surface backed by an RGBA buffer. It provides methods to draw, export, and composite images.
func MustLoadLayerFromImagePath ¶
MustLoadLayerFromImagePath loads a PNG or JPEG image from the specified file path and returns it as a Layer. It panics if the file cannot be opened, decoded, or if the format is unsupported. Intended for initialization code, tests, or tools where image load failures are considered fatal.
func NewLayer ¶
NewLayer creates a new empty Layer with the specified width and height. The underlying image buffer is initialized as a blank RGBA canvas.
func NewLayerFromImage ¶
NewLayerFromImage creates a new Layer from any image.Image instance. The input image is converted to RGBA format if necessary.
func NewLayerFromImagePath ¶
NewLayerFromImagePath loads an image from the given file path. Only PNG and JPEG formats are allowed.
func NewLayerFromRGBA ¶
NewLayerFromRGBA creates a new Layer from an existing *image.RGBA buffer. The Layer will share the same underlying pixel data as the provided buffer.
func (*Layer) AddLayer ¶
AddLayer composites another Layer on top of the current one at the specified coordinates. The source Layer is drawn using the Over operator, preserving transparency.
func (*Layer) Draw ¶
Draw renders this Layer’s contents onto another base and overlay image.
The method composites the layer’s RGBA data into the overlay image at the current (x, y) position. This allows a Layer to act as a drawable Shape within higher-level containers or layouts.
func (*Layer) Export ¶
Export automatically determines the file format (PNG or JPEG) based on the file extension. Supported extensions: .png, .jpg, .jpeg.
func (*Layer) ExportBytes ¶
func (l *Layer) ExportBytes(level png.CompressionLevel) ([]byte, error)
ExportBytes encodes the current Layer as PNG and returns the raw byte slice. Useful for in-memory exports, HTTP responses, or further processing.
func (*Layer) ExportJPEG ¶
ExportJPEG saves the Layer as a JPEG image to the specified file path. The quality value must be between 0 and 100.
func (*Layer) ExportPNG ¶
func (l *Layer) ExportPNG(path string, level png.CompressionLevel) error
ExportPNG saves the Layer as a PNG image to the specified file path. The compression level controls the output file size and encoding speed.
func (*Layer) LoadInstruction ¶
LoadInstruction executes a single drawing instruction on the Layer. The instruction defines its own drawing behavior through the Shape interface.
func (*Layer) LoadInstructions ¶
LoadInstructions executes a sequence of drawing instructions in order. Optimized for batch operations while maintaining predictable execution order.
func (*Layer) SetBounds ¶
SetBounds sets the Layer’s position and visible bounds. The size change is clamped to the current buffer capacity and does not resample or reallocate pixels. Only the bounds are adjusted; content stays intact.
func (*Layer) SetBoundsChain ¶
SetBoundsChain sets position and size, clamps size to buffer limits, and returns the Layer. Identical to SetBounds but chainable.
func (*Layer) SetPosition ¶
SetPosition sets the Layer’s position in integer coordinates.
func (*Layer) SetPositionChain ¶
SetPositionChain sets position and returns the same Layer for method chaining.
func (*Layer) SetSize ¶
SetSize adjusts the Layer's visible bounds to the requested width and height without resampling or reallocating pixels. The bounds are clamped to the current backing buffer capacity to avoid expansion. Content is not modified.
func (*Layer) SetSizeChain ¶
SetSizeChain sets the visible bounds to width and height and returns the Layer. Identical to SetSize but chainable.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line is the public facade that exposes a vector drawing API.
func NewLine ¶
func NewLine() *Line
NewLine creates a new Line with default styles and identity transform.
func (*Line) ClipPreserve ¶
ClipPreserve updates the clip mask by rasterizing the current fill path.
func (*Line) ClosePath ¶
ClosePath closes the current subpath by drawing a segment to the start point.
func (*Line) FillPreserve ¶
FillPreserve schedules a fill rasterization of the current path without clearing it.
func (*Line) MoveTo ¶
MoveTo starts a new subpath at (x, y). Closes the previous fill subpath if needed.
func (*Line) NewSubPath ¶
NewSubPath ends the current fill subpath and prepares for a new one.
func (*Line) QuadraticTo ¶
QuadraticTo adds a quadratic Bézier curve and discretizes it for dashing.
func (*Line) ResetMatrix ¶
ResetMatrix resets the transform matrix to identity.
func (*Line) SetDashOffset ¶
SetDashOffset sets the initial dash offset along the path.
func (*Line) SetFillPattern ¶
SetFillPattern sets the pattern used to paint fills.
func (*Line) SetFillRule ¶
SetFillRule sets the fill rule used to determine interior.
func (*Line) SetLineCap ¶
SetLineCap sets the cap style for strokes.
func (*Line) SetLineJoin ¶
SetLineJoin sets the join style for strokes.
func (*Line) SetLineWidth ¶
SetLineWidth sets the stroke width in pixels.
func (*Line) SetStrokePattern ¶
SetStrokePattern sets the pattern used to paint strokes.
func (*Line) StrokePreserve ¶
StrokePreserve schedules a stroke rasterization of the current path without clearing it.
type LineJoin ¶
type LineJoin int
LineJoin defines how the junction between two line segments is rendered.
type Point ¶
type Point struct {
X, Y float64
// contains filtered or unexported fields
}
Point represents a 2D coordinate or vector using float64 precision. It also holds an optional color used for rendering operations.
func CubicBezier ¶
CubicBezier discretizes a cubic Bézier into a sequence of points.
func QuadraticBezier ¶
QuadraticBezier discretizes a quadratic Bézier into a sequence of points.
func (*Point) Angle ¶
Angle returns the angle in radians between vectors p and q, computed using the dot product. Returns 0 if either vector has zero length.
func (*Point) Distance ¶
Distance returns the Euclidean distance between the current Point (p) and another Point (q).
func (*Point) Dot ¶
Dot returns the dot product of p and q, commonly used for angle and projection calculations.
func (*Point) Draw ¶
Draw renders a single pixel representing the Point’s location on the given overlay image, if it lies within bounds. The base image parameter is ignored for consistency with other Draw methods.
func (*Point) Fixed ¶
Fixed converts the Point to a fixed-point coordinate (26.6 format). Commonly used for subpixel-accurate rendering and rasterization.
func (*Point) Interpolate ¶
Interpolate returns a linearly interpolated point between p and q. The parameter t (0–1) determines the position: t=0 → p, t=1 → q.
func (*Point) Length ¶
Length returns the magnitude of the vector represented by the Point (distance from the origin to the point).
func (*Point) Normalize ¶
Normalize returns a unit vector (length = 1) pointing in the same direction as p. If p is zero-length, it returns (0, 0).
func (*Point) Rotate ¶
Rotate returns a new Point rotated around the origin by the given angle in radians. Positive values rotate counterclockwise.
func (*Point) Scale ¶
Scale returns a new Point scaled by the specified factor. Both X and Y coordinates are multiplied by factor.
type PositionType ¶
type PositionType int
PositionType indicates whether an item participates in normal layout flow.
const ( // PosRelative participates in normal flow (default). PosRelative PositionType = iota // PosAbsolute is removed from flow and positioned relative to the container padding box. PosAbsolute )
type Rectangle ¶
type Rectangle struct {
// contains filtered or unexported fields
}
Rectangle represents a drawable rectangle with per-corner rounding, fill, and stroke.
func NewRectangle ¶
NewRectangle creates a new rectangle with the given position and size.
func (*Rectangle) AddEffect ¶
AddEffect attaches a visual effect to the rectangle rendering pipeline.
The added effect will be stored inside the internal effect container `t.effects` and applied automatically during rendering:
- Pre-effects (e.IsPre() == true) execute before text drawing.
- Post-effects (e.IsPre() == false) execute after text drawing.
This allows chaining multiple visual transformations such as drop shadows, layer blurs, and noise filters.
Example:
rectangle.AddEffect(effects.NewDropShadow(0, 4, 4, 0, colors.Black, 0.25))
func (*Rectangle) AddEffects ¶
AddEffects attaches multiple visual effects to the pipeline.
func (*Rectangle) Draw ¶
Draw renders the rectangle with stroke alignment (inside, center, outside).
func (*Rectangle) SetCornerRadii ¶
SetCornerRadii sets per-corner radii: top-left, top-right, bottom-right, bottom-left.
func (*Rectangle) SetFillColor ¶
SetFillColor sets solid fill colorPattern.
func (*Rectangle) SetFillPattern ¶
SetFillPattern sets fill pattern.
func (*Rectangle) SetLineWidth ¶
SetLineWidth sets stroke width.
func (*Rectangle) SetPosition ¶
SetPosition sets the rectangle’s top-left corner.
func (*Rectangle) SetRoundedSteps ¶
SetRoundedSteps sets resolution of rounded arcs.
func (*Rectangle) SetStrokeColor ¶
SetStrokeColor sets solid stroke colorPattern.
func (*Rectangle) SetStrokePattern ¶
SetStrokePattern sets stroke pattern.
func (*Rectangle) SetStrokePosition ¶
func (r *Rectangle) SetStrokePosition(pos StrokePosition) *Rectangle
SetStrokePosition defines whether stroke is drawn inside, centered, or outside the border.
type Resizable ¶
type Resizable interface {
SetSize(w, h int)
}
Resizable is an optional capability: layout passes resolved size to the shape.
type Shape ¶
type Shape interface {
// Draw renders the shape’s visual representation into the given
// base and overlay image buffers. Implementations decide how to
// blend, composite, or otherwise use the provided layers.
Draw(base, overlay *image.RGBA)
}
Shape defines the minimal contract for any drawable visual entity or rendering instruction in the system.
Implementations of Shape are responsible for drawing visual output onto one or both of the provided RGBA image buffers. These buffers represent different layers in the rendering pipeline:
- base: The read-only background image. Can be used for sampling or blending reference data but should not be modified directly.
- overlay: The active target buffer where the shape should render its visual output.
The drawing function should confine its modifications to the intended area of the shape and must not alter unrelated pixels outside its bounds. Each Shape implementation defines its own compositing, blending, and color behavior.
type StrokePosition ¶
type StrokePosition int
StrokePosition defines stroke alignment relative to the rectangle border.
const ( StrokeInside StrokePosition = iota StrokeCenter StrokeOutside )
func (StrokePosition) Outset ¶
func (s StrokePosition) Outset(lineWidth float64) float64
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text describes a multi-line text block capable of wrapping, aligning, scaling, and applying stroke/fill effects.
Features include:
- Word or symbol wrapping with optional hyphenation.
- Left/center/right alignment within fixed width or anchor-based layout.
- Progressive per-line scaling for dynamic typography.
- Automatic or manual line spacing.
- Pattern or gradient fill based on canvas coordinates.
- Morphological stroke expansion using alpha dilation.
- Pre- and post-processing effects via a flexible effect container.
func NewText ¶
NewText constructs a Text instance with default configuration. Defaults:
- WrapByWord and AlignTextLeft
- No stroke or fill pattern
- lineSpacing = 0 → automatic by font metrics
- maxWidth = 0 → no wrapping, anchor-based alignment
func (*Text) AddEffect ¶
AddEffect adds a single post-processing effect to the text rendering pipeline.
func (*Text) AddEffects ¶
AddEffects appends multiple effects to the rendering pipeline in order.
func (*Text) Draw ¶
Draw renders the text block into the given base and overlay images. The method performs optional stroke, fill, and post-processing effects.
func (*Text) SetColorPattern ¶
SetColorPattern applies a pattern or gradient fill for text glyphs.
func (*Text) SetLineSpacing ¶
SetLineSpacing defines custom spacing as a percentage of line height.
func (*Text) SetMaxLines ¶
SetMaxLines limits the number of rendered lines. Zero means no limit.
func (*Text) SetMaxWidth ¶
SetMaxWidth limits the maximum text box width in pixels. A value of 0 disables wrapping and aligns relative to anchor coordinates.
func (*Text) SetPosition ¶
SetPosition updates the anchor coordinates of the text block.
func (*Text) SetScaleStep ¶
SetScaleStep applies a per-line font size increment (in points). Positive values enlarge text progressively; negative values shrink it.
func (*Text) SetSolidColor ¶
SetSolidColor applies a uniform color fill by generating a solid pattern.
func (*Text) SetStrokeWithColor ¶
SetStrokeWithColor defines a stroke using a solid color pattern.
func (*Text) SetStrokeWithPattern ¶
SetStrokeWithPattern defines a stroke using a color or gradient pattern.
func (*Text) SetWrapMode ¶
SetWrapMode changes wrapping behavior without modifying the hyphenation symbol.
func (*Text) SetWrapSymbol ¶
SetWrapSymbol defines a custom symbol used during symbol-based wrapping. Falls back to "-" when an empty string is provided.
type Vector2 ¶
type Vector2 = Point
Vector2 is an alias for Point, used for semantic clarity when representing mathematical vectors instead of geometric coordinates.