tomo/tomo.go

62 lines
1.1 KiB
Go

package tomo
import "image"
import "errors"
var backend Backend
// Run initializes a backend, runs the specified callback function, and runs the
// event loop in that order. This function blocks until Stop is called, or the
// backend experiences a fatal error.
func Run (callback func ()) error {
loadPlugins()
if backend != nil {
return errors.New("there is already a backend running")
}
back, err := Initialize()
if err != nil { return err }
backend = back
callback()
return backend.Run()
}
func assertBackend () {
if backend == nil { panic("nil backend") }
}
// Stop stops the backend, unblocking run. Run may be called again after calling
// Stop.
func Stop () {
assertBackend()
backend.Stop()
backend = nil
}
func NewWindow (bounds image.Rectangle) MainWindow {
assertBackend()
return backend.NewWindow(bounds)
}
func NewBox () Box {
assertBackend()
return backend.NewBox()
}
func NewTextBox () TextBox {
assertBackend()
return backend.NewTextBox()
}
func NewCanvasBox () CanvasBox {
assertBackend()
return backend.NewCanvasBox()
}
func NewContainerBox () ContainerBox {
assertBackend()
return backend.NewContainerBox()
}