Compare commits

...

2 Commits

Author SHA1 Message Date
d096d40c57 Add a way for applications to request canvases
Makes fix to #14 useful
2024-06-03 19:29:41 -04:00
34358da6eb Add canvas.CanvasCloser
Remedy #14
2024-06-03 19:28:03 -04:00
3 changed files with 18 additions and 0 deletions

View File

@ -29,6 +29,10 @@ type Backend interface {
// reject any texture that was not made by it.
NewTexture (image.Image) canvas.TextureCloser
// NewCanvas creates a new canvas with the specified bounds. The backend
// must reject any canvas that was not made by it.
NewCanvas (image.Rectangle) canvas.CanvasCloser
// Run runs the event loop until Stop() is called, or the backend
// experiences a fatal error.
Run () error

View File

@ -77,6 +77,13 @@ type Canvas interface {
SubCanvas (image.Rectangle) Canvas
}
// CanvasCloser is a canvas that can be closed. Anything that receives a
// CanvasCloser must close it after use.
type CanvasCloser interface {
CanvasCloser
io.Closer
}
// Drawer can draw to a canvas.
type Drawer interface {
// Draw draws to the given canvas.

View File

@ -93,3 +93,10 @@ func NewTexture (source image.Image) canvas.TextureCloser {
assertBackend()
return backend.NewTexture(source)
}
// NewCanvas creates a new canvas with the specified bounds. When no longer in
// use, it must be freed using Close().
func NewCanvas (bounds image.Rectangle) canvas.CanvasCloser {
assertBackend()
return backend.NewTexture(bounds)
}