Documentation
¶
Index ¶
- type Cell
- type Displayer
- type Table
- func (t *Table) Cell() iter.Seq[*Cell]
- func (t *Table) CellAt(x, y int) *Cell
- func (t *Table) Cleanup()
- func (t *Table) FullTable() [][]*Cell
- func (t *Table) GetLines() []string
- func (t *Table) Height() int
- func (t *Table) IsXInBounds(x int) error
- func (t *Table) IsYInBounds(y int) error
- func (t *Table) ResizeHeight(new_height int) error
- func (t *Table) ResizeWidth(new_width int) error
- func (t *Table) Row() iter.Seq[[]*Cell]
- func (t *Table) Width() int
- func (t *Table) WriteAt(x, y int, cell *Cell)
- func (t *Table) WriteHorizontalSequence(x, y *int, sequence []*Cell)
- func (t *Table) WriteLineAt(x, y *int, line string, style tcell.Style, isHorizontal bool)
- func (t *Table) WriteTableAt(table *Table, x, y *int)
- func (t *Table) WriteVerticalSequence(x, y *int, sequence []*Cell)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct { // Char is the character of the cell. Char rune // Style is the Style of the cell. Style tcell.Style }
Cell is a table cell.
func LineToCells ¶
LineToCells converts a string to a slice of DrawCells with the given style.
Parameters:
- line: The string to convert.
- style: The style to use.
Returns:
- []*DrawCell: The slice of DrawCells.
type Displayer ¶
type Displayer interface { // 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. // - Assumes that the table is not nil. Draw(table *Table, x, y *int) error }
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a table of cells that can be drawn to the screen.
func NewTable ¶
NewTable creates a new table of type DrawCell with the given width and height. Negative parameters are treated as absolute values.
Parameters:
- width: The width of the table.
- height: The height of the table.
Returns:
- *Table: The new table.
- error: An error if the table could not be created.
Errors:
- *gcers.ErrInvalidParameter: If the width or height is less than 0.
func (*Table) Cell ¶
Cell returns an iterator that is a pull-model iterator that scans the table row by row as it was an array of elements of type DrawCell.
Example:
[ a b c ] [ d e f ] Cell() -> [ a ] -> [ b ] -> [ c ] -> [ d ] -> [ e ] -> [ f ]
func (*Table) CellAt ¶
CellAt returns the cell at the given coordinates in the table. However, out-of-bounds coordinates return nil.
Parameters:
- x: The x-coordinate of the cell.
- y: The y-coordinate of the cell.
Returns:
- *DrawCell: The cell at the given coordinates.
func (*Table) Cleanup ¶
func (t *Table) Cleanup()
Cleanup is a method that cleans up the table.
It sets all cells in the table to the zero value of type int.
func (*Table) FullTable ¶
FullTable returns the full table as a 2D slice of elements of type DrawCell.
Returns:
- [][]*DrawCell: The full table.
func (*Table) GetLines ¶
GetLines returns each line of the drawTable as a string.
Parameters:
- table: The drawTable.
Returns:
- []string: The lines of the drawTable.
Behaviors:
- Any nil cells in the drawTable are represented by a space character.
- The last line may not be full width.
func (*Table) Height ¶
Height returns the height of the table.
Returns:
- int: The height of the table. Never negative.
func (*Table) IsXInBounds ¶
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 *ints.ErrOutOfBounds if the x-coordinate is out of bounds.
func (*Table) IsYInBounds ¶
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 *ints.ErrOutOfBounds if the y-coordinate is out of bounds.
func (*Table) ResizeHeight ¶
ResizeHeight resizes the table to the given height.
Parameters:
- new_height: The new height of the table.
Returns:
- error: An error if the table could not be resized.
Errors:
- *gcers.ErrInvalidParameter: If the new height is less than 0.
- gcers.NilReceiver: If the table is nil.
func (*Table) ResizeWidth ¶
ResizeWidth resizes the table to the given width.
Parameters:
- new_width: The new width of the table.
Returns:
- error: An error if the table could not be resized.
Errors:
- *gcers.ErrInvalidParameter: If the new width is less than 0.
- gcers.NilReceiver: If the table is nil.
func (*Table) Row ¶
Row returns an iterator that is a pull-model iterator that scans the table row by row as it was an array of elements of type DrawCell.
Example:
[ a b c ] [ d e f ] Row(0) -> [ a b c ] Row(1) -> [ d e f ]
func (*Table) Width ¶
Width returns the width of the table.
Returns:
- int: The width of the table. Never negative.
func (*Table) WriteAt ¶
WriteAt writes a cell to the table at the given coordinates. However, out-of-bounds coordinates do nothing.
Parameters:
- x: The x-coordinate of the cell.
- y: The y-coordinate of the cell.
- cell: The cell to write to the table.
func (*Table) WriteHorizontalSequence ¶
WriteHorizontalSequence is the equivalent of WriteVerticalSequence but for horizontal sequences.
See WriteVerticalSequence for more information.
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.
func (*Table) WriteLineAt ¶
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.
- x and y are updated to the next available cell after the line is written.
func (*Table) WriteTableAt ¶
WriteTableAt is a convenience function that copies the values from the given table to the table starting at the given coordinates in a more efficient way than using any other methods.
While it acts in the same way as both WriteVerticalSequence and WriteHorizontalSequence combined, it is more efficient than calling those two functions separately.
See WriteVerticalSequence for more information.
Parameters:
- table: The table to write to the table.
- x: The x-coordinate to write the table at.
- y: The y-coordinate to write the table at.
If the table is nil, x or y are nil, nothing happens.
func (*Table) WriteVerticalSequence ¶
WriteVerticalSequence is a function that writes the specified values to the table starting from the specified coordinates (top = 0, 0) and continuing down the table in the vertical direction until either the sequence is exhausted or the end of the table is reached; at which point any remaining values in the sequence are ignored.
Due to implementation details, any value that would be written outside are ignored. As such, if x is out-of-bounds, the function does nothing and, if y is out-of-bounds, only out-of-bounds values are not written.
Parameters:
- x: The x-coordinate of the starting cell. (Never changes)
- y: The y-coordinate of the starting cell.
- sequence: The sequence of cells to write to the table.
At the end of the function, the y coordinate points to the cell right below the last cell in the sequence that was written.
Example:
// [ a b c ] // [ d e f ] // // seq := [ g h i ], x = 0, y = -1 WriteVerticalSequence(x, y, seq) // [ h b c ] // [ i e f ] // // x = 0, y = 2
As you can see, the 'g' value was ignored as it would be out-of-bounds. Finally, if either x or y is nil, the function does nothing.