sixteen

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sixteen simulates a 16-segment display drawn on a canvas.

Given a canvas, determines the placement and size of the individual segments and exposes API that can turn individual segments on and off or display ASCII characters.

The following outlines segments in the display and their names.

     A1      A2
   ------- -------
  | \     |     / |
  |  \    |    /  |
F |   H   J   K   | B
  |    \  |  /    |
  |     \ | /     |
   -G1---- ----G2-
  |     / | \     |
  |    /  |  \    |
E |   N   M   L   | C
  |  /    |    \  |
  | /     |     \ |
   ------- -------
     D1      D2

Index

Constants

View Source
const (
	// MinCols is the smallest valid amount of columns in a cell area.
	MinCols = 6
	// MinRowPixels is the smallest valid amount of rows in a cell area.
	MinRows = 5
)

Minimum valid size of a cell canvas in order to draw the segment display.

Variables

This section is empty.

Functions

func Required

func Required(cellArea image.Rectangle) (image.Rectangle, error)

Required, when given an area of cells, returns either an area of the same size or a smaller area that is required to draw one display. Returns a smaller area when the provided area didn't have the required aspect ratio. Returns an error if the area is too small to draw a segment display, i.e. smaller than MinCols x MinRows.

func Sanitize

func Sanitize(s string) string

Sanitize returns a copy of the string, replacing all unsupported characters with a space character.

func SupportsChars

func SupportsChars(s string) (bool, []rune)

SupportsChars asserts whether the display supports all runes in the provided string. The display only supports a subset of ASCII characters. Returns any unsupported runes found in the string in an unspecified order.

Types

type Display

type Display struct {
	// contains filtered or unexported fields
}

Display represents the segment display. This object is not thread-safe.

func New

func New(opts ...Option) *Display

New creates a new segment display. Initially all the segments are off.

func (*Display) Clear

func (d *Display) Clear(opts ...Option)

Clear clears the entire display, turning all segments off.

func (*Display) ClearSegment

func (d *Display) ClearSegment(s Segment) error

ClearSegment sets the specified segment off. This method is idempotent.

func (*Display) Draw

func (d *Display) Draw(cvs *canvas.Canvas, opts ...Option) error

Draw draws the current state of the segment display onto the canvas. The canvas must be at least MinCols x MinRows cells, or an error will be returned. Any options provided to draw overwrite the values provided to New.

func (*Display) SetCharacter

func (d *Display) SetCharacter(c rune) error

Character sets all the segments that are needed to display the provided character. The display only supports a subset of ASCII characters, use SupportsChars() or Sanitize() to ensure the provided character is supported. Doesn't clear the display of segments set previously.

func (*Display) SetSegment

func (d *Display) SetSegment(s Segment) error

SetSegment sets the specified segment on. This method is idempotent.

func (*Display) ToggleSegment

func (d *Display) ToggleSegment(s Segment) error

ToggleSegment toggles the state of the specified segment, i.e it either sets or clears it depending on its current state.

type Option

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

Option is used to provide options.

func CellOpts

func CellOpts(cOpts ...cell.Option) Option

CellOpts sets the cell options on the cells that contain the segment display.

type Segment

type Segment int

Segment represents a single segment in the display.

const (
	A1 Segment
	A2
	B
	C
	D1
	D2
	E
	F
	G1
	G2
	H
	J
	K
	L
	M
	N
)

func AllSegments

func AllSegments() []Segment

AllSegments returns all 16 segments in an undefined order.

func (Segment) String

func (s Segment) String() string

String implements fmt.Stringer()

Directories

Path Synopsis
Package testsixteen provides helpers for tests that use the sixteen package.
Package testsixteen provides helpers for tests that use the sixteen package.

Jump to

Keyboard shortcuts

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