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
@@ -70,7 +70,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
Y: halfWidth + trackWidth/2,
},
}
clip.Rect{Rect: track}.Add(gtx.Ops)
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{Rect: track}.Add(gtx.Ops)
st.Pop()
@@ -79,7 +79,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
st = op.Push(gtx.Ops)
track.Min.X = thumbPos
track.Max.X = float32(size.X) - halfWidth
clip.Rect{Rect: track}.Add(gtx.Ops)
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: mulAlpha(color, 96)}.Add(gtx.Ops)
paint.PaintOp{Rect: track}.Add(gtx.Ops)
st.Pop()
@@ -97,7 +97,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
},
}
rr := thumbRadius
clip.Rect{
clip.RRect{
Rect: thumb,
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)