Nasin has its own registry system that is way more flexible than what was in this module, that ought to be used instead.
85 lines
2.9 KiB
Go
85 lines
2.9 KiB
Go
package tomo
|
|
|
|
import "sync"
|
|
import "image"
|
|
import "git.tebibyte.media/tomo/tomo/data"
|
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
|
|
|
// Backend is any Tomo implementation. Backends handle window creation, layout,
|
|
// rendering, and events so that there can be as many platform-specific
|
|
// optimizations as possible.
|
|
type Backend interface {
|
|
// These methods create new objects. The backend must reject any object
|
|
// that was not made by it.
|
|
NewBox () Box
|
|
NewTextBox () TextBox
|
|
NewCanvasBox () CanvasBox
|
|
NewSurfaceBox () (SurfaceBox, error)
|
|
NewContainerBox () ContainerBox
|
|
|
|
// NewWindow creates a normal Window and returns it.
|
|
NewWindow (image.Rectangle) (Window, error)
|
|
|
|
// NewPlainWindow creates an undecorated window that does not appear in
|
|
// window lists and returns it. This is intended for making things like
|
|
// panels, docks, etc.
|
|
NewPlainWindow (image.Rectangle) (Window, error)
|
|
|
|
// NewTexture creates a new texture from an image. The backend must
|
|
// reject any texture that was not made by it.
|
|
NewTexture (image.Image) canvas.TextureCloser
|
|
|
|
// NewCanvas creates a new canvas with the specified bounds. The backend
|
|
// must reject any canvas that was not made by it.
|
|
NewCanvas (image.Rectangle) canvas.CanvasCloser
|
|
|
|
// ColorRGBA returns the RGBA of a color according to the current style,
|
|
// as specified in color.Color.RGBA. It may be rendered invalid if the
|
|
// visual style changes, but the backend must send a StyleChange event
|
|
// to all managed boxes when this happens.
|
|
ColorRGBA (id Color) (r, g, b, a uint32)
|
|
|
|
// IconTexture returns the texture of an icon. It may be closed and
|
|
// therefore rendered invalid if the icon set changes, but the backend
|
|
// must send an IconSetChange event to all managed boxes when this
|
|
// happens.
|
|
IconTexture (Icon, IconSize) canvas.Texture
|
|
|
|
// MimeIconTexture returns the texture of an icon corresponding to the
|
|
// specified MIME type. It may be closed and therefore rendered invalid
|
|
// if the icon set changes, but the backend must send an IconSetChange
|
|
// event to all managed boxes when this happens.
|
|
MimeIconTexture (data.Mime, IconSize) canvas.Texture
|
|
|
|
// Run runs the event loop until Stop is called, or the backend
|
|
// experiences a fatal error.
|
|
Run () error
|
|
|
|
// Stop must unblock run. This behavior may only be called from within
|
|
// tomo.Stop.
|
|
Stop ()
|
|
|
|
// Do performs a callback function in the event loop thread as soon as
|
|
// possible. This method must be safe to call concurrently.
|
|
Do (func ())
|
|
}
|
|
|
|
var backendLock sync.Mutex
|
|
var backend Backend
|
|
|
|
func assertBackend () {
|
|
if backend == nil { panic("nil backend") }
|
|
}
|
|
|
|
// SetBackend sets the backend that functions in this package will call upon.
|
|
// This function will panic if there is already a backend running.
|
|
func SetBackend (back Backend) {
|
|
backendLock.Lock()
|
|
defer backendLock.Unlock()
|
|
|
|
if backend != nil {
|
|
panic("SetBackend called while another backend was running")
|
|
}
|
|
backend = back
|
|
}
|