zntg/ui/rendererfactory.go
Sander Schobers 2c9007ce9b Added renderer factory.
- Removes dependency on the specific backend from an application point-of-view.
2020-05-12 22:46:58 +02:00

32 lines
733 B
Go

package ui
import (
"errors"
"opslag.de/schobers/geom"
)
type RendererFactory interface {
New(title string, width, height int) (Renderer, error)
NewOptions(title string, width, height int, opts NewRendererOptions) (Renderer, error)
}
var rendererFactory RendererFactory
func NewRenderer(title string, width, height int) (Renderer, error) {
if rendererFactory == nil {
return nil, errors.New("no renderer factory registered")
}
return rendererFactory.New(title, width, height)
}
// SetRendererFactory sets the new factory that is used to create a new renderer.
func SetRendererFactory(factory RendererFactory) {
rendererFactory = factory
}
type NewRendererOptions struct {
Location *geom.PointF32
Resizable bool
}