op/clip: split Rect into pixel-aligned Rect and rounded RRect

The pixel-aligned Rect is more efficient and easier to use in the common case
of layout clipping.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-07-09 18:06:00 +02:00
parent 4818538ef8
commit d572aa23ac
14 changed files with 105 additions and 116 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
}
trackColor := mulAlpha(col, 150)
op.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
clip.Rect{
clip.RRect{
Rect: trackRect,
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
}.Add(gtx.Ops)
@@ -74,7 +74,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
}
op.Offset(inkOff).Add(gtx.Ops)
gtx.Constraints.Min = image.Pt(inkSize, inkSize)
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{
Max: layout.FPt(gtx.Constraints.Min),
},
@@ -127,7 +127,7 @@ func drawDisc(ops *op.Ops, sz float32, col color.RGBA) {
defer op.Push(ops).Pop()
rr := sz / 2
r := f32.Rectangle{Max: f32.Point{X: sz, Y: sz}}
clip.Rect{
clip.RRect{
Rect: r,
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(ops)