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") } renderer, err := rendererFactory.New(title, width, height, opts) if err != nil { return nil, err } renderer.SetResourceProvider(DefaultResources()) return renderer, nil } // 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 NewRenderer(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 Borderless bool Resizable bool VSync bool }