render

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFrameWidth is the normal width for a frame.
	DefaultFrameWidth = 64

	// DefaultFrameHeight is the normal height for a frame.
	DefaultFrameHeight = 32

	// DefaultMaxFrameCount is the default maximum number of frames to render.
	DefaultMaxFrameCount = 2000
)
View Source
const (
	DefaultFontFace   = "tb-8"
	DefaultFontFace2x = "terminus-16"
	MaxWidth          = 1000
)
View Source
const (
	AlignLeft   = "left"
	AlignCenter = "center"
	AlignRight  = "right"
)

Variables

View Source
var DefaultFontColor = color.White
View Source
var DefaultPalette = map[string]color.RGBA{
	"r": {0xff, 0, 0, 0xff},
	"g": {0, 0xff, 0, 0xff},
	"b": {0, 0, 0xff, 0xff},
	"w": {0xff, 0xff, 0xff, 0xff},
	".": {0, 0, 0, 0},
	"x": {0, 0, 0, 0xff},
}
View Source
var DefaultPlotColor = color.RGBA{0xff, 0xff, 0xff, 0xff}
View Source
var FillDampFactor uint8 = 0x55

FillDampFactor determines how much surface fill gets line color dampened.

View Source
var (
	FontCacheTTL = time.Hour
)

Functions

func CheckImage

func CheckImage(expected []string, actual image.Image) error

func DrawLine

func DrawLine(dc *gg.Context, x0, y0, x1, y1 int)

DrawLine draws a line from (x0, y0) to (x1, y1).

TODO: use PolyLine from path.go instead.

func GetFont

func GetFont(name string) (font.Face, error)

func GetFontList

func GetFontList() ([]string, error)

func MaxFrameCount

func MaxFrameCount(widgets []Widget, bounds image.Rectangle) int

MaxFrameCount computes the maximum frame count of a slice of widgets.

func ModInt

func ModInt(a, m int) int

ModInt computes a (mod m). Useful for handling frameIdx > num available frames in Widget.Paint().

func PaintWidget

func PaintWidget(w Widget, bounds image.Rectangle, frameIdx int) image.Image

Types

type Animation

type Animation struct {
	// Children to use as frames in the animation
	Children []Widget
}

Animation turns a list of children into an animation, where each child is a frame.

FIXME: Behaviour when children themselves are animated is a bit weird. Think and fix.

Example:

render.Animation(
     children=[
          render.Box(width=10, height=10, color="#300"),
          render.Box(width=12, height=12, color="#500"),
          render.Box(width=14, height=14, color="#700"),
          render.Box(width=16, height=16, color="#900"),
          render.Box(width=18, height=18, color="#b00"),
     ],
)

func (Animation) FrameCount

func (a Animation) FrameCount(bounds image.Rectangle) int

func (Animation) Paint

func (a Animation) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Animation) PaintBounds

func (a Animation) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Arc added in v0.50.0

type Arc struct {
	Widget

	// The x-coordinate of the center of the arc.
	X float64 `starlark:"x,required"`
	// The y-coordinate of the center of the arc.
	Y float64 `starlark:"y,required"`
	// The radius of the arc.
	Radius float64 `starlark:"radius,required"`
	// The starting angle of the arc, in radians.
	StartAngle float64 `starlark:"start_angle,required"`
	// The ending angle of the arc, in radians.
	EndAngle float64 `starlark:"end_angle,required"`
	// The color of the arc.
	Color color.Color `starlark:"color,required"`
	// The width of the arc.
	Width float64 `starlark:"width,required"`
	// Enables antialiased stroke rendering.
	AntiAlias bool `starlark:"antialias"`
}

Arc draws an arc. The arc is centered at (x, y).

Example:

render.Arc(
    x = 10,
    y = 10,
    radius = 10,
    start_angle = 0,
    end_angle = 3.14 * 1.5,
    width = 3,
    color = "#0ff",
)

func (Arc) FrameCount added in v0.50.0

func (a Arc) FrameCount(bounds image.Rectangle) int

func (Arc) Paint added in v0.50.0

func (a Arc) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Arc) PaintBounds added in v0.50.0

func (a Arc) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Box

type Box struct {
	// Child to center inside box
	Child Widget
	// Limits Box width
	Width int
	// Limits Box height
	Height int
	// Padding around the child widget
	Padding int
	// Background color
	Color color.Color
}

A Box is a rectangular widget that can hold a child widget.

Boxes are transparent unless `color` is provided. They expand to fill all available space, unless `width` and/or `height` is provided. Boxes can have a `child`, which will be centered in the box, and the child can be padded (via `padding`).

Example:

render.Box(
    color="#00f",
    child=render.Box(
        width=20,
        height=10,
        color="#f00",
    )
)

func (Box) FrameCount

func (b Box) FrameCount(bounds image.Rectangle) int

func (Box) Paint

func (b Box) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Box) PaintBounds

func (b Box) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Circle

type Circle struct {
	// Widget to place in the center of the circle
	Child Widget
	// Fill color
	Color color.Color `starlark:"color, required"`
	// Diameter of the circle
	Diameter int `starlark:"diameter,required"`
}

Circle draws a circle with the given `diameter` and `color`. If a `child` widget is provided, it is drawn in the center of the circle.

Example:

render.Circle(
    color="#666",
    diameter=30,
    child=render.Circle(color="#0ff", diameter=10),
)

func (Circle) FrameCount

func (c Circle) FrameCount(bounds image.Rectangle) int

func (Circle) Paint

func (c Circle) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Circle) PaintBounds

func (c Circle) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type CircularPath

type CircularPath struct {
	Radius int
	// contains filtered or unexported fields
}

CircularPath draws a circle XXX: from where, in what direction?

func (*CircularPath) Length

func (cp *CircularPath) Length() int

func (*CircularPath) Point

func (cp *CircularPath) Point(i int) (int, int)

func (*CircularPath) Size

func (cp *CircularPath) Size() (int, int)

type Column

type Column struct {
	// Child widgets to lay out
	Children []Widget `starlark:"children,required"`
	// Alignment along vertical main axis
	MainAlign string `starlark:"main_align"`
	// Alignment along horizontal cross axis
	CrossAlign string `starlark:"cross_align"`
	// Column should expand to fill all available vertical space
	Expanded bool
}

Column lays out and draws its children vertically (in a column).

By default, a Column is as small as possible, while still holding all its children. However, if `expanded` is set, the Column will fill all available space vertically. The width of a Column is always that of its widest child.

Alignment along the vertical main axis is controlled by passing one of the following `main_align` values: - `"start"`: place children at the beginning of the column - `"end"`: place children at the end of the column - `"center"`: place children in the middle of the column - `"space_between"`: place equal space between children - `"space_evenly"`: equal space between children and before/after first/last child - `"space_around"`: equal space between children, and half of that before/after first/last child

Alignment along the horizontal cross axis is controlled by passing one of the following `cross_align` values: - `"start"`: place children at the left - `"end"`: place children at the right - `"center"`: place children in the center

Example:

render.Column(
    children=[
         render.Box(width=10, height=8, color="#a00"),
         render.Box(width=14, height=6, color="#0a0"),
         render.Box(width=16, height=4, color="#00a"),
    ],
)

Example:

render.Column(
    expanded=True,
    main_align="space_around",
    cross_align="center",
    children=[
        render.Box(width=10, height=8, color="#a00"),
        render.Box(width=14, height=6, color="#0a0"),
        render.Box(width=16, height=4, color="#00a"),
    ],
)

func (Column) FrameCount

func (c Column) FrameCount(bounds image.Rectangle) int

func (Column) Paint

func (c Column) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Column) PaintBounds

func (c Column) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Emoji

type Emoji struct {
	// The Unicode emoji sequence to render
	EmojiStr string `starlark:"emoji,required"`
	// Scale emoji to this width
	Width int
	// Scale emoji to this height
	Height int
	// contains filtered or unexported fields
}

Emoji renders a single emoji at a specified height, maintaining aspect ratio. This allows for rendering emojis much larger than the standard 10x10 pixel size used in text rendering.

Example:

render.Emoji(emoji="😀", height=32) # Large smiley face

func (Emoji) FrameCount

func (e Emoji) FrameCount(bounds image.Rectangle) int

func (*Emoji) Init

func (e *Emoji) Init(*starlark.Thread) error

func (*Emoji) Paint

func (e *Emoji) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*Emoji) PaintBounds

func (e *Emoji) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

func (*Emoji) Size

func (e *Emoji) Size() (int, int)

type Image

type Image struct {
	// Binary image data or SVG text
	Src string `starlark:"src,required"`
	// Scale image to this width
	Width int
	// Scale image to this height
	Height int
	// (Read-only) Frame delay in ms, for animated GIFs
	Delay int `starlark:"delay,readonly"`
	// Number of render frames to hold each animation frame, default is 1.
	HoldFrames int `starlark:"hold_frames"`
	// contains filtered or unexported fields
}

Image renders the binary image data passed via `src`. Supported formats include PNG, JPEG, GIF, and SVG.

If `width` or `height` are set, the image will be scaled accordingly, with nearest neighbor interpolation. Otherwise the image's original dimensions are used.

If the image data encodes an animated GIF, the Image instance will also be animated. Frame delay (in milliseconds) can be read from the `delay` attribute.

func (*Image) FrameCount

func (p *Image) FrameCount(bounds image.Rectangle) int

func (*Image) Init

func (p *Image) Init(*starlark.Thread) error

func (*Image) InitFromGIF

func (p *Image) InitFromGIF(data []byte) error

func (*Image) InitFromImage

func (p *Image) InitFromImage(data []byte) error

func (*Image) InitFromSVG

func (p *Image) InitFromSVG(data []byte) error

func (*Image) InitFromWebP

func (p *Image) InitFromWebP(data []byte) error

func (*Image) Paint

func (p *Image) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*Image) PaintBounds

func (p *Image) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

func (*Image) Size

func (p *Image) Size() (int, int)

type ImageChecker

type ImageChecker struct {
	Palette map[string]color.RGBA
}

func (ImageChecker) Check

func (ic ImageChecker) Check(expected []string, actual image.Image) error

func (ImageChecker) PrintDiff

func (ic ImageChecker) PrintDiff(expected []string, actual image.Image)

func (ImageChecker) PrintImage

func (ic ImageChecker) PrintImage(im image.Image)

type Insets

type Insets struct {
	Left   int
	Top    int
	Right  int
	Bottom int
}

type Line added in v0.50.0

type Line struct {
	Widget

	// The x-coordinate of the starting point.
	X1 float64 `starlark:"x1,required"`
	// The y-coordinate of the starting point.
	Y1 float64 `starlark:"y1,required"`
	// The x-coordinate of the ending point.
	X2 float64 `starlark:"x2,required"`
	// The y-coordinate of the ending point.
	Y2 float64 `starlark:"y2,required"`
	// The color of the line.
	Color color.Color `starlark:"color,required"`
	// The width of the line.
	Width float64 `starlark:"width,required"`
	// Enables antialiased stroke rendering.
	AntiAlias bool `starlark:"antialias"`
}

Line draws a line from (x1, y1) to (x2, y2).

Example:

render.Line(
    x1 = 0,
    y1 = 0,
    x2 = 63,
    y2 = 31,
    width = 1,
    color = "#fff",
)

func (Line) FrameCount added in v0.50.0

func (l Line) FrameCount(bounds image.Rectangle) int

func (Line) Paint added in v0.50.0

func (l Line) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Line) PaintBounds added in v0.50.0

func (l Line) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Marquee

type Marquee struct {
	// Widget to potentially scroll
	Child Widget `starlark:"child,required"`
	// Width of the Marquee, required for horizontal
	Width int `starlark:"width"`
	// Height of the Marquee, required for vertical
	Height int `starlark:"height"`
	// Position of child at beginning of animation
	OffsetStart int `starlark:"offset_start"`
	// Position of child at end of animation
	OffsetEnd int `starlark:"offset_end"`
	// Direction to scroll, 'vertical' or 'horizontal', default is horizontal
	ScrollDirection string `starlark:"scroll_direction"`
	// Alignment when contents fit on screen, 'start', 'center' or 'end', default is start
	Align string `starlark:"align"`
	// Delay the scroll of the animation by a certain number of frames, default is 0
	Delay int `starlark:"delay"`
}

Marquee scrolls its child horizontally or vertically.

The `scroll_direction` will be 'horizontal' and will scroll from right to left if left empty, if specified as 'vertical' the Marquee will scroll from bottom to top.

In horizontal mode the height of the Marquee will be that of its child, but its `width` must be specified explicitly. In vertical mode the width will be that of its child but the `height` must be specified explicitly.

If the child's width fits fully, it will not scroll.

The `offset_start` and `offset_end` parameters control the position of the child in the beginning and the end of the animation.

Alignment for a child that fits fully along the horizontal/vertical axis is controlled by passing one of the following `align` values: - `"start"`: place child at the left/top - `"end"`: place child at the right/bottom - `"center"`: place child at the center

Example:

render.Marquee(
    width=64,
    child=render.Text("this won't fit in 64 pixels"),
    offset_start=5,
    offset_end=32,
)

func (Marquee) FrameCount

func (m Marquee) FrameCount(bounds image.Rectangle) int

func (Marquee) Paint

func (m Marquee) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Marquee) PaintBounds

func (m Marquee) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Padding

type Padding struct {
	// The Widget to place padding around
	Child Widget `starlark:"child,required"`
	// Padding around the child
	Pad Insets
	// This is a confusing parameter
	Expanded bool
	// Background color.
	Color color.Color
}

Padding places padding around its child.

If the `pad` attribute is a single integer, that amount of padding will be placed on all sides of the child. If it's a 4-tuple `(left, top, right, bottom)`, then padding will be placed on the sides accordingly.

func (Padding) FrameCount

func (p Padding) FrameCount(bounds image.Rectangle) int

func (Padding) Paint

func (p Padding) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Padding) PaintBounds

func (p Padding) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Path

type Path interface {
	Length() int
	Size() (int, int)
	Point(i int) (int, int)
}

type PathPoint

type PathPoint struct {
	X int
	Y int
}

type PieChart

type PieChart struct {
	// List of color hex codes
	Colors []color.Color `starlark:"colors, required"`
	// List of numbers corresponding to the relative size of each color
	Weights []float64 `starlark:"weights, required"`
	// Diameter of the circle
	Diameter int `starlark:"diameter,required"`
}

PieChart draws a circular pie chart of size `diameter`. It takes two arguments for the data: parallel lists `colors` and `weights` representing the shading and relative sizes of each data entry.

Example:

render.PieChart(
    colors = [ "#fff", "#0f0", "#00f" ],
    weights  = [ 180, 135, 45 ],
    diameter = 30,
)

func (PieChart) FrameCount

func (c PieChart) FrameCount(bounds image.Rectangle) int

func (PieChart) Paint

func (c PieChart) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (PieChart) PaintBounds

func (c PieChart) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Plot

type Plot struct {
	// A list of 2-tuples of numbers
	Data [][2]float64 `starlark:"data,required"`

	// Limits Plot width
	Width int `starlark:"width,required"`
	// Limits Plot height
	Height int `starlark:"height,required"`

	// Line color, default is '#fff'
	Color color.Color `starlark:"color"`

	// Line color for Y-values below 0
	ColorInverted color.Color `starlark:"color_inverted"`

	// Limit X-axis to a range
	XLim [2]float64 `starlark:"x_lim"`
	// Limit Y-axis to a range
	YLim [2]float64 `starlark:"y_lim"`

	// Paint surface between line and X-axis
	Fill bool `starlark:"fill"`

	// Specifies the type of chart to render, "scatter" or "line", default is "line"
	ChartType string `starlark:"chart_type"`

	// Fill color for Y-values above 0
	FillColor color.Color `starlark:"fill_color"`

	// Fill color for Y-values below 0
	FillColorInverted color.Color `starlark:"fill_color_inverted"`
	// contains filtered or unexported fields
}

Plot is a widget that draws a data series.

Example:

render.Plot(
    data = [
        (0, 3.35),
        (1, 2.15),
        (2, 2.37),
        (3, -0.31),
        (4, -3.53),
        (5, 1.31),
        (6, -1.3),
        (7, 4.60),
        (8, 3.33),
        (9, 5.92),
    ],
    width = 64,
    height = 32,
    color = "#0f0",
    color_inverted = "#f00",
    x_lim = (0, 9),
    y_lim = (-5, 7),
    fill = True,
)

func (Plot) FrameCount

func (p Plot) FrameCount(bounds image.Rectangle) int

func (Plot) Paint

func (p Plot) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Plot) PaintBounds

func (p Plot) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Point added in v0.50.0

type Point struct {
	X, Y float64
}

type PolyLine

type PolyLine struct {
	Vertices []PathPoint
	// contains filtered or unexported fields
}

PolyLine draws straight lines passing through a list of vertices.

func (*PolyLine) Length

func (pl *PolyLine) Length() int

func (*PolyLine) Point

func (pl *PolyLine) Point(i int) (int, int)

func (*PolyLine) Size

func (pl *PolyLine) Size() (int, int)

type Polygon added in v0.50.0

type Polygon struct {
	Widget

	// A list of (x, y) tuples representing the vertices of the polygon.
	Vertices []Point `starlark:"vertices,required"`
	// The color used to fill the polygon.
	FillColor color.Color `starlark:"fill_color"`
	// The color used to draw the polygon's stroke.
	StrokeColor color.Color `starlark:"stroke_color"`
	// The width of the polygon's stroke.
	StrokeWidth float64 `starlark:"stroke_width"`
	// Enables antialiased stroke rendering.
	AntiAlias bool `starlark:"antialias"`
}

Polygon draws a polygon.

Example:

render.Polygon(
    vertices = [(0, 0), (20, 0), (20, 10), (0, 10)],
    fill_color = "#00f",
    stroke_color = "#fff",
    stroke_width = 1,
)

func (Polygon) FrameCount added in v0.50.0

func (p Polygon) FrameCount(bounds image.Rectangle) int

func (Polygon) Paint added in v0.50.0

func (p Polygon) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Polygon) PaintBounds added in v0.50.0

func (p Polygon) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Root

type Root struct {
	// Widget to render
	Child Widget `starlark:"child,required"`
	// Frame delay in milliseconds
	Delay int32 `starlark:"delay"`
	// Expiration time in seconds
	MaxAge int32 `starlark:"max_age"`
	// Request animation is shown in full, regardless of app cycle speed.
	ShowFullAnimation bool `starlark:"show_full_animation"`
	// contains filtered or unexported fields
}

Root is the top level of every Widget tree.

The child widget, and all its descendants, will be drawn on a 64x32 canvas. Root places its child in the upper left corner of the canvas.

If the tree contains animated widgets, the resulting animation will run with _delay_ milliseconds per frame.

If the tree holds time sensitive information which must never be displayed past a certain point in time, pass _MaxAge_ to specify an expiration time in seconds. Display devices use this to avoid displaying stale data in the event of e.g. connectivity issues.

func (Root) Paint

func (r Root) Paint(ctx context.Context, width, height int, solidBackground bool, opts ...RootPaintOption) iter.Seq[image.Image]

Paint renders the child widget onto the frame. It doesn't do any resizing or alignment.

type RootPaintOption

type RootPaintOption func(*Root)

func WithMaxFrameCount

func WithMaxFrameCount(maxFrames int) RootPaintOption

WithMaxFrameCount sets the maximum number of frames that will be rendered. If a widget tree has more frames than this, the number of frames will be capped.

func WithMaxParallelFrames

func WithMaxParallelFrames(maxFrames int) RootPaintOption

WithMaxParallelFrames sets the maximum number of frames rendered concurrently. If <=0, Paint uses runtime.NumCPU().

type Row

type Row struct {
	// Child widgets to lay out
	Children []Widget `starlark:"children,required"`
	// Alignment along horizontal main axis
	MainAlign string `starlark:"main_align"`
	// Alignment along vertical cross axis
	CrossAlign string `starlark:"cross_align"`
	// Row should expand to fill all available horizontal space
	Expanded bool
}

Row lays out and draws its children horizontally (in a row).

By default, a Row is as small as possible, while still holding all its children. However, if `expanded` is set, the Row will fill all available space horizontally. The height of a Row is always that of its tallest child.

Alignment along the horizontal main axis is controlled by passing one of the following `main_align` values: - `"start"`: place children at the beginning of the row - `"end"`: place children at the end of the row - `"center"`: place children in the middle of the row - `"space_between"`: place equal space between children - `"space_evenly"`: equal space between children and before/after first/last child - `"space_around"`: equal space between children, and half of that before/after first/last child

Alignment along the vertical cross axis is controlled by passing one of the following `cross_align` values: - `"start"`: place children at the top - `"end"`: place children at the bottom - `"center"`: place children at the center

Example:

render.Row(
    children=[
        render.Box(width=10, height=8, color="#a00"),
        render.Box(width=14, height=6, color="#0a0"),
        render.Box(width=16, height=4, color="#00a"),
    ],
)

Example:

render.Row(
    expanded=True,
    main_align="space_between",
    cross_align="end",
    children=[
        render.Box(width=10, height=8, color="#a00"),
        render.Box(width=14, height=6, color="#0a0"),
        render.Box(width=16, height=4, color="#00a"),
    ],
)

func (Row) FrameCount

func (r Row) FrameCount(bounds image.Rectangle) int

func (Row) Paint

func (r Row) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Row) PaintBounds

func (r Row) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Sequence

type Sequence struct {
	// List of child widgets
	Children []Widget `starlark:"children,required"`
}

Sequence renders a list of child widgets in sequence.

Each child widget is rendered for the duration of its frame count, then the next child wiget in the list will be rendered and so on.

It comes in quite useful when chaining animations. If you want to know more about that, go check out the [animation](animation.md) documentation.

Example:

render.Sequence(
    children = [
        render.Box(width=10, height=10, color="#f00"),
        render.Box(width=10, height=10, color="#0f0"),
        render.Box(width=10, height=10, color="#00f"),
    ],
)

func (Sequence) FrameCount

func (s Sequence) FrameCount(bounds image.Rectangle) int

func (Sequence) Paint

func (s Sequence) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Sequence) PaintBounds

func (s Sequence) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Stack

type Stack struct {
	// Widgets to stack
	Children []Widget `starlark:"children,required"`
}

Stack draws its children on top of each other.

Just like a stack of pancakes, except with Widgets instead of pancakes. The Stack will be given a width and height sufficient to fit all its children.

Example:

render.Stack(
    children=[
        render.Box(width=50, height=25, color="#911"),
        render.Text("hello there"),
        render.Box(width=4, height=32, color="#119"),
    ],
)

func (Stack) FrameCount

func (s Stack) FrameCount(bounds image.Rectangle) int

func (Stack) Paint

func (s Stack) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Stack) PaintBounds

func (s Stack) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Star

type Star struct {
	X     float64
	Y     float64
	D     float64
	V     float64
	PrevX float64
	PrevY float64
}

func (*Star) Tick

func (s *Star) Tick()

type Starfield

type Starfield struct {
	Child  Widget
	Color  color.Color
	Width  int
	Height int
	// contains filtered or unexported fields
}

func (*Starfield) FrameCount

func (s *Starfield) FrameCount(bounds image.Rectangle) int

func (*Starfield) Init

func (s *Starfield) Init(*starlark.Thread) error

func (*Starfield) Paint

func (s *Starfield) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*Starfield) PaintBounds

func (s *Starfield) PaintBounds(bounds image.Rectangle, frameIdx int) image.Image

type Text

type Text struct {
	// The text string to draw
	Content string `starlark:"content,required"`
	// Desired font face
	Font string
	// Limits height of the area on which text is drawn
	Height int
	// Shifts position of text vertically.
	Offset int
	// Desired font color
	Color color.Color
	// contains filtered or unexported fields
}

Text draws a string of text on a single line.

By default, the text will use the "tb-8" font, but other fonts can be chosen via the `font` attribute. The `height` and `offset` parameters allow fine tuning of the vertical layout of the string. Take a look at the [font documentation](fonts.md) for more information.

Example:

render.Text(content="Tidbyt!", color="#099")

func (Text) FrameCount

func (t Text) FrameCount(bounds image.Rectangle) int

func (*Text) Init

func (t *Text) Init(thread *starlark.Thread) error

func (*Text) Paint

func (t *Text) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*Text) PaintBounds

func (t *Text) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

func (*Text) Size

func (t *Text) Size() (int, int)

type Tracer

type Tracer struct {
	Path        Path
	TraceLength int
}

func (Tracer) FrameCount

func (tr Tracer) FrameCount(bounds image.Rectangle) int

func (Tracer) Paint

func (t Tracer) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Tracer) PaintBounds

func (t Tracer) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Vector

type Vector struct {
	Children   []Widget
	MainAlign  string `starlark:"main_align"`
	CrossAlign string `starlark:"cross_align"`
	Expanded   bool
	Vertical   bool
}

Vector draws its children either vertically or horizontally (like a row or a column).

A vector has a main axis along which children are draw. The main axis is either horizontal or vertical (i.e. a row or a column). MainAlign controls how children are placed along this axis. CrossAlign controls placement orthogonally to the main axis.

func (Vector) FrameCount

func (v Vector) FrameCount(bounds image.Rectangle) int

func (Vector) Paint

func (v Vector) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (Vector) PaintBounds

func (v Vector) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Widget

type Widget interface {
	// PaintBounds Returns the bounds of the area that will actually be drawn to when Paint() is called
	PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle
	Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)
	FrameCount(bounds image.Rectangle) int
}

A Widget is a self-contained object that can render itself as an image.

type WidgetStaticSize

type WidgetStaticSize interface {
	Size() (int, int)
}

WidgetStaticSize has inherent size and width known before painting.

type WidgetWithInit

type WidgetWithInit interface {
	Init(thread *starlark.Thread) error
}

WidgetWithInit is an interface for widgets that require initialization.

type WrappedText

type WrappedText struct {
	// The text string to draw
	Content string `starlark:"content,required"`
	// Desired font face
	Font string
	// Limits height of the area on which text may be drawn
	Height int
	// Limits width of the area on which text may be drawn
	Width int
	// Controls spacing between lines
	LineSpacing int
	// Desired font color
	Color color.Color
	// Text alignment
	Align string
	// If true, long words that exceed the width will be broken to fit
	WordBreak bool
	// contains filtered or unexported fields
}

WrappedText draws multi-line text.

The optional `width` and `height` parameters limit the drawing area. If not set, WrappedText will use as much vertical and horizontal space as possible to fit the text.

Alignment of the text is controlled by passing one of the following `align` values: - `"left"`: align text to the left - `"center"`: align text in the center - `"right"`: align text to the right

Example:

render.WrappedText(
    content="this is a multi-line text string",
    width=50,
    color="#fa0",
)

func (*WrappedText) FrameCount

func (tw *WrappedText) FrameCount(bounds image.Rectangle) int

func (*WrappedText) Init

func (tw *WrappedText) Init(thread *starlark.Thread) error

func (*WrappedText) Paint

func (tw *WrappedText) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*WrappedText) PaintBounds

func (tw *WrappedText) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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