@@ 25,6 25,7 @@ import (
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
+ "gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
@@ 312,7 313,10 @@ func (t *Transition) Layout(gtx *layout.Context) {
clipCenter := f32.Point{X: diameter / 2, Y: diameter / 2}
off := op.TransformOp{}.Offset(center.Sub(clipCenter))
off.Add(gtx.Ops)
- rrect(gtx.Ops, diameter, diameter, radius, radius, radius, radius)
+ clip.RoundRect(gtx.Ops,
+ f32.Rectangle{Max: f32.Point{X: diameter, Y: diameter}},
+ radius, radius, radius, radius,
+ ).Add(gtx.Ops)
off.Invert().Add(gtx.Ops)
fill{rgb(0xffffff)}.Layout(gtx)
}
@@ 727,7 731,11 @@ func (b *Background) Layout(gtx *layout.Context, w layout.Widget) {
if r > height/2 {
r = height / 2
}
- rrect(gtx.Ops, width, height, r, r, r, r)
+ clip.RoundRect(gtx.Ops,
+ f32.Rectangle{Max: f32.Point{
+ X: width, Y: height,
+ }}, r, r, r, r,
+ ).Add(gtx.Ops)
}
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: width, Y: height}}}.Add(gtx.Ops)
@@ 1265,7 1273,10 @@ func (cc *clipCircle) Layout(gtx *layout.Context, w layout.Widget) {
rr := szf * .5
var stack op.StackOp
stack.Push(gtx.Ops)
- rrect(gtx.Ops, szf, szf, rr, rr, rr, rr)
+ clip.RoundRect(gtx.Ops,
+ f32.Rectangle{Max: f32.Point{X: szf, Y: szf}},
+ rr, rr, rr, rr,
+ ).Add(gtx.Ops)
macro.Add(gtx.Ops)
stack.Pop()
}
@@ 1292,20 1303,3 @@ func (ic *icon) image(c unit.Converter, col color.RGBA) paint.ImageOp {
ic.imgSize = sz
return ic.op
}
-
-// https://pomax.github.io/bezierinfo/#circles_cubic.
-func rrect(ops *op.Ops, width, height, se, sw, nw, ne float32) {
- w, h := float32(width), float32(height)
- const c = 0.55228475 // 4*(sqrt(2)-1)/3
- var b paint.Path
- b.Begin(ops)
- b.Move(f32.Point{X: w, Y: h - se})
- b.Cube(f32.Point{X: 0, Y: se * c}, f32.Point{X: -se + se*c, Y: se}, f32.Point{X: -se, Y: se}) // SE
- b.Line(f32.Point{X: sw - w + se, Y: 0})
- b.Cube(f32.Point{X: -sw * c, Y: 0}, f32.Point{X: -sw, Y: -sw + sw*c}, f32.Point{X: -sw, Y: -sw}) // SW
- b.Line(f32.Point{X: 0, Y: nw - h + sw})
- b.Cube(f32.Point{X: 0, Y: -nw * c}, f32.Point{X: nw - nw*c, Y: -nw}, f32.Point{X: nw, Y: -nw}) // NW
- b.Line(f32.Point{X: w - ne - nw, Y: 0})
- b.Cube(f32.Point{X: ne * c, Y: 0}, f32.Point{X: ne, Y: ne - ne*c}, f32.Point{X: ne, Y: ne}) // NE
- b.End().Add(ops)
-}