Display

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmptyRuneCell is a rune that represents an empty cell.
	EmptyRuneCell rune = '\000'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DrawTable

type DrawTable struct {
	*cdt.Table[*dtCell]
}

DrawTable represents a table of cells that can be drawn to the screen.

func NewDrawTable

func NewDrawTable(width, height int) *DrawTable

NewDrawTable creates a new DrawTable with the given width and height.

Parameters:

  • width: The width of the drawTable.
  • height: The height of the drawTable.

Returns:

  • *DrawTable: The new drawTable.

Behaviors:

  • If the width or height is negative, the absolute value is used.

func (*DrawTable) GetLines

func (dt *DrawTable) GetLines() []string

GetLines returns each line of the drawTable as a string.

Returns:

  • []string: The lines of the drawTable.

Behaviors:

  • Any nil cells in the drawTable are represented by a space character.

func (*DrawTable) WriteLineAt

func (dt *DrawTable) WriteLineAt(x, y int, line string, style tcell.Style, isHorizontal bool)

WriteLineAt writes a string to the drawTable at the given coordinates.

Parameters:

  • x: The x-coordinate of the starting cell.
  • y: The y-coordinate of the starting cell.
  • line: The string to write to the drawTable.
  • style: The style of the string.
  • isHorizontal: A boolean that determines if the string should be written horizontally or vertically.

Behaviors:

  • This is just a convenience function that converts the string to a sequence of cells and calls WriteHorizontalSequence or WriteVerticalSequence.

type DtUnit

type DtUnit[T DtUniter] struct {
	// contains filtered or unexported fields
}

DtUnit represents a unit in a draw table. It contains the content of the unit

func NewDtUnit

func NewDtUnit[T DtUniter](content T, style tcell.Style) *DtUnit[T]

NewDtUnit creates a new DtUnit with the given content and style.

Parameters:

  • content: The content of the unit.
  • style: The style of the unit.

Returns:

  • *DtUnit: The new DtUnit.

func (*DtUnit[T]) Draw

func (u *DtUnit[T]) Draw(table *DrawTable, x, y int) error

Draw is a method of cdd.TableDrawer that draws the unit to the table at the given x and y coordinates.

Parameters:

  • table: The table to draw the unit to.
  • x: The x coordinate to draw the unit at.
  • y: The y coordinate to draw the unit at.

Returns:

  • error: An error of type *ers.ErrInvalidParameter if the table is nil.

Behaviors:

  • Any value that would be drawn outside of the table is not drawn.

type DtUniter

type DtUniter interface {
	// Runes returns the content of the unit as a 2D slice of runes
	// given the size of the table.
	//
	// Parameters:
	//   - width: The width of the table.
	//   - height: The height of the table.
	//
	// Returns:
	//   - [][]rune: The content of the unit as a 2D slice of runes.
	//   - error: An error if the content could not be converted to runes.
	//
	// Behaviors:
	//   - Always assume that the width and height are greater than 0. No need to check for
	//     this.
	//   - Errors are only for critical issues, such as the content not being able to be
	//     converted to runes. However, out of bounds or other issues should not error.
	//     Instead, the content should be drawn as much as possible before unable to be
	//     drawn.
	Runes(width, height int) ([][]rune, error)
}

DtUniter is an interface that represents the content of a unit in a draw table.

Jump to

Keyboard shortcuts

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