draw

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package draw provides functions that draw lines, shapes, etc on 2-D terminal like canvases.

Index

Constants

View Source
const DefaultBorderLineStyle = linestyle.Light

DefaultBorderLineStyle is the default value for the BorderLineStyle option.

View Source
const DefaultLineStyle = linestyle.Light

DefaultLineStyle is the default value for the HVLineStyle option.

View Source
const DefaultRectChar = ' '

DefaultRectChar is the default value for the RectChar option.

Variables

This section is empty.

Functions

func Border

func Border(c *canvas.Canvas, border image.Rectangle, opts ...BorderOption) error

Border draws a border on the canvas.

func BrailleCircle

func BrailleCircle(bc *braille.Canvas, mid image.Point, radius int, opts ...BrailleCircleOption) error

BrailleCircle draws an approximated circle with the specified mid point and radius. The mid point must be a valid pixel within the canvas. All the points that form the circle must fit into the canvas. The smallest valid radius is two.

func BrailleFill

func BrailleFill(bc *braille.Canvas, start image.Point, border []image.Point, opts ...BrailleFillOption) error

BrailleFill fills the braille canvas starting at the specified point. The function will not fill or cross over any points in the defined border. The start point must be in the canvas.

func BrailleLine

func BrailleLine(bc *braille.Canvas, start, end image.Point, opts ...BrailleLineOption) error

BrailleLine draws an approximated line segment on the braille canvas between the two provided points. Both start and end must be valid points within the canvas. Start and end can be the same point in which case only one pixel will be set on the braille canvas. The start or end coordinates must not be negative.

func HVLines

func HVLines(c *canvas.Canvas, lines []HVLine, opts ...HVLineOption) error

HVLines draws horizontal or vertical lines. Handles drawing of the correct characters for locations where any two lines cross (e.g. a corner, a T shape or a cross). Each line must be at least two cells long. Both start and end must be on the same horizontal (same X coordinate) or same vertical (same Y coordinate) line.

func Rectangle

func Rectangle(c *canvas.Canvas, r image.Rectangle, opts ...RectangleOption) error

Rectangle draws a filled rectangle on the canvas.

func ResizeNeeded

func ResizeNeeded(cvs *canvas.Canvas) error

ResizeNeeded draws an unicode character indicating that the canvas size is too small to draw meaningful content.

func Text

func Text(c *canvas.Canvas, text string, start image.Point, opts ...TextOption) error

Text prints the provided text on the canvas starting at the provided point.

func TrimText

func TrimText(text string, maxCells int, om OverrunMode) (string, error)

TrimText trims the provided text so that it fits the specified amount of cells.

func VerticalText

func VerticalText(c *canvas.Canvas, text string, start image.Point, opts ...VerticalTextOption) error

VerticalText prints the provided text on the canvas starting at the provided point. The text is printed in a vertical orientation, i.e:

H
e
l
l
o

Types

type BorderOption

type BorderOption interface {
	// contains filtered or unexported methods
}

BorderOption is used to provide options to Border().

func BorderCellOpts

func BorderCellOpts(opts ...cell.Option) BorderOption

BorderCellOpts sets options on the cells that create the border.

func BorderLineStyle

func BorderLineStyle(ls linestyle.LineStyle) BorderOption

BorderLineStyle sets the style of the line used to draw the border.

func BorderTitle

func BorderTitle(title string, overrun OverrunMode, opts ...cell.Option) BorderOption

BorderTitle sets a title for the border.

func BorderTitleAlign

func BorderTitleAlign(h align.Horizontal) BorderOption

BorderTitleAlign configures the horizontal alignment for the title.

type BrailleCircleOption

type BrailleCircleOption interface {
	// contains filtered or unexported methods
}

BrailleCircleOption is used to provide options to BrailleCircle.

func BrailleCircleArcOnly

func BrailleCircleArcOnly(startDegree, endDegree int) BrailleCircleOption

BrailleCircleArcOnly indicates that only a portion of the circle should be drawn. The arc will be between the two provided angles in degrees. Each angle must be in range 0 <= angle <= 360. Start and end must not be equal. The zero angle is on the X axis, angles grow counter-clockwise.

func BrailleCircleCellOpts

func BrailleCircleCellOpts(cOpts ...cell.Option) BrailleCircleOption

BrailleCircleCellOpts sets options on the cells that contain the circle. Cell options on a braille canvas can only be set on the entire cell, not per pixel.

func BrailleCircleClearPixels

func BrailleCircleClearPixels() BrailleCircleOption

BrailleCircleClearPixels changes the behavior of BrailleCircle, so that it clears the pixels belonging to the circle instead of setting them. Useful in order to "erase" a circle from the canvas as opposed to drawing one.

func BrailleCircleFilled

func BrailleCircleFilled() BrailleCircleOption

BrailleCircleFilled indicates that the drawn circle should be filled.

type BrailleFillOption

type BrailleFillOption interface {
	// contains filtered or unexported methods
}

BrailleFillOption is used to provide options to BrailleFill.

func BrailleFillCellOpts

func BrailleFillCellOpts(cOpts ...cell.Option) BrailleFillOption

BrailleFillCellOpts sets options on the cells that are set as part of filling shapes. Cell options on a braille canvas can only be set on the entire cell, not per pixel.

func BrailleFillClearPixels

func BrailleFillClearPixels() BrailleFillOption

BrailleFillClearPixels changes the behavior of BrailleFill, so that it clears the pixels instead of setting them. Useful in order to "erase" the filled area as opposed to drawing one.

type BrailleLineOption

type BrailleLineOption interface {
	// contains filtered or unexported methods
}

BrailleLineOption is used to provide options to BrailleLine().

func BrailleLineCellOpts

func BrailleLineCellOpts(cOpts ...cell.Option) BrailleLineOption

BrailleLineCellOpts sets options on the cells that contain the line. Cell options on a braille canvas can only be set on the entire cell, not per pixel.

func BrailleLineClearPixels

func BrailleLineClearPixels() BrailleLineOption

BrailleLineClearPixels changes the behavior of BrailleLine, so that it clears the pixels belonging to the line instead of setting them. Useful in order to "erase" a line from the canvas as opposed to drawing one.

type HVLine

type HVLine struct {
	// Start is the cell where the line starts.
	Start image.Point
	// End is the cell where the line ends.
	End image.Point
}

HVLine represents one horizontal or vertical line.

type HVLineOption

type HVLineOption interface {
	// contains filtered or unexported methods
}

HVLineOption is used to provide options to HVLine().

func HVLineCellOpts

func HVLineCellOpts(cOpts ...cell.Option) HVLineOption

HVLineCellOpts sets options on the cells that contain the line.

func HVLineStyle

func HVLineStyle(ls linestyle.LineStyle) HVLineOption

HVLineStyle sets the style of the line. Defaults to DefaultLineStyle.

type OverrunMode

type OverrunMode int

OverrunMode represents

const (
	// OverrunModeStrict verifies that the drawn value fits the canvas and
	// returns an error if it doesn't.
	OverrunModeStrict OverrunMode = iota

	// OverrunModeTrim trims the part of the text that doesn't fit.
	OverrunModeTrim

	// OverrunModeThreeDot trims the text and places the horizontal ellipsis
	// '…' character at the end.
	OverrunModeThreeDot
)

func (OverrunMode) String

func (om OverrunMode) String() string

String implements fmt.Stringer()

type RectangleOption

type RectangleOption interface {
	// contains filtered or unexported methods
}

RectangleOption is used to provide options to the Rectangle function.

func RectCellOpts

func RectCellOpts(opts ...cell.Option) RectangleOption

RectCellOpts sets options on the cells that create the rectangle.

func RectChar

func RectChar(c rune) RectangleOption

RectChar sets the character used in each of the cells of the rectangle.

type TextOption

type TextOption interface {
	// contains filtered or unexported methods
}

TextOption is used to provide options to Text().

func TextCellOpts

func TextCellOpts(opts ...cell.Option) TextOption

TextCellOpts sets options on the cells that contain the text.

func TextMaxX

func TextMaxX(x int) TextOption

TextMaxX sets a limit on the X coordinate (column) of the drawn text. The X coordinate of all cells used by the text must be within start.X <= X < TextMaxX. If not provided, the width of the canvas is used as TextMaxX.

func TextOverrunMode

func TextOverrunMode(om OverrunMode) TextOption

TextOverrunMode indicates what to do with text that overruns the TextMaxX() or the width of the canvas if TextMaxX() isn't specified. Defaults to OverrunModeStrict.

type VerticalTextOption

type VerticalTextOption interface {
	// contains filtered or unexported methods
}

VerticalTextOption is used to provide options to Text().

func VerticalTextCellOpts

func VerticalTextCellOpts(opts ...cell.Option) VerticalTextOption

VerticalTextCellOpts sets options on the cells that contain the text.

func VerticalTextMaxY

func VerticalTextMaxY(y int) VerticalTextOption

VerticalTextMaxY sets a limit on the Y coordinate (row) of the drawn text. The Y coordinate of all cells used by the vertical text must be within start.Y <= Y < VerticalTextMaxY. If not provided, the height of the canvas is used as VerticalTextMaxY.

func VerticalTextOverrunMode

func VerticalTextOverrunMode(om OverrunMode) VerticalTextOption

VerticalTextOverrunMode indicates what to do with text that overruns the VerticalTextMaxY() or the width of the canvas if VerticalTextMaxY() isn't specified. Defaults to OverrunModeStrict.

Directories

Path Synopsis
Package testdraw provides helpers for tests that use the draw package.
Package testdraw provides helpers for tests that use the draw package.

Jump to

Keyboard shortcuts

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