render

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 23 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
)

Variables

View Source
var (
	DefaultFontFace  = "tb-8"
	DefaultFontColor = color.White
	MaxWidth         = 1000
)
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

surface fill gets line color dampened by this factor

View Source
var FrameHeight = DefaultFrameHeight
View Source
var FrameWidth = DefaultFrameWidth

Functions

func CheckImage

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

func DrawLine

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

TODO: use PolyLine from path.go instead

func GetFont added in v0.28.0

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

func GetFontList added in v0.28.0

func GetFontList() []string

func MaxFrameCount added in v0.17.1

func MaxFrameCount(widgets []Widget) int

Computes the maximum frame count of a slice of widgets.

func ModInt

func ModInt(a, m int) int

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

func PaintRoots

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

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

func PaintWidget added in v0.17.16

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

func ParseColor added in v0.15.3

func ParseColor(scol string) (color.Color, error)

Types

type Animation

type Animation struct {
	Widget
	Children []Widget
}

Animations 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() int

func (Animation) Paint

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

func (Animation) PaintBounds added in v0.17.16

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

type Box

type Box struct {
	Widget
	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() int

func (Box) Paint

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

func (Box) PaintBounds added in v0.17.16

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

type Circle

type Circle struct {
	Widget

	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() int

func (Circle) Paint

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

func (Circle) PaintBounds added in v0.17.16

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

	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() int

func (Column) Paint

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

func (Column) PaintBounds added in v0.17.16

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

type Image

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

func (*Image) FrameCount

func (p *Image) FrameCount() int

func (*Image) Init added in v0.4.2

func (p *Image) Init() error

func (*Image) InitFromGIF added in v0.16.4

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

func (*Image) InitFromImage added in v0.16.4

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

func (*Image) InitFromSVG added in v0.28.0

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

func (*Image) InitFromWebP added in v0.16.4

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 added in v0.17.16

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 Marquee

type Marquee struct {
	Widget
	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() int

func (Marquee) Paint

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

func (Marquee) PaintBounds added in v0.17.16

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

type Padding

type Padding struct {
	Widget

	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() int

func (Padding) Paint

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

func (Padding) PaintBounds added in v0.17.16

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 added in v0.23.0

type PieChart struct {
	Widget

	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 added in v0.23.0

func (c PieChart) FrameCount() int

func (PieChart) Paint added in v0.23.0

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

func (PieChart) PaintBounds added in v0.23.0

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

type Plot

type Plot struct {
	Widget

	// 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() int

func (Plot) Paint

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

func (Plot) PaintBounds added in v0.17.16

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

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 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
}

Every Widget tree has a Root.

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(solidBackground bool, opts ...RootPaintOption) []image.Image

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

type RootPaintOption added in v0.18.0

type RootPaintOption func(*Root)

func WithMaxFrameCount added in v0.18.1

func WithMaxFrameCount(max int) RootPaintOption

WithMaxFrameCount sets the maximum number of frames that will be rendered when calling `Paint`.

func WithMaxParallelFrames added in v0.18.0

func WithMaxParallelFrames(max int) RootPaintOption

WithMaxParallelFrames sets the maximum number of frames that will be painted in parallel.

By default, only `runtime.NumCPU()` frames are painted in parallel. Higher parallelism consumes more memory, and doesn't usually make sense since painting is CPU-bouond.

type Row

type Row struct {
	Widget

	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() int

func (Row) Paint

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

func (Row) PaintBounds added in v0.17.16

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

type Sequence added in v0.17.7

type Sequence struct {
	Widget

	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 = [
  animation.Transformation(...),
  animation.Transformation(...),
  ...
],

), EXAMPLE END

func (Sequence) FrameCount added in v0.17.7

func (s Sequence) FrameCount() int

func (Sequence) Paint added in v0.17.7

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

func (Sequence) PaintBounds added in v0.17.16

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

type Stack

type Stack struct {
	Widget
	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() int

func (Stack) Paint

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

func (Stack) PaintBounds added in v0.17.16

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

	Child  Widget
	Color  color.Color
	Width  int
	Height int
	// contains filtered or unexported fields
}

func (*Starfield) FrameCount

func (s *Starfield) FrameCount() int

func (*Starfield) Init added in v0.17.16

func (s *Starfield) Init() error

func (*Starfield) Paint

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

func (*Starfield) PaintBounds added in v0.17.16

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

type Text

type Text struct {
	Widget
	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() int

func (*Text) Init added in v0.4.2

func (t *Text) Init() error

func (*Text) Paint

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

func (*Text) PaintBounds added in v0.17.16

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 {
	Widget
	Path        Path
	TraceLength int
}

func (Tracer) FrameCount

func (t Tracer) FrameCount() int

func (Tracer) Paint

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

func (Tracer) PaintBounds added in v0.17.16

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

type Vector

type Vector struct {
	Widget

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

A 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() int

func (Vector) Paint

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

func (Vector) PaintBounds added in v0.17.16

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() 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 added in v0.4.2

type WidgetWithInit interface {
	Init() error
}

Widgets can require initialization

type WrappedText

type WrappedText struct {
	Widget

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

func (*WrappedText) Init added in v0.28.7

func (tw *WrappedText) Init() error

func (*WrappedText) Paint

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

func (*WrappedText) PaintBounds added in v0.17.16

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