diff --git a/allg5ui/rendererfactory.go b/allg5ui/rendererfactory.go index f1358f5..6d24112 100644 --- a/allg5ui/rendererfactory.go +++ b/allg5ui/rendererfactory.go @@ -11,11 +11,7 @@ func init() { type rendererFactory struct{} -func (f rendererFactory) New(title string, width, height int) (ui.Renderer, error) { - return f.NewOptions(title, width, height, ui.NewRendererOptions{Resizable: true}) -} - -func (f rendererFactory) NewOptions(title string, width, height int, opts ui.NewRendererOptions) (ui.Renderer, error) { +func (f rendererFactory) New(title string, width, height int, opts ui.NewRendererOptions) (ui.Renderer, error) { renderer, err := NewRenderer(width, height, allg5.NewDisplayOptions{ Resizable: opts.Resizable, Vsync: opts.VSync, diff --git a/sdlui/rendererfactory.go b/sdlui/rendererfactory.go index 6d2d6ca..2a43028 100644 --- a/sdlui/rendererfactory.go +++ b/sdlui/rendererfactory.go @@ -11,11 +11,7 @@ func init() { type rendererFactory struct{} -func (f rendererFactory) New(title string, width, height int) (ui.Renderer, error) { - return f.NewOptions(title, width, height, ui.NewRendererOptions{Resizable: true}) -} - -func (f rendererFactory) NewOptions(title string, width, height int, opts ui.NewRendererOptions) (ui.Renderer, error) { +func (f rendererFactory) New(title string, width, height int, opts ui.NewRendererOptions) (ui.Renderer, error) { return NewRenderer(title, int32(width), int32(height), NewRendererOptions{ Location: sdl.Point{X: sdl.WINDOWPOS_UNDEFINED, Y: sdl.WINDOWPOS_UNDEFINED}, Resizable: opts.Resizable, diff --git a/ui/examples/01_basic/basic.go b/ui/examples/01_basic/basic.go index 542ee10..b07477e 100644 --- a/ui/examples/01_basic/basic.go +++ b/ui/examples/01_basic/basic.go @@ -116,7 +116,7 @@ func (b *basic) Init(ctx ui.Context) error { } func run() error { - var render, err = ui.NewRenderer("Basic Example", 800, 600) + var render, err = ui.NewRendererDefault("Basic Example", 800, 600) if err != nil { return err } diff --git a/ui/rendererfactory.go b/ui/rendererfactory.go index a80a0a8..d89154a 100644 --- a/ui/rendererfactory.go +++ b/ui/rendererfactory.go @@ -6,18 +6,26 @@ import ( "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) (Renderer, error) - NewOptions(title string, width, height int, opts NewRendererOptions) (Renderer, error) + New(title string, width, height int, opts NewRendererOptions) (Renderer, error) } var rendererFactory RendererFactory -func NewRenderer(title string, width, height int) (Renderer, error) { +// 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) + 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. @@ -25,6 +33,7 @@ func SetRendererFactory(factory RendererFactory) { rendererFactory = factory } +// NewRendererOptions provides options when creating a new renderer. type NewRendererOptions struct { Location *geom.PointF32 Resizable bool