canvas

package module
v0.0.0-...-d640f43 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	Layers []*Layer
	// contains filtered or unexported fields
}

A Canvas is a drawable area on top of a screen interface.

func NewCanvas

func NewCanvas(screen Screen) Canvas

NewCanvas returns a new, uninitiated canvas object.

func (*Canvas) AddLayer

func (c *Canvas) AddLayer(layers ...*Layer)

AddLayer adds a new blank layer to a canvas object.

func (*Canvas) Draw

func (c *Canvas) Draw()

Draw will draw the contents of all layers to the screen.

type Cell

type Cell struct {
	Rune  rune
	Style tcell.Style
}

A Cell is a single point in a layer (a single char space on the screen)

func (*Cell) Set

func (c *Cell) Set(Rune rune, Style tcell.Style)

type Layer

type Layer struct {
	Grid                            [][]Cell
	Width, Height, X, Y, MaxX, MaxY int
}

A Layer is a drawable area in a canvas that carries its own origin coords and max boundaries.

func NewLayer

func NewLayer(width, height, x, y int) Layer

NewLayer creates a new layer with the specified size at the specified offset

func (*Layer) At

func (l *Layer) At(x, y int) *Cell

At returns the cell at the given coords, or nil if no such position exists

func (*Layer) Clear

func (l *Layer) Clear()

@todo write test Clear will set each of the runes in the layer to zero and the style to the default

func (*Layer) Each

func (l *Layer) Each(f func(*Cell))

Each will pass each cell in the grid to the provided closure

func (*Layer) InBounds

func (l *Layer) InBounds(x, y int) bool

InBounds returns true if cell is inside layer bounds

func (*Layer) Normalize

func (l *Layer) Normalize(minX, minY, maxX, maxY int) (nMinX, nMinY, nMaxX, nMaxY int)

Normalize will take a set of rect coords and normalize them to be legal layer coordinates.

func (*Layer) SetRune

func (l *Layer) SetRune(x, y int, r rune)

SetRune will set the Cell at the given coordinates with the provided rune.

func (*Layer) SetStyle

func (l *Layer) SetStyle(x, y int, style tcell.Style)

type Screen

type Screen interface {
	SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)
	Size() (int, int)
	Show()
	Fill(r rune, s tcell.Style)
}

Screen bridges methods used in a tcell screen to methods used by the tools. This allows for easier faking.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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