components

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: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ComponentIdle means the component is neither clicked not hovered over.
	ComponentIdle = ComponentState(0)
	// ComponentHovered means the component is hovered over
	ComponentHovered = ComponentState(1)
	// ComponentClicked means the component is hovered over and the left mouse button is currently pressed.
	ComponentClicked = ComponentState(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	*console.ComponentBase
	// contains filtered or unexported fields
}

Button represents a button that you can click.

func NewButton

func NewButton(x, y, width, height int, text string, callback ClickedCallback) *Button

NewButton creates a new button at the given position, size and text.

func (*Button) Draw

func (b *Button) Draw(con *console.Console, timeElapsed float64)

Draw draws the button

func (*Button) FocusOnClick

func (b *Button) FocusOnClick() bool

FocusOnClick returns true if a click should focus the button

func (*Button) SetBackground

func (b *Button) SetBackground(idle, hover, clicked *concolor.Color)

SetBackground sets the background colors for the button states. Parameters that are nil will be ignored and not set.

func (*Button) SetForeground

func (b *Button) SetForeground(idle, hover, clicked *concolor.Color)

SetForeground sets the foreground colors for the button states. Parameters that are nil will be ignored and not set.

func (*Button) Update

func (b *Button) Update(con *console.Console, timeElapsed float64) bool

Update updates the button

type ClickedCallback

type ClickedCallback func()

ClickedCallback will be called if a click on the component happened.

type ComponentState

type ComponentState int

ComponentState represents generic states that components can use to define logic.

func CalculateComponentState

func CalculateComponentState(con *console.Console, x, y, w, h int) ComponentState

CalculateComponentState is generic helper function to calculate the state of a given area in the console.

type EnterCallback

type EnterCallback func(text string)

EnterCallback will be called if the enter key has been pressed.

type TextBox

type TextBox struct {
	*console.ComponentBase
	// contains filtered or unexported fields
}

TextBox represents a box that you can type in.

func NewTextbox

func NewTextbox(x, y, width, height int) *TextBox

NewTextbox creates a new textbox at the given position and size.

func (*TextBox) Draw

func (tb *TextBox) Draw(con *console.Console, timeElapsed float64)

Draw draws the textbox.

func (*TextBox) FocusOnClick

func (tb *TextBox) FocusOnClick() bool

FocusOnClick returns true if a click should focus the textbox

func (*TextBox) GetText

func (tb *TextBox) GetText() string

GetText returns the text of the textbox.

func (*TextBox) SetBackground

func (tb *TextBox) SetBackground(idle, hover, clicked *concolor.Color)

SetBackground sets the background colors for textbox. Parameters that are nil will be ignored and not set.

func (*TextBox) SetEnterCallback

func (tb *TextBox) SetEnterCallback(callback EnterCallback)

SetEnterCallback sets the enter callback.

func (*TextBox) SetForeground

func (tb *TextBox) SetForeground(active, inactive *concolor.Color)

SetForeground sets the foreground colors for the textbox states. Parameters that are nil will be ignored and not set.

func (*TextBox) SetText

func (tb *TextBox) SetText(newText string)

SetText changes the text of the textbox.

func (*TextBox) SetTextChanged

func (tb *TextBox) SetTextChanged(callback TextChangeCallback)

SetTextChanged sets the text change callback.

func (*TextBox) Update

func (tb *TextBox) Update(con *console.Console, timeElapsed float64) bool

Update updates the textbox.

type TextChangeCallback

type TextChangeCallback func(text string)

TextChangeCallback will be called if a text of the component has been changed.

Jump to

Keyboard shortcuts

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