clip: add Path method to Rect

Useful when drawing non-rounded rectangles with Stroke.
Also, this makes it consistent with RRect and Circle which
also have a Path method.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-11-04 21:02:51 +01:00
committed by Elias Naur
parent 3e0b72304a
commit 3f25a49c75
+9 -4
View File
@@ -18,10 +18,7 @@ type Rect image.Rectangle
func (r Rect) Op() Op { func (r Rect) Op() Op {
return Op{ return Op{
outline: true, outline: true,
path: PathSpec{ path: r.Path(),
shape: ops.Rect,
bounds: image.Rectangle(r),
},
} }
} }
@@ -30,6 +27,14 @@ func (r Rect) Push(ops *op.Ops) Stack {
return r.Op().Push(ops) return r.Op().Push(ops)
} }
// Path returns the PathSpec for the rectangle.
func (r Rect) Path() PathSpec {
return PathSpec{
shape: ops.Rect,
bounds: image.Rectangle(r),
}
}
// UniformRRect returns an RRect with all corner radii set to the // UniformRRect returns an RRect with all corner radii set to the
// provided radius. // provided radius.
func UniformRRect(rect f32.Rectangle, radius float32) RRect { func UniformRRect(rect f32.Rectangle, radius float32) RRect {