Documentation ¶
Overview ¶
Package console provides a emulated console view.
Index ¶
- type ColorSection
- type ColorSections
- type Component
- type ComponentAttributes
- type ComponentBase
- func (cb *ComponentBase) Close()
- func (cb *ComponentBase) ID() string
- func (cb *ComponentBase) IsFocused() bool
- func (cb *ComponentBase) Position() (int, int)
- func (cb *ComponentBase) SetFocus(value bool)
- func (cb *ComponentBase) ShouldClose() bool
- func (cb *ComponentBase) ShouldDraw() bool
- func (cb *ComponentBase) Show(value bool)
- func (cb *ComponentBase) Size() (int, int)
- type ComponentLogic
- type Console
- func (c *Console) AddComponent(component Component)
- func (c *Console) CalcTextHeight(width, height int, text string) int
- func (c *Console) Clear(x, y, width, height int) error
- func (c *Console) ClearAll() error
- func (c *Console) CreateSubConsole(x, y, width, height int) (*Console, error)
- func (c *Console) Draw(screen *ebiten.Image)
- func (c *Console) HasComponent(component Component) bool
- func (c *Console) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)
- func (c *Console) MouseInArea(x, y, width, height int) bool
- func (c *Console) MousePosition() (int, int)
- func (c *Console) Print(x, y int, text string, transformer ...t.Transformer)
- func (c *Console) PrintBounded(x, y, width, height int, text string, transformer ...t.Transformer) int
- func (c *Console) PrintBoundedOffset(x, y, width, height, sy int, text string, transformer ...t.Transformer) int
- func (c *Console) RemoveComponent(component Component)
- func (c *Console) RemoveSubConsole(con *Console) error
- func (c *Console) SetPostRenderHook(hook func(screen *ebiten.Image, timeElapsed float64) error) error
- func (c *Console) SetPreRenderHook(hook func(screen *ebiten.Image, timeElapsed float64) error) error
- func (c *Console) SetPriority(priority int) error
- func (c *Console) SetTickHook(hook func(timeElapsed float64) error) error
- func (c *Console) Start(scale float64) error
- func (c *Console) Transform(x, y int, transformer ...t.Transformer) error
- func (c *Console) TransformAll(transformer ...t.Transformer) error
- func (c *Console) TransformArea(x, y, width, height int, transformer ...t.Transformer) error
- func (c *Console) Update() error
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 (*Console) AddComponent ¶
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 ¶
CalcTextHeight pre-calculates the height a text will need.
func (*Console) CreateSubConsole ¶
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
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 ¶
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 ¶
MouseInArea checks if the mouse cursor is currently in the given area.
func (*Console) MousePosition ¶
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
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 ¶
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 ¶
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 ¶
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) 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.