console

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2022 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Overview

Package console provides a emulated console view.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorSection

type ColorSection struct {
	Index       int
	Transformer []t.Transformer
}

ColorSection represents a colorized section in a text.

type ColorSections

type ColorSections []*ColorSection

ColorSections represents a slice of color sections.

func ParseColoredText

func ParseColoredText(text string) (string, ColorSections)

ParseColoredText parses the coloring annotations in a string and returns the cleaned string and the parsed color sections.

func (ColorSections) GetCurrent

func (cs ColorSections) GetCurrent(index int) *ColorSection

GetCurrent gets the current color section for the given index in a string.

func (ColorSections) GetCurrentTransformer

func (cs ColorSections) GetCurrentTransformer(index int) []t.Transformer

GetCurrentTransformer gets the transformers for the current color section for the given index in a string.

type Component

type Component interface {
	ComponentAttributes
	ComponentLogic
}

Component represents a ui element on the console.

type ComponentAttributes

type ComponentAttributes interface {
	ID() string
	Position() (int, int)
	Size() (int, int)
	ShouldClose() bool
	ShouldDraw() bool
	IsFocused() bool
	SetFocus(value bool)
}

ComponentAttributes represents a closable object with a position and size.

type ComponentBase

type ComponentBase struct {
	X      int
	Y      int
	Width  int
	Height int
	// contains filtered or unexported fields
}

ComponentBase represents the base for a ui element on the console.

func NewComponentBase

func NewComponentBase(x, y, width, height int) *ComponentBase

NewComponentBase creates a new component base for ease of use.

func (*ComponentBase) Close

func (cb *ComponentBase) Close()

Close tells the component to close and remove itself from the parents component list on the next update.

func (*ComponentBase) ID added in v0.2.0

func (cb *ComponentBase) ID() string

func (*ComponentBase) IsFocused

func (cb *ComponentBase) IsFocused() bool

IsFocused returns true if the component is active, which means it was clicked on.

func (*ComponentBase) Position

func (cb *ComponentBase) Position() (int, int)

Position returns the position of the component.

func (*ComponentBase) SetFocus

func (cb *ComponentBase) SetFocus(value bool)

SetFocus adds or remove focus from component.

func (*ComponentBase) ShouldClose

func (cb *ComponentBase) ShouldClose() bool

ShouldClose returns true if the component should be closed and deleted from the console.

func (*ComponentBase) ShouldDraw

func (cb *ComponentBase) ShouldDraw() bool

ShouldDraw returns true if the component should be drawn.

func (*ComponentBase) Show

func (cb *ComponentBase) Show(value bool)

Show shows or hides the component.

func (*ComponentBase) Size

func (cb *ComponentBase) Size() (int, int)

Size returns the size of the component.

type ComponentLogic

type ComponentLogic interface {
	Update(con *Console, timeElapsed float64) bool
	Draw(con *Console, timeElapsed float64)
	FocusOnClick() bool
}

ComponentLogic represents an object that can be updated and drawn on a console.

type Console

type Console struct {
	Title       string
	Width       int
	Height      int
	Font        *font.Font
	ShowFPS     bool
	SubConsoles []*Console
	// contains filtered or unexported fields
}

Console represents a emulated console view.

func New

func New(width, height int, font *font.Font, title string) (*Console, error)

New creates a new console.

func (*Console) AddComponent

func (c *Console) AddComponent(component Component)

AddComponent adds a component that should be updated and rendered to the console.

Attention: Don't use this function inside a callback from a component as this will create a deadlock!

func (*Console) CalcTextHeight

func (c *Console) CalcTextHeight(width, height int, text string) int

CalcTextHeight pre-calculates the height a text will need.

func (*Console) Clear

func (c *Console) Clear(x, y, width, height int) error

Clear clears part of the console.

func (*Console) ClearAll

func (c *Console) ClearAll() error

ClearAll clears the whole console.

func (*Console) CreateSubConsole

func (c *Console) CreateSubConsole(x, y, width, height int) (*Console, error)

CreateSubConsole creates a new sub-console.

func (*Console) Draw

func (c *Console) Draw(screen *ebiten.Image)

Draw draws the game screen and is called every frame (typically 1/60[s] for 60Hz display). This is an ebiten function. Don't call it yourself!

func (*Console) HasComponent added in v0.2.0

func (c *Console) HasComponent(component Component) bool

HasComponent checks if component is mounted to the console.

Attention: Don't use this function inside a callback from a component as this will create a deadlock!

func (*Console) Layout

func (c *Console) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

Layout returns size of drawable area inside window. This will be stretched to window sized. This is an ebiten function. Don't call it yourself!

func (*Console) MouseInArea

func (c *Console) MouseInArea(x, y, width, height int) bool

MouseInArea checks if the mouse cursor is currently in the given area.

func (*Console) MousePosition

func (c *Console) MousePosition() (int, int)

MousePosition returns the cell that the mouse cursor is currently in. If it returns (-1, -1) the mouse cursor is currently not in the console.

func (*Console) Print

func (c *Console) Print(x, y int, text string, transformer ...t.Transformer)

Print prints a text onto the console. To give the text a different foreground or background color use transformer. This function also supports inlined color definitions.

func (*Console) PrintBounded

func (c *Console) PrintBounded(x, y, width, height int, text string, transformer ...t.Transformer) int

PrintBounded prints a text onto the console that is bounded by a width and height. If you set width or height to <= 0 this bound won't have a limit. To give the text a different foreground or background color use transformer. This function also supports inlined color definitions.

func (*Console) PrintBoundedOffset

func (c *Console) PrintBoundedOffset(x, y, width, height, sy int, text string, transformer ...t.Transformer) int

PrintBoundedOffset prints a text onto the console that is bounded by a width and height and skips the first sy lines. If you set width or height to <= 0 this bound won't have a limit. To give the text a different foreground or background color use transformer. This function also supports inlined color definitions.

func (*Console) RemoveComponent added in v0.2.0

func (c *Console) RemoveComponent(component Component)

RemoveComponent removes a component from the console.

Attention: Don't use this function inside a callback from a component as this will create a deadlock!

func (*Console) RemoveSubConsole

func (c *Console) RemoveSubConsole(con *Console) error

RemoveSubConsole removes a sub-console from his parent.

func (*Console) SetPostRenderHook

func (c *Console) SetPostRenderHook(hook func(screen *ebiten.Image, timeElapsed float64) error) error

SetPostRenderHook will apply a hook that gets triggered after the console is finished rendering. This is a good place if you want to draw some extra content over the console.

func (*Console) SetPreRenderHook

func (c *Console) SetPreRenderHook(hook func(screen *ebiten.Image, timeElapsed float64) error) error

SetPreRenderHook will apply a hook that gets triggered before the console started rendering. This is a good place to change the console or to draw extra content under the console.

func (*Console) SetPriority

func (c *Console) SetPriority(priority int) error

SetPriority sets the priority of the console. A higher priority will result in the console being drawn on top of all the ones with lower priority.

func (*Console) SetTickHook

func (c *Console) SetTickHook(hook func(timeElapsed float64) error) error

SetTickHook will apply a hook that gets triggered every tick, even if drawing is skipped in this tick. This is a good place for game logic as it runs disconnected from the fps.

func (*Console) Start

func (c *Console) Start(scale float64) error

Start will open the console window with the given scale.

func (*Console) Transform

func (c *Console) Transform(x, y int, transformer ...t.Transformer) error

Transform transforms a cell. This can be used to change the character, foreground and background of a cell or apply custom transformers onto a cell.

func (*Console) TransformAll added in v0.2.0

func (c *Console) TransformAll(transformer ...t.Transformer) error

TransformAll applies the given transformers to all cells in the console.

func (*Console) TransformArea added in v0.2.0

func (c *Console) TransformArea(x, y, width, height int, transformer ...t.Transformer) error

TransformArea applies the given transformers to all cells in the given area.

func (*Console) Update

func (c *Console) Update() error

Update proceeds the game state and is called every tick (1/60 [s] by default). This is an ebiten function. Don't call it yourself!

Jump to

Keyboard shortcuts

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