84203ce5a4600afddee9aebafa91138fb96f0e97 — Jack Mordaunt 1 year, 8 months ago 67742c9
widget/material: maintain size for empty images

If the image source is empty, we should maintain the specified size so
that the parent can rely on the Width and Height values they specified.

Prior to this patch, the layout would move around when the image was
empty one frame and present the next. This produces bad user experience
as the layout resizes as images pop in.

Such behaviour reliably occured when using an async.Loader to download

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

M widget/material/image.go
M widget/material/image.go => widget/material/image.go +4 -0
@@ 7,6 7,7 @@ import (

@@ 30,6 31,9 @@ func (img Image) Layout(gtx layout.Context) layout.Dimensions {
	if img.Height.V > 0 {
		gtx.Constraints.Max.Y = gtx.Constraints.Constrain(image.Pt(0, gtx.Px(img.Height))).Y
	if img.Image.Src == (paint.ImageOp{}) {
		return D{Size: gtx.Constraints.Max}
	defer op.Save(gtx.Ops).Load()
	macro := op.Record(gtx.Ops)
	dims := img.Image.Layout(gtx)