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
+4 -4
View File
@@ -89,7 +89,7 @@ func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) la
return layout.Stack{}.Layout(gtx,
layout.Expanded(button.Layout),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{
X: float32(gtx.Constraints.Min.X),
Y: float32(gtx.Constraints.Min.Y),
@@ -122,7 +122,7 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
return layout.Stack{Alignment: layout.Center}.Layout(gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
rr := float32(gtx.Px(b.CornerRadius))
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{
X: float32(gtx.Constraints.Min.X),
Y: float32(gtx.Constraints.Min.Y),
@@ -153,7 +153,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
size := gtx.Constraints.Min.X
sizef := float32(size)
rr := sizef * .5
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{X: sizef, Y: sizef}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
@@ -282,7 +282,7 @@ func drawInk(gtx layout.Context, c widget.Press) {
X: -rr,
Y: -rr,
})).Add(gtx.Ops)
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{
X: float32(size),
Y: float32(size),
+1 -1
View File
@@ -35,7 +35,7 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
}
clip.Rect{
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{X: width, Y: float32(gtx.Px(maxHeight))}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
+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)
+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)