op/paint: remove support for PaintOp.Rect

PaintOp.Rect is the wrong abstraction; it implies a clip operation
better handled by package clip, and not all paints need it (colors).
Furthermore, it's awkward to specify a PaintOp that fills up the
current clip area, regardless of its size.

Redefine PathOp to mean "fill current clip area".

API change. Replace uses of PaintOp.Rect with a TransformOp applied
before the PaintOp.

Leave a TODO for the PathOp infinity area.

Fixes gio#167

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-11-05 16:09:55 +01:00
parent afb52194d1
commit 94d242d18c
19 changed files with 93 additions and 106 deletions
+1 -1
View File
@@ -287,5 +287,5 @@ func drawInk(gtx layout.Context, c widget.Press) {
}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(size), Y: float32(size)}}}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
}
+1 -3
View File
@@ -48,9 +48,7 @@ func (l LoaderStyle) Layout(gtx layout.Context) layout.Dimensions {
Color: l.Color,
}.Add(gtx.Ops)
op.Offset(f32.Pt(-float32(radius), -float32(radius))).Add(gtx.Ops)
paint.PaintOp{
Rect: f32.Rectangle{Max: layout.FPt(sz)},
}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
op.InvalidateOp{}.Add(gtx.Ops)
return layout.Dimensions{
Size: sz,
+1 -4
View File
@@ -32,9 +32,6 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
rr := float32(gtx.Px(unit.Dp(2)))
d := image.Point{X: int(width), Y: gtx.Px(maxHeight)}
dr := f32.Rectangle{
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
}
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{X: width, Y: float32(gtx.Px(maxHeight))}},
@@ -42,7 +39,7 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{Rect: dr}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
return layout.Dimensions{Size: d}
}
+3 -3
View File
@@ -73,7 +73,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
}
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{Rect: track}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
// Draw track after thumb.
@@ -82,7 +82,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
track.Max.X = float32(size.X) - halfWidth
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: f32color.MulAlpha(color, 96)}.Add(gtx.Ops)
paint.PaintOp{Rect: track}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
// Draw thumb.
@@ -103,7 +103,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{Rect: thumb}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
return layout.Dimensions{Size: size}
+2 -2
View File
@@ -62,7 +62,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
}.Add(gtx.Ops)
paint.ColorOp{Color: trackColor}.Add(gtx.Ops)
paint.PaintOp{Rect: trackRect}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
stack.Pop()
// Draw thumb ink.
@@ -133,5 +133,5 @@ func drawDisc(ops *op.Ops, sz float32, col color.RGBA) {
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(ops)
paint.ColorOp{Color: col}.Add(ops)
paint.PaintOp{Rect: r}.Add(ops)
paint.PaintOp{}.Add(ops)
}