diff --git a/layout/list.go b/layout/list.go index cd32005d..97329f6c 100644 --- a/layout/list.go +++ b/layout/list.go @@ -5,6 +5,7 @@ package layout import ( "image" + "gioui.org/f32" "gioui.org/gesture" "gioui.org/io/pointer" "gioui.org/op" @@ -248,7 +249,7 @@ func (l *List) layout() Dimensions { } var stack op.StackOp stack.Push(ops) - clip.Rect(r).Add(ops) + clip.Rect(ops, toRectF(r)).Add(ops) op.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, pos, cross))).Add(ops) child.macro.Add(ops) stack.Pop() @@ -267,3 +268,10 @@ func (l *List) layout() Dimensions { l.macro.Add(ops) return Dimensions{Size: dims} } + +func toRectF(r image.Rectangle) f32.Rectangle { + return f32.Rectangle{ + Min: f32.Point{X: float32(r.Min.X), Y: float32(r.Min.Y)}, + Max: f32.Point{X: float32(r.Max.X), Y: float32(r.Max.Y)}, + } +} diff --git a/op/clip/clip.go b/op/clip/clip.go index 47a44470..68e28bb4 100644 --- a/op/clip/clip.go +++ b/op/clip/clip.go @@ -284,9 +284,17 @@ func (p *Path) End() Op { } } -// Rect returns the clip area of a pixel aligned rectangular area. -func Rect(r image.Rectangle) Op { - return Op{bounds: toRectF(r)} +// Rect returns the clip area of a rectangle. +func Rect(ops *op.Ops, r f32.Rectangle) Op { + ri := image.Rectangle{ + Min: image.Point{X: int(r.Min.X), Y: int(r.Min.Y)}, + Max: image.Point{X: int(r.Max.X), Y: int(r.Max.Y)}, + } + // Optimize pixel-aligned rectangles to just its bounds. + if r == toRectF(ri) { + return Op{bounds: r} + } + return RoundRect(ops, r, 0, 0, 0, 0) } // RoundRect returns the clip area of a rectangle with rounded diff --git a/widget/material/image.go b/widget/material/image.go index 318de388..6a4c2bef 100644 --- a/widget/material/image.go +++ b/widget/material/image.go @@ -37,7 +37,7 @@ func (im Image) Layout(gtx *layout.Context) { d := image.Point{X: cs.Width.Constrain(w), Y: cs.Height.Constrain(h)} var s op.StackOp s.Push(gtx.Ops) - clip.Rect(image.Rectangle{Max: d}).Add(gtx.Ops) + clip.Rect(gtx.Ops, f32.Rectangle{Max: toPointF(d)}).Add(gtx.Ops) im.Src.Add(gtx.Ops) paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(w), Y: float32(h)}}}.Add(gtx.Ops) s.Pop()