forked from joejulian/gio
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:
@@ -43,14 +43,9 @@ func TestClipping(t *testing.T) {
|
||||
w, release := newTestWindow(t)
|
||||
defer release()
|
||||
|
||||
sz := w.size
|
||||
col := color.RGBA{A: 0xff, R: 0xca, G: 0xfe}
|
||||
col2 := color.RGBA{A: 0xff, R: 0x00, G: 0xfe}
|
||||
var ops op.Ops
|
||||
pop := paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{
|
||||
X: float32(sz.X),
|
||||
Y: float32(sz.Y),
|
||||
}}}
|
||||
paint.ColorOp{Color: col}.Add(&ops)
|
||||
clip.RRect{
|
||||
Rect: f32.Rectangle{
|
||||
@@ -59,7 +54,7 @@ func TestClipping(t *testing.T) {
|
||||
},
|
||||
SE: 75,
|
||||
}.Add(&ops)
|
||||
pop.Add(&ops)
|
||||
paint.PaintOp{}.Add(&ops)
|
||||
paint.ColorOp{Color: col2}.Add(&ops)
|
||||
clip.RRect{
|
||||
Rect: f32.Rectangle{
|
||||
@@ -68,7 +63,7 @@ func TestClipping(t *testing.T) {
|
||||
},
|
||||
NW: 75,
|
||||
}.Add(&ops)
|
||||
pop.Add(&ops)
|
||||
paint.PaintOp{}.Add(&ops)
|
||||
if err := w.Frame(&ops); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
+8
-23
@@ -25,7 +25,6 @@ import (
|
||||
gunsafe "gioui.org/internal/unsafe"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
)
|
||||
|
||||
type GPU struct {
|
||||
@@ -216,26 +215,6 @@ func decodeLinearGradientOp(data []byte) linearGradientOpData {
|
||||
}
|
||||
}
|
||||
|
||||
func decodePaintOp(data []byte) paint.PaintOp {
|
||||
bo := binary.LittleEndian
|
||||
if opconst.OpType(data[0]) != opconst.TypePaint {
|
||||
panic("invalid op")
|
||||
}
|
||||
r := f32.Rectangle{
|
||||
Min: f32.Point{
|
||||
X: math.Float32frombits(bo.Uint32(data[1:])),
|
||||
Y: math.Float32frombits(bo.Uint32(data[5:])),
|
||||
},
|
||||
Max: f32.Point{
|
||||
X: math.Float32frombits(bo.Uint32(data[9:])),
|
||||
Y: math.Float32frombits(bo.Uint32(data[13:])),
|
||||
},
|
||||
}
|
||||
return paint.PaintOp{
|
||||
Rect: r,
|
||||
}
|
||||
}
|
||||
|
||||
type clipType uint8
|
||||
|
||||
type resource interface {
|
||||
@@ -854,12 +833,18 @@ loop:
|
||||
state.matType = materialTexture
|
||||
state.image = decodeImageOp(encOp.Data, encOp.Refs)
|
||||
case opconst.TypePaint:
|
||||
op := decodePaintOp(encOp.Data)
|
||||
// Transform (if needed) the painting rectangle and if so generate a clip path,
|
||||
// for those cases also compute a partialTrans that maps texture coordinates between
|
||||
// the new bounding rectangle and the transformed original paint rectangle.
|
||||
trans, off := splitTransform(state.t)
|
||||
clipData, bnd, partialTrans := d.boundsForTransformedRect(op.Rect, trans)
|
||||
// Fill the clip area, unless the material is a (bounded) image.
|
||||
// TODO: Find a tighter bound.
|
||||
inf := float32(1e6)
|
||||
dst := f32.Rect(-inf, -inf, inf, inf)
|
||||
if state.matType == materialTexture {
|
||||
dst = layout.FRect(state.image.src.Rect)
|
||||
}
|
||||
clipData, bnd, partialTrans := d.boundsForTransformedRect(dst, trans)
|
||||
clip := state.clip.Intersect(bnd.Add(off))
|
||||
if clip.Empty() {
|
||||
continue
|
||||
|
||||
@@ -36,7 +36,7 @@ const (
|
||||
TypeLayerLen = 1
|
||||
TypeRedrawLen = 1 + 8
|
||||
TypeImageLen = 1
|
||||
TypePaintLen = 1 + 4*4
|
||||
TypePaintLen = 1
|
||||
TypeColorLen = 1 + 4
|
||||
TypeLinearGradientLen = 1 + 8*2 + 4*2
|
||||
TypeAreaLen = 1 + 1 + 4*4
|
||||
|
||||
@@ -171,7 +171,7 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
c := r.Stop()
|
||||
|
||||
for x := 0; x < 100; x++ {
|
||||
@@ -228,7 +228,7 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
|
||||
r := op.Record(ops)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
c := r.Stop()
|
||||
|
||||
squares.Add(ops)
|
||||
|
||||
@@ -81,7 +81,8 @@ func TestPaintArc(t *testing.T) {
|
||||
func TestPaintTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 80, 80)}.Add(o)
|
||||
scale(80.0/512, 80.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.Blue)
|
||||
r.expect(79, 10, colornames.Green)
|
||||
@@ -94,7 +95,8 @@ func TestPaintClippedTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
squares.Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 80, 80)}.Add(o)
|
||||
scale(80.0/512, 80.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(40, 40, colornames.White)
|
||||
r.expect(25, 35, colornames.Blue)
|
||||
|
||||
@@ -35,10 +35,10 @@ func TestTransformMacro(t *testing.T) {
|
||||
stack := op.Push(o)
|
||||
op.Offset(f32.Pt(0, 10)).Add(o)
|
||||
|
||||
// Actually create the text clip-path
|
||||
// Apply the clip-path.
|
||||
c.Add(o)
|
||||
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
stack.Pop()
|
||||
|
||||
c2 := m2.Stop()
|
||||
@@ -124,7 +124,7 @@ func constSqCirc() op.CallOp {
|
||||
func drawChild(ops *op.Ops, text op.CallOp) op.CallOp {
|
||||
r1 := op.Record(ops)
|
||||
text.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
return r1.Stop()
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
s := op.Push(o)
|
||||
op.Offset(f32.Pt(0, off)).Add(o)
|
||||
txt.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
s.Pop()
|
||||
}
|
||||
|
||||
@@ -184,7 +184,8 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
func TestNegativeOverlaps(t *testing.T) {
|
||||
run(t, func(ops *op.Ops) {
|
||||
clip.RRect{Rect: f32.Rect(50, 50, 100, 100)}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 120, 100, 122)}.Add(ops)
|
||||
clip.Rect(image.Rect(0, 120, 100, 122)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
}, func(r result) {
|
||||
r.expect(60, 60, colornames.White)
|
||||
r.expect(60, 110, colornames.White)
|
||||
@@ -207,6 +208,8 @@ var gradients = []Gradient{
|
||||
}
|
||||
|
||||
func TestLinearGradient(t *testing.T) {
|
||||
t.Skip("linear gradients don't support transformations")
|
||||
|
||||
const gradienth = 8
|
||||
// 0.5 offset from ends to ensure that the center of the pixel
|
||||
// aligns with gradient from and to colors.
|
||||
@@ -214,7 +217,7 @@ func TestLinearGradient(t *testing.T) {
|
||||
samples := []int{0, 12, 32, 64, 96, 115, 127}
|
||||
|
||||
run(t, func(ops *op.Ops) {
|
||||
gr := pixelAligned
|
||||
gr := f32.Rect(0, 0, 128, gradienth)
|
||||
for _, g := range gradients {
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(gr.Min.X, gr.Min.Y),
|
||||
@@ -222,7 +225,12 @@ func TestLinearGradient(t *testing.T) {
|
||||
Stop2: f32.Pt(gr.Max.X, gr.Min.Y),
|
||||
Color2: g.To,
|
||||
}.Add(ops)
|
||||
paint.PaintOp{Rect: gr}.Add(ops)
|
||||
st := op.Push(ops)
|
||||
clip.RRect{Rect: gr}.Add(ops)
|
||||
op.Affine(f32.Affine2D{}.Offset(pixelAligned.Min)).Add(ops)
|
||||
scale(pixelAligned.Dx()/128, 1).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
gr = gr.Add(f32.Pt(0, gradienth))
|
||||
}
|
||||
}, func(r result) {
|
||||
@@ -247,7 +255,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 0),
|
||||
Color2: colornames.Red,
|
||||
}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 64, 64)}.Add(ops)
|
||||
st := op.Push(ops)
|
||||
clip.Rect(image.Rect(0, 0, 64, 64)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -255,7 +266,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 0),
|
||||
Color2: colornames.Green,
|
||||
}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(64, 0, 128, 64)}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
clip.Rect(image.Rect(64, 0, 128, 64)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -263,7 +277,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 128),
|
||||
Color2: colornames.Blue,
|
||||
}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(64, 64, 128, 128)}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
clip.Rect(image.Rect(64, 64, 128, 128)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -271,7 +288,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 128),
|
||||
Color2: colornames.Magenta,
|
||||
}.Add(ops)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 64, 64, 128)}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
clip.Rect(image.Rect(0, 64, 64, 128)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
}, func(r result) {})
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ func TestOffsetTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
op.Offset(f32.Pt(15, 15)).Add(o)
|
||||
squares.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o)
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(14, 20, colornames.White)
|
||||
r.expect(66, 20, colornames.White)
|
||||
@@ -118,7 +119,8 @@ func TestOffsetScaleTexture(t *testing.T) {
|
||||
op.Offset(f32.Pt(15, 15)).Add(o)
|
||||
squares.Add(o)
|
||||
op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(2, 1))).Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(0, 0, 50, 50)}.Add(o)
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(114, 64, colornames.Blue)
|
||||
r.expect(116, 64, colornames.White)
|
||||
@@ -127,10 +129,12 @@ func TestOffsetScaleTexture(t *testing.T) {
|
||||
|
||||
func TestRotateTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
defer op.Push(o).Pop()
|
||||
squares.Add(o)
|
||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), math.Pi/4)
|
||||
a := f32.Affine2D{}.Offset(f32.Pt(30, 30)).Rotate(f32.Pt(40, 40), math.Pi/4)
|
||||
op.Affine(a).Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
scale(20.0/512, 20.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(40, 40-12, colornames.Blue)
|
||||
r.expect(40+12, 40, colornames.Green)
|
||||
@@ -143,7 +147,9 @@ func TestRotateClipTexture(t *testing.T) {
|
||||
a := f32.Affine2D{}.Rotate(f32.Pt(40, 40), math.Pi/8)
|
||||
op.Affine(a).Add(o)
|
||||
clip.RRect{Rect: f32.Rect(30, 30, 50, 50)}.Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(10, 10, 70, 70)}.Add(o)
|
||||
op.Affine(f32.Affine2D{}.Offset(f32.Pt(10, 10))).Add(o)
|
||||
scale(60.0/512, 60.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
r.expect(37, 39, colornames.Green)
|
||||
@@ -164,8 +170,8 @@ func TestComplicatedTransform(t *testing.T) {
|
||||
op.Affine(a).Add(o)
|
||||
clip.RRect{Rect: f32.Rect(0, 0, 50, 40)}.Add(o)
|
||||
|
||||
op.Offset(f32.Pt(-100, -100)).Add(o)
|
||||
paint.PaintOp{Rect: f32.Rect(100, 100, 150, 150)}.Add(o)
|
||||
scale(50.0/512, 50.0/512).Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
}, func(r result) {
|
||||
r.expect(20, 5, colornames.White)
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"gioui.org/app/headless"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
"golang.org/x/image/colornames"
|
||||
@@ -210,3 +211,7 @@ func newWindow(t testing.TB, width, height int) *headless.Window {
|
||||
t.Cleanup(w.Release)
|
||||
return w
|
||||
}
|
||||
|
||||
func scale(sx, sy float32) op.TransformOp {
|
||||
return op.Affine(f32.Affine2D{}.Scale(f32.Point{}, f32.Pt(sx, sy)))
|
||||
}
|
||||
|
||||
+2
-17
@@ -43,12 +43,8 @@ type LinearGradientOp struct {
|
||||
Color2 color.RGBA
|
||||
}
|
||||
|
||||
// PaintOp fills an area with the current brush, respecting the
|
||||
// current clip path and transformation.
|
||||
// PaintOp fills fills the current clip area with the current brush.
|
||||
type PaintOp struct {
|
||||
// Rect is the destination area to paint. If necessary, the brush is
|
||||
// scaled to cover the rectangle area.
|
||||
Rect f32.Rectangle
|
||||
}
|
||||
|
||||
// NewImageOp creates an ImageOp backed by src. See
|
||||
@@ -139,11 +135,6 @@ func (c LinearGradientOp) Add(o *op.Ops) {
|
||||
func (d PaintOp) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypePaintLen)
|
||||
data[0] = byte(opconst.TypePaint)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], math.Float32bits(d.Rect.Min.X))
|
||||
bo.PutUint32(data[5:], math.Float32bits(d.Rect.Min.Y))
|
||||
bo.PutUint32(data[9:], math.Float32bits(d.Rect.Max.X))
|
||||
bo.PutUint32(data[13:], math.Float32bits(d.Rect.Max.Y))
|
||||
}
|
||||
|
||||
// FillShape fills the clip shape with a color.
|
||||
@@ -160,11 +151,5 @@ func FillShape(ops *op.Ops, c color.RGBA, shape clip.Op) {
|
||||
func Fill(ops *op.Ops, c color.RGBA) {
|
||||
defer op.Push(ops).Pop()
|
||||
ColorOp{Color: c}.Add(ops)
|
||||
inf := float32(1e6)
|
||||
PaintOp{
|
||||
Rect: f32.Rectangle{
|
||||
Min: f32.Pt(-inf, -inf),
|
||||
Max: f32.Pt(+inf, +inf),
|
||||
},
|
||||
}.Add(ops)
|
||||
PaintOp{}.Add(ops)
|
||||
}
|
||||
|
||||
+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