op/clip: expose Circle.Path and RRect.Path.

These can be nicely used together with clip.Stroke.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2021-03-14 12:09:21 +02:00
committed by Elias Naur
parent a50a0db3a2
commit fecfbbb050
2 changed files with 31 additions and 31 deletions
+14 -19
View File
@@ -7,7 +7,6 @@ import (
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/unit"
@@ -23,24 +22,20 @@ type Border struct {
func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
dims := w(gtx)
sz := dims.Size
rr := float32(gtx.Px(b.CornerRadius))
st := op.Save(gtx.Ops)
width := gtx.Px(b.Width)
sz.X -= width
sz.Y -= width
op.Offset(f32.Point{
X: float32(width) * 0.5,
Y: float32(width) * 0.5,
}).Add(gtx.Ops)
clip.Border{
Rect: f32.Rectangle{
Max: layout.FPt(sz),
},
NE: rr, NW: rr, SE: rr, SW: rr,
Width: float32(width),
}.Add(gtx.Ops)
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Load()
width := float32(gtx.Px(b.Width))
r := f32.Rectangle{Max: layout.FPt(sz)}
r = r.Add(f32.Point{X: width * 0.5, Y: width * 0.5})
paint.FillShape(gtx.Ops,
b.Color,
clip.Stroke{
Path: clip.UniformRRect(r, rr).Path(gtx.Ops),
Style: clip.StrokeStyle{Width: width},
}.Op(),
)
return dims
}