zntg/ui/rendererfactory.go

42 lines
1.2 KiB
Go

package ui
import (
"errors"
"opslag.de/schobers/geom"
)
// RendererFactory can be used to inject a new factory for creating renderers.
type RendererFactory interface {
New(title string, width, height int, opts NewRendererOptions) (Renderer, error)
}
var rendererFactory RendererFactory
// NewRenderer creates a new renderer based on the registered renderer factory.
func NewRenderer(title string, width, height int, opts NewRendererOptions) (Renderer, error) {
if rendererFactory == nil {
return nil, errors.New("no renderer factory registered")
}
return rendererFactory.New(title, width, height, opts)
}
// NewRendererDefault creates a new renderer with default options set based on the registered renderer factory.
func NewRendererDefault(title string, width, height int) (Renderer, error) {
return rendererFactory.New(title, width, height, NewRendererOptions{
Resizable: true,
})
}
// SetRendererFactory sets the new factory that is used to create a new renderer.
func SetRendererFactory(factory RendererFactory) {
rendererFactory = factory
}
// NewRendererOptions provides options when creating a new renderer.
type NewRendererOptions struct {
Location *geom.PointF32
Resizable bool
VSync bool
}