render

package
v0.51.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 31 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 PaintRoots

func PaintRoots(width, height int, solidBackground bool, roots ...Root) []image.Image

PaintRoots draws >=1 Roots which must all have the same dimensions.

func PaintWidget

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

Types

type Animation

type Animation struct {
	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.

DOC(Children): Children to use as frames in the animation

EXAMPLE BEGIN

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"),
     ],
)

EXAMPLE END.

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

	X          float64     `starlark:"x,required"`
	Y          float64     `starlark:"y,required"`
	Radius     float64     `starlark:"radius,required"`
	StartAngle float64     `starlark:"start_angle,required"`
	EndAngle   float64     `starlark:"end_angle,required"`
	Color      color.Color `starlark:"color,required"`
	Width      float64     `starlark:"width,required"`
}

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

DOC(X): The x-coordinate of the center of the arc. DOC(Y): The y-coordinate of the center of the arc. DOC(Radius): The radius of the arc. DOC(StartAngle): The starting angle of the arc, in radians. DOC(EndAngle): The ending angle of the arc, in radians. DOC(Color): The color of the arc. DOC(Width): The width of the arc.

EXAMPLE BEGIN render.Arc(

x = 10,
y = 10,
radius = 10,
start_angle = 0,
end_angle = 3.14 * 1.5,
width = 3,
color = "#0ff",

) EXAMPLE END.

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         Widget
	Width, Height int
	Padding       int
	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`).

DOC(Child): Child to center inside box DOC(Width): Limits Box width DOC(Height): Limits Box height DOC(Padding): Padding around the child widget DOC(Color): Background color

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Child    Widget
	Color    color.Color `starlark:"color, required"`
	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.

DOC(Child): Widget to place in the center of the circle DOC(Color): Fill color DOC(Diameter): Diameter of the circle

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Children   []Widget `starlark:"children,required"`
	MainAlign  string   `starlark:"main_align"`
	CrossAlign string   `starlark:"cross_align"`
	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

DOC(Children): Child widgets to lay out DOC(Expanded): Column should expand to fill all available vertical space DOC(MainAlign): Alignment along vertical main axis DOC(CrossAlign): Alignment along horizontal cross axis

EXAMPLE BEGIN

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 END

EXAMPLE BEGIN

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"),
    ],
)

EXAMPLE END.

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 {
	EmojiStr      string `starlark:"emoji,required"`
	Width, 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.

DOC(Emoji): The Unicode emoji sequence to render DOC(Width): Scale emoji to this width DOC(Height): Scale emoji to this height

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Src           string `starlark:"src,required"`
	Width, Height int
	Delay         int `starlark:"delay,readonly"`
	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.

DOC(Src): Binary image data or SVG text DOC(Width): Scale image to this width DOC(Height): Scale image to this height DOC(Delay): (Read-only) Frame delay in ms, for animated GIFs DOC(HoldFrames): Number of render frames to hold each animation frame, default is 1.

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

	X1    float64     `starlark:"x1,required"`
	Y1    float64     `starlark:"y1,required"`
	X2    float64     `starlark:"x2,required"`
	Y2    float64     `starlark:"y2,required"`
	Color color.Color `starlark:"color,required"`
	Width float64     `starlark:"width,required"`
}

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

DOC(X1): The x-coordinate of the starting point. DOC(Y1): The y-coordinate of the starting point. DOC(X2): The x-coordinate of the ending point. DOC(Y2): The y-coordinate of the ending point. DOC(Color): The color of the line. DOC(Width): The width of the line.

EXAMPLE BEGIN render.Line(

x1 = 0,
y1 = 0,
x2 = 63,
y2 = 31,
width = 1,
color = "#fff",

) EXAMPLE END.

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 {
	Child           Widget `starlark:"child,required"`
	Width           int    `starlark:"width"`
	Height          int    `starlark:"height"`
	OffsetStart     int    `starlark:"offset_start"`
	OffsetEnd       int    `starlark:"offset_end"`
	ScrollDirection string `starlark:"scroll_direction"`
	Align           string `starlark:"align"`
	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

DOC(Child): Widget to potentially scroll DOC(Width): Width of the Marquee, required for horizontal DOC(Height): Height of the Marquee, required for vertical DOC(OffsetStart): Position of child at beginning of animation DOC(OffsetEnd): Position of child at end of animation DOC(ScrollDirection): Direction to scroll, 'vertical' or 'horizontal', default is horizontal DOC(Align): Alignment when contents fit on screen, 'start', 'center' or 'end', default is start DOC(Delay): Delay the scroll of the animation by a certain number of frames, default is 0

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Child    Widget `starlark:"child,required"`
	Pad      Insets
	Expanded bool
	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.

DOC(Child): The Widget to place padding around DOC(Expanded): This is a confusing parameter DOC(Pad): Padding around the child DOC(Color): Background color.

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 {
	Colors   []color.Color `starlark:"colors, required"`
	Weights  []float64     `starlark:"weights, required"`
	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.

DOC(Colors): List of color hex codes DOC(Weights): List of numbers corresponding to the relative size of each color DOC(Diameter): Diameter of the circle

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	// Coordinates of points to plot
	Data [][2]float64 `starlark:"data,required"`

	// Overall size of the plot
	Width  int `starlark:"width,required"`
	Height int `starlark:"height,required"`

	// Primary line color
	Color color.Color `starlark:"color"`

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

	// Optional limit on X and Y axis
	XLim [2]float64 `starlark:"x_lim"`
	YLim [2]float64 `starlark:"y_lim"`

	// If true, also paint surface between line and X-axis
	Fill bool `starlark:"fill"`

	// Optional, default "line". If set to "scatter", the line connecting dots will not be drawn
	ChartType string `starlark:"chart_type"`

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

	// Optional 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.

DOC(Data): A list of 2-tuples of numbers DOC(Width): Limits Plot width DOC(Height): Limits Plot height DOC(Color): Line color, default is '#fff' DOC(ColorInverted): Line color for Y-values below 0 DOC(XLim): Limit X-axis to a range DOC(YLim): Limit Y-axis to a range DOC(Fill): Paint surface between line and X-axis DOC(FillColor): Fill color for Y-values above 0 DOC(FillColorInverted): Fill color for Y-values below 0 DOC(ChartType): Specifies the type of chart to render, "scatter" or "line", default is "line"

EXAMPLE BEGIN

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,
)

EXAMPLE END.

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

	Vertices    []Point     `starlark:"vertices,required"`
	FillColor   color.Color `starlark:"fill_color"`
	StrokeColor color.Color `starlark:"stroke_color"`
	StrokeWidth float64     `starlark:"stroke_width"`
}

Polygon draws a polygon.

DOC(Vertices): A list of (x, y) tuples representing the vertices of the polygon. DOC(FillColor): The color used to fill the polygon. DOC(StrokeColor): The color used to draw the polygon's stroke. DOC(StrokeWidth): The width of the polygon's stroke.

EXAMPLE BEGIN render.Polygon(

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

) EXAMPLE END.

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 {
	Child             Widget `starlark:"child,required"`
	Delay             int32  `starlark:"delay"`
	MaxAge            int32  `starlark:"max_age"`
	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.

DOC(Child): Widget to render DOC(Delay): Frame delay in milliseconds DOC(MaxAge): Expiration time in seconds DOC(ShowFullAnimation): Request animation is shown in full, regardless of app cycle speed.

func (Root) Paint

func (r Root) Paint(width, height int, solidBackground bool, opts ...RootPaintOption) []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

type Row

type Row struct {
	Children   []Widget `starlark:"children,required"`
	MainAlign  string   `starlark:"main_align"`
	CrossAlign string   `starlark:"cross_align"`
	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

DOC(Children): Child widgets to lay out DOC(Expanded): Row should expand to fill all available horizontal space DOC(MainAlign): Alignment along horizontal main axis DOC(CrossAlign): Alignment along vertical cross axis

EXAMPLE BEGIN

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 END

EXAMPLE BEGIN

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"),
    ],
)

EXAMPLE END.

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 {
	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.

DOC(Children): List of child widgets

EXAMPLE BEGIN

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"),
    ],
)

EXAMPLE END.

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 {
	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.

DOC(Children): Widgets to stack

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Content string `starlark:"content,required"`
	Font    string
	Height  int
	Offset  int
	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.

DOC(Content): The text string to draw DOC(Font): Desired font face DOC(Height): Limits height of the area on which text is drawn DOC(Offset): Shifts position of text vertically. DOC(Color): Desired font color

EXAMPLE BEGIN

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

EXAMPLE END.

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 {
	Content     string `starlark:"content,required"`
	Font        string
	Height      int
	Width       int
	LineSpacing int
	Color       color.Color
	Align       string
	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

DOC(Content): The text string to draw DOC(Font): Desired font face DOC(Height): Limits height of the area on which text may be drawn DOC(Width): Limits width of the area on which text may be drawn DOC(LineSpacing): Controls spacing between lines DOC(Color): Desired font color DOC(Align): Text Alignment DOC(WordBreak): If true, long words that exceed the width will be broken to fit EXAMPLE BEGIN

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

EXAMPLE END.

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