Display

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Display

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

Display represents a display screen with a frame rate. It also includes synchronization primitives for managing the display's state.

func (*Display) Init

func (d *Display) Init(frameRate float64, defaultStyle tcell.Style) error

Init initializes the Display with a given frame rate.

Parameters:

  • frameRate: The frame rate for the Display, specified as a float64.
  • defaultStyle: The default style for the screen. It must be of type tcell.Style.

Returns:

  • An error if any occurred during initialization.

The frame rate is converted to a time.Duration by dividing 1000 by the frame rate, rounding the result, and multiplying by time.Millisecond. This gives the duration between frames for the Display.

func (*Display) Start

func (d *Display) Start(elementToDisplay Displayable)

Start begins the main loop of the Display, which clears the screen, sets the sizes of the element to display, draws the element, shows the screen, and then waits for the duration of the frame rate. This loop continues until the Display.Close() method is called or the program terminates unexpectedly.

Parameters:

  • elementToDisplay: The element to display on the screen. It must satisfy the Displayable interface.

The method uses a sync.Once to ensure that the main loop is only started once.

If an error occurs while setting the size of the element to display, the method panics with an appropriate message.

After the element has been drawn and shown, the method waits for the duration of the frame rate before starting the next iteration of the loop.

When the loop ends, the method sets the closeReceived field to true, clears the screen, finalizes it, and sets it to nil.

func (*Display) Stop

func (d *Display) Stop()

Stop signals to the main loop of the Display to stop and waits for all goroutines related to the Display to finish.

The method should be called when the Display is no longer needed, to ensure that all resources are properly released and all goroutines have finished.

type Displayable

type Displayable interface {
	// Checks if the width of the object can be set to a given value.
	// Returns a boolean.
	CanSetWidth(width int) bool

	// Sets the width of the object to a given value.
	SetWidth(width int)

	// Checks if the height of the object can be set to a given value.
	// Returns a boolean.
	CanSetHeight(height int) bool

	// Sets the height of the object to a given value.
	SetHeight(height int)

	// Draws the object on a given screen and returns the updated screen.
	GenerateDrawTables() ([][]rune, []tcell.Style)
}

Displayable defines the behavior of an object that can be displayed on a screen.

Any type that implements these methods is said to satisfy the Displayable interface. This means that the type can be used wherever a Displayable is expected.

type ErrHeightTooSmall

type ErrHeightTooSmall struct{}

func (ErrHeightTooSmall) Error

func (e ErrHeightTooSmall) Error() string

type ErrTextTooLong

type ErrTextTooLong struct{}

func (ErrTextTooLong) Error

func (e ErrTextTooLong) Error() string

type ErrWidthTooSmall

type ErrWidthTooSmall struct{}

func (ErrWidthTooSmall) Error

func (e ErrWidthTooSmall) Error() string

type ErrXOutOfBounds

type ErrXOutOfBounds struct{}

func (ErrXOutOfBounds) Error

func (e ErrXOutOfBounds) Error() string

type ErrYOutOfBounds

type ErrYOutOfBounds struct{}

func (ErrYOutOfBounds) Error

func (e ErrYOutOfBounds) Error() string

Jump to

Keyboard shortcuts

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