Table

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixBoundaries

func FixBoundaries[T any](maxWidth, maxHeight int, elems [][]T, x, y *int) [][]T

FixBoundaries is a function that fixes the boundaries of a table of elements based on the maximum width and height of the table.

Parameters:

  • maxWidth: The maximum width of the table.
  • maxHeight: The maximum height of the table.
  • elems: The elements of the table.
  • x: The x-coordinate to fix the boundaries at.
  • y: The y-coordinate to fix the boundaries at.

Returns:

  • [][]T: The elements of the table with the boundaries fixed.

Behaviors:

  • If maxWidth is less than 0, it is set to 0.
  • If maxHeight is less than 0, it is set to 0.
  • If elems is empty, nil is returned.

Types

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table[T] represents a table of cells that can be drawn to the screen.

func NewTable

func NewTable[T any](width, height int) *Table[T]

NewDrawTable creates a new Table[T] with the given width and height.

Parameters:

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

Returns:

  • *Table[T]: The new table.

Behaviors:

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

func (*Table[T]) ClearTable

func (dt *Table[T]) ClearTable()

ClearTable clears the table by setting all cells to their zero value.

func (*Table[T]) GetAt

func (dt *Table[T]) GetAt(x, y int) T

GetAt returns the cell at the given coordinates in the table.

Parameters:

  • x: The x-coordinate of the cell.
  • y: The y-coordinate of the cell.

Returns:

  • T: The cell at the given coordinates.

Behaviors:

  • If the x or y coordinates are out of bounds, the function returns the zero value of type T.

func (*Table[T]) GetFullTable

func (dt *Table[T]) GetFullTable() [][]T

GetFullTable returns the full table as a 2D slice of elements of type T.

Returns:

  • [][]T: The full table.

func (*Table[T]) GetHeight

func (dt *Table[T]) GetHeight() int

GetHeight returns the height of the table.

Returns:

  • int: The height of the table.

func (*Table[T]) GetWidth

func (dt *Table[T]) GetWidth() int

GetWidth returns the width of the table.

Returns:

  • int: The width of the table.

func (*Table[T]) IsXInBounds

func (dt *Table[T]) IsXInBounds(x int) error

IsXInBounds checks if the given x-coordinate is within the bounds of the table.

Parameters:

  • x: The x-coordinate to check.

Returns:

  • error: An error of type *ers.ErrOutOfBounds if the x-coordinate is out of bounds.

func (*Table[T]) IsYInBounds

func (dt *Table[T]) IsYInBounds(y int) error

IsYInBounds checks if the given y-coordinate is within the bounds of the table.

Parameters:

  • y: The y-coordinate to check.

Returns:

  • error: An error of type *ers.ErrOutOfBounds if the y-coordinate is out of bounds.

func (*Table[T]) Iterator

func (t *Table[T]) Iterator() ll.Iterater[T]

Iterator returns an iterator for the table. It iterates over the rows and columns as if it were an array of elements of type T.

Returns:

  • ll.Iterater[T]: An iterator for the table.

Behaviors:

  • For efficiency, the iterator is procedural. It is not a generator.

func (*Table[T]) WriteAt

func (dt *Table[T]) WriteAt(x, y int, cell T)

WriteAt writes a cell to the table at the given coordinates.

Parameters:

  • x: The x-coordinate of the cell.
  • y: The y-coordinate of the cell.
  • cell: The cell to write to the table.

Behaviors:

  • If the x or y coordinates are out of bounds, the function does nothing.

func (*Table[T]) WriteHorizontalSequence

func (dt *Table[T]) WriteHorizontalSequence(x, y *int, sequence []T)

WriteHorizontalSequence writes a sequence of cells to the table starting at the given coordinates. The sequence is written horizontally from the starting coordinates.

Parameters:

  • x: The x-coordinate of the starting cell.
  • y: The y-coordinate of the starting cell.
  • sequence: The sequence of cells to write to the table.

Behaviors:

  • Any value that would cause the sequence to be written outside the bounds of the table is ignored.
  • The x-coordinate is updated to the next available cell after the sequence is written.

func (*Table[T]) WriteTableAt

func (dt *Table[T]) WriteTableAt(table *Table[T], x, y *int)

WriteTableAt writes the given table to the table at the given coordinates.

Parameters:

  • x: The x-coordinate to write the table at.
  • y: The y-coordinate to write the table at.
  • table: The table to write to the table.

Behaviors:

  • If the table is nil, the function does nothing.
  • Any value that would cause the table to be written outside the bounds of the table is ignored.
  • The x and y coordinates are updated to the next available cell after the table is written.

func (*Table[T]) WriteVerticalSequence

func (dt *Table[T]) WriteVerticalSequence(x, y *int, sequence []T)

WriteVerticalSequence writes a sequence of cells to the table starting at the given coordinates. The sequence is written vertically from the starting coordinates.

Parameters:

  • x: The x-coordinate of the starting cell.
  • y: The y-coordinate of the starting cell.
  • sequence: The sequence of cells to write to the table.

Behaviors:

  • Any value that would cause the sequence to be written outside the bounds of the table is ignored.
  • The y-coordinate is updated to the next available cell after the sequence is written.

Jump to

Keyboard shortcuts

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