~gioverse/chat

9068d14be6496e2b9acc8b68712d132e54cf4f00 — Jack Mordaunt 4 months ago 18b40f7
widget: allow method chaining

It's common to use this type to cache and then immediately use.
Chaining would allow this to occur on a single line:

    picture.Cache(img).Op()

Rather than forcing a multi line approach:

    picture.Cache(img)
    picture.Op()

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
1 files changed, 3 insertions(+), 2 deletions(-)

M widget/image.go
M widget/image.go => widget/image.go +3 -2
@@ 20,13 20,14 @@ func (ci *CachedImage) Reload() {
// Cache the image if it is not already.
// First call will compute the image operation, subsequent calls will noop.
// When reloaded, cache will re-populated on next invocation.
func (img *CachedImage) Cache(src image.Image) {
func (img *CachedImage) Cache(src image.Image) *CachedImage {
	if img == nil || src == nil {
		return
		return img
	}
	if img.op == (paint.ImageOp{}) || img.changed() {
		img.op = paint.NewImageOp(src)
	}
	return img
}

// Op returns the concrete image operation.