-
Notifications
You must be signed in to change notification settings - Fork 6
UI Components
Daniel S edited this page Sep 21, 2018
·
6 revisions
A ui component needs to implement the Component interface, which itself is a combination of the ComponentAttributes and the ComponentLogic interface. To make it easier there is already a ComponentBase struct that implements the ComponentAttributes interface so you only need to embed the ComponentBase into your component struct and implement a Update and a Draw function.
// YourComponent that embeds ComponentBase
type YourComponent struct {
*console.ComponentBase
}
// NewYourComponent creates your component.
func NewYourComponent(x, y, width, height int) *YourComponent {
y := YourComponent{
ComponentBase: console.NewComponentBase(x, y, width, height),
}
return &y
}
// Update updates your component
func (y *YourComponent) Update(con *console.Console, timeElapsed float64) bool {
// Return true if the component should keep on living.
// Return false if the component should be deleted from the console.
// Use y.Close() to close it from outside.
return true
}
// Draw draws your component
func (y *YourComponent) Draw(con *console.Console, timeElapsed float64) {
con.Clear(y.X, y.Y, y.Width, y.Height, t.Background(consolecolor.NewHex("#000"))
}