2023-01-08 23:03:19 -07:00
|
|
|
package tomo
|
|
|
|
|
2023-04-10 00:36:28 -06:00
|
|
|
import "image"
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
// Backend represents a connection to a display server, or something similar.
|
|
|
|
// It is capable of managing an event loop, and creating windows.
|
|
|
|
type Backend interface {
|
|
|
|
// Run runs the backend's event loop. It must block until the backend
|
|
|
|
// experiences a fatal error, or Stop() is called.
|
2023-04-10 00:36:28 -06:00
|
|
|
Run () error
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
// Stop stops the backend's event loop.
|
|
|
|
Stop ()
|
|
|
|
|
|
|
|
// Do executes the specified callback within the main thread as soon as
|
|
|
|
// possible. This method must be safe to call from other threads.
|
|
|
|
Do (callback func ())
|
|
|
|
|
2023-04-14 23:14:36 -06:00
|
|
|
// NewEntity creates a new entity for the specified element.
|
|
|
|
NewEntity (owner Element) Entity
|
|
|
|
|
2023-04-10 00:36:28 -06:00
|
|
|
// NewWindow creates a new window within the specified bounding
|
|
|
|
// rectangle. The position on screen may be overridden by the backend or
|
|
|
|
// operating system.
|
|
|
|
NewWindow (bounds image.Rectangle) (MainWindow, error)
|
2023-02-02 23:25:45 -07:00
|
|
|
|
|
|
|
// SetTheme sets the theme of all open windows.
|
2023-03-30 23:06:29 -06:00
|
|
|
SetTheme (Theme)
|
2023-02-02 23:25:45 -07:00
|
|
|
|
|
|
|
// SetConfig sets the configuration of all open windows.
|
2023-03-30 23:06:29 -06:00
|
|
|
SetConfig (Config)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-04-29 23:27:04 -06:00
|
|
|
var backend Backend
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-04-29 23:27:04 -06:00
|
|
|
// GetBackend returns the currently running backend.
|
|
|
|
func GetBackend () Backend {
|
|
|
|
return backend
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-04-29 23:27:04 -06:00
|
|
|
// SetBackend sets the currently running backend. The backend can only be set
|
|
|
|
// once—if there already is one then this function will do nothing.
|
|
|
|
func SetBackend (b Backend) {
|
|
|
|
if backend != nil { return }
|
|
|
|
backend = b
|
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-04-29 23:27:04 -06:00
|
|
|
// 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)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|