Try casting to PhysicalResources first when setting resource provider.
SetResourceProvider accepts Resources instead of factory method to it.
This commit is contained in:
parent
67e73a8671
commit
de87c5d3aa
@ -331,15 +331,20 @@ func (r *Renderer) SetMouseCursor(c ui.MouseCursor) {
|
|||||||
|
|
||||||
func (r *Renderer) SetPosition(p geom.PointF32) { r.disp.SetPosition(int(p.X), int(p.Y)) }
|
func (r *Renderer) SetPosition(p geom.PointF32) { r.disp.SetPosition(int(p.X), int(p.Y)) }
|
||||||
|
|
||||||
func (r *Renderer) SetResourceProvider(factory func() ui.Resources) {
|
func (r *Renderer) SetResourceProvider(res ui.Resources) {
|
||||||
if r.res != nil {
|
if r.res != nil {
|
||||||
r.res.Destroy()
|
r.res.Destroy()
|
||||||
}
|
}
|
||||||
res, err := ui.NewCopyResources("allg5ui", factory(), false)
|
|
||||||
if err != nil {
|
if phys, ok := res.(ui.PhysicalResources); ok {
|
||||||
return
|
r.res = phys
|
||||||
|
} else {
|
||||||
|
copy, err := ui.NewCopyResources("allg5ui", res, false)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.res = copy
|
||||||
}
|
}
|
||||||
r.res = res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) SetUnhandledEventHandler(handler func(allg5.Event)) {
|
func (r *Renderer) SetUnhandledEventHandler(handler func(allg5.Event)) {
|
||||||
|
@ -473,15 +473,20 @@ func (r *Renderer) TextTexture(font ui.Font, color color.Color, text string) (ui
|
|||||||
|
|
||||||
func (r *Renderer) Resources() ui.Resources { return r.resources }
|
func (r *Renderer) Resources() ui.Resources { return r.resources }
|
||||||
|
|
||||||
func (r *Renderer) SetResourceProvider(factory func() ui.Resources) {
|
func (r *Renderer) SetResourceProvider(resources ui.Resources) {
|
||||||
if r.resources != nil {
|
if r.resources != nil {
|
||||||
r.resources.Destroy()
|
r.resources.Destroy()
|
||||||
}
|
}
|
||||||
resources, err := ui.NewCopyResources("sdlui", factory(), false)
|
|
||||||
if err != nil {
|
if physical, ok := resources.(ui.PhysicalResources); ok {
|
||||||
return
|
r.resources = physical
|
||||||
|
} else {
|
||||||
|
copy, err := ui.NewCopyResources("sdlui", resources, false)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.resources = copy
|
||||||
}
|
}
|
||||||
r.resources = resources
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture
|
// Texture
|
||||||
|
@ -41,7 +41,7 @@ type Renderer interface {
|
|||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
Resources() Resources
|
Resources() Resources
|
||||||
SetResourceProvider(factory func() Resources)
|
SetResourceProvider(resources Resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextTexture renders specified text to a new texture.
|
// TextTexture renders specified text to a new texture.
|
||||||
|
@ -22,7 +22,7 @@ func NewRenderer(title string, width, height int, opts NewRendererOptions) (Rend
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
renderer.SetResourceProvider(func() Resources { return DefaultResources() })
|
renderer.SetResourceProvider(DefaultResources())
|
||||||
return renderer, nil
|
return renderer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user