mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
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:
+1
-4
@@ -33,11 +33,8 @@ func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
|
||||
NE: rr, NW: rr, SE: rr, SW: rr,
|
||||
Width: float32(width),
|
||||
}.Add(gtx.Ops)
|
||||
dr := f32.Rectangle{
|
||||
Max: layout.FPt(sz),
|
||||
}
|
||||
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: dr}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
st.Pop()
|
||||
return dims
|
||||
}
|
||||
|
||||
+13
-9
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -7,7 +7,6 @@ import (
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
@@ -35,11 +34,7 @@ func NewIcon(data []byte) (*Icon, error) {
|
||||
func (ic *Icon) Layout(gtx layout.Context, sz unit.Value) layout.Dimensions {
|
||||
ico := ic.image(gtx.Px(sz))
|
||||
ico.Add(gtx.Ops)
|
||||
paint.PaintOp{
|
||||
Rect: f32.Rectangle{
|
||||
Max: layout.FPt(ico.Size()),
|
||||
},
|
||||
}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
return layout.Dimensions{
|
||||
Size: ico.Size(),
|
||||
}
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@ package widget
|
||||
import (
|
||||
"image"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
@@ -36,7 +35,7 @@ func (im Image) Layout(gtx layout.Context) layout.Dimensions {
|
||||
stack := op.Push(gtx.Ops)
|
||||
clip.Rect(image.Rectangle{Max: d}).Add(gtx.Ops)
|
||||
im.Src.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(w), Y: float32(h)}}}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
return layout.Dimensions{Size: d}
|
||||
}
|
||||
|
||||
+1
-2
@@ -106,12 +106,11 @@ func (l Label) Layout(gtx layout.Context, s text.Shaper, font text.Font, size un
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
lclip := layout.FRect(clip).Sub(off)
|
||||
stack := op.Push(gtx.Ops)
|
||||
op.Offset(off).Add(gtx.Ops)
|
||||
str := txt[start:end]
|
||||
s.ShapeString(font, textSize, str, l).Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: lclip}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
}
|
||||
return dims
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user