package statusline

import "git.teletypegames.org/engines/inkwell/inkbase/statusline"

Package statusline is an inkbase widget: StatusLine, a single line of text that shows the host's flash message while one is up, and the hover hint ("verb + target") otherwise.

The widget only displays. The flash message and its expiry belong to the host: it is up for as long as the host says, whether or not a StatusLine is registered, visible or gated off by its When. The widget reaches its game through Host: the screen, FlashText, HoverHint and the Colors. inkwell's *Game is a Host — its flash is what FlashLine put up, and the game loop expires it after about two seconds — and the root package re-exports StatusLine.

Index

Types

type Colors

type Colors struct {
	Flash  color.Color
	Status color.Color
}

Colors is the palette a StatusLine draws with: Flash for a flash message, Status for the hover hint.

type Host

type Host interface {
	widget.Screen
	// FlashText is the flash message up now, or "" when there is none. The
	// host owns it and its expiry; the line only shows it.
	FlashText() string
	// HoverHint is what the line says when there is no flash: in inkwell
	// the verb and the target under the cursor.
	HoverHint() string
	// StatusLineColors is the palette the line draws with.
	StatusLineColors() Colors
}

Host is what a StatusLine needs from the game it is drawn for, the UICtx's Game. On a Game that does not implement it the line draws nothing.

type StatusLine

type StatusLine struct {
	// Name is the key the widget is registered under.
	Name string
	// When gates the widget; nil shows it always.
	When inkbase.Condition
	// Y is the line's top in pixels.
	Y int
	// Align places the line: left or right with a 2 pixel margin, centred
	// otherwise.
	Align inkbase.Align
	// ScreenWidth is the width Align works against; 0 uses the screen's.
	ScreenWidth int
}

StatusLine renders a single line: either the host's flash message while one is up, or the hover hint (verb + target under the cursor). It only displays: the flash expires on the host's clock whether a StatusLine is registered, visible or not.

func (*StatusLine) Draw
func (s *StatusLine) Draw(dst *ebiten.Image, ctx *widget.UICtx)

Draw prints the flash message, or the hover hint when there is none, at height Y, placed by Align across ScreenWidth. It draws nothing when both are empty.

func (*StatusLine) GetName
func (s *StatusLine) GetName() string

GetName returns the name the status line is registered under.

func (*StatusLine) Layer
func (s *StatusLine) Layer() widget.Layer

Layer puts the line on widget.LayerHUD.

func (*StatusLine) Tick
func (s *StatusLine) Tick(ctx *widget.UICtx)

Tick does nothing; the line reads the host when it draws.

func (*StatusLine) VisibleWhen
func (s *StatusLine) VisibleWhen() inkbase.Condition

VisibleWhen returns the condition that switches the line on; nil means always.