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
+13 -9
View File
@@ -19,6 +19,7 @@ import (
"gioui.org/io/pointer"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
@@ -432,7 +433,7 @@ func (e *Editor) PaintText(gtx layout.Context) {
stack := op.Push(gtx.Ops)
op.Offset(shape.offset).Add(gtx.Ops)
shape.clip.Add(gtx.Ops)
paint.PaintOp{Rect: layout.FRect(clip).Sub(shape.offset)}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
stack.Pop()
}
}
@@ -457,19 +458,22 @@ func (e *Editor) PaintCaret(gtx layout.Context) {
X: -e.scrollOff.X,
Y: -e.scrollOff.Y,
})
clip := textPadding(e.lines)
cl := textPadding(e.lines)
// Account for caret width to each side.
whalf := (carWidth / 2).Ceil()
if clip.Max.X < whalf {
clip.Max.X = whalf
if cl.Max.X < whalf {
cl.Max.X = whalf
}
if clip.Min.X > -whalf {
clip.Min.X = -whalf
if cl.Min.X > -whalf {
cl.Min.X = -whalf
}
clip.Max = clip.Max.Add(e.viewSize)
carRect = clip.Intersect(carRect)
cl.Max = cl.Max.Add(e.viewSize)
carRect = cl.Intersect(carRect)
if !carRect.Empty() {
paint.PaintOp{Rect: layout.FRect(carRect)}.Add(gtx.Ops)
st := op.Push(gtx.Ops)
clip.Rect(carRect).Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
}
}