This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/tomo.go

58 lines
1.6 KiB
Go
Raw Normal View History

2023-01-08 23:03:19 -07:00
package tomo
import "image"
2023-01-08 23:03:19 -07:00
var backend Backend
// Run initializes a backend, calls the callback function, and begins the event
// loop in that order. This function does not return until Stop() is called, or
// the backend experiences a fatal error.
func Run (callback func ()) (err error) {
backend, err = instantiateBackend()
2023-03-08 19:05:56 -07:00
if err != nil { return }
2023-01-08 23:03:19 -07:00
if callback != nil { callback() }
err = backend.Run()
backend = nil
return
}
// Stop gracefully stops the event loop and shuts the backend down. Call this
// before closing your application.
func Stop () {
if backend != nil { backend.Stop() }
}
// Do executes the specified callback within the main thread as soon as
// possible. This function can be safely called from other threads.
func Do (callback func ()) {
assertBackend()
2023-01-09 09:36:37 -07:00
backend.Do(callback)
2023-01-08 23:03:19 -07:00
}
// NewWindow creates a new window using the current backend, and returns it as a
// MainWindow. If the window could not be created, an error is returned
// explaining why.
func NewWindow (bounds image.Rectangle) (window MainWindow, err error) {
assertBackend()
return backend.NewWindow(bounds)
}
// SetTheme sets the theme of all open windows.
2023-03-30 23:06:29 -06:00
func SetTheme (theme Theme) {
backend.SetTheme(theme)
}
// SetConfig sets the configuration of all open windows.
2023-03-30 23:06:29 -06:00
func SetConfig (config Config) {
backend.SetConfig(config)
}
// Bounds creates a rectangle from an x, y, width, and height.
func Bounds (x, y, width, height int) image.Rectangle {
return image.Rect(x, y, x + width, y + height)
}
func assertBackend () {
if backend == nil { panic("no backend is running") }
}