stone/backend.go
2022-11-06 15:59:06 -05:00

43 lines
1.1 KiB
Go

package stone
import "time"
import "errors"
type Backend interface {
Run (callback func (application *Application)) ()
Await (timeout time.Duration) (keepRunning bool)
Poll () (keepRunning bool)
SetTitle (title string)
JustPressed (button Button) (pressed bool)
JustReleased (button Button) (released bool)
Pressed (button Button) (pressed bool)
Repeated (button Button) (repeated bool)
Typed () (text string)
Resized () (resized bool)
MousePosition () (x, y int)
}
type BackendFactory func (application *Application) (backend Backend, err error)
var factories []BackendFactory
func RegisterBackend (factory BackendFactory) {
factories = append(factories, factory)
}
func instantiateBackend (application *Application) (backend Backend, err error) {
// find a suitable backend
for _, factory := range factories {
backend, err = factory(application)
if err == nil && backend != nil { return }
}
// if none were found, but there was no error produced, produce an
// error
if err == nil {
err = errors.New("no available backends")
}
return
}