forked from joejulian/gio
all: introduce Outline and Stroke builders
This CL introduces 2 new path builders:
- Outline which takes a PathSpec to be outlined
- Stroke which takes a PathSpec and a stroke style, to stroke a path.
typically, code like this:
var p clip.Path
...
p.Outline().Add(o)
should be replaced with:
var p clip.Path
...
clip.Outline{Path: p.End()}.Op().Add(o)
similarly, stroking should be modified from:
var p clip.Path
...
p.Stroke(width, clip.StrokeStyle{...}).Add(o)
to:
var p clip.Path
...
clip.Stroke{Path: p.End(), Style: clip.StrokeStyle{Width:...}}.Op().Add(o)
here are tentative 'rf' scripts (see rsc.io/rf for more details):
```
ex {
import "gioui.org/op";
import "gioui.org/op/clip";
var p clip.Path;
var o *op.Ops;
p.Outline().Add(o) -> clip.Outline{Path:p.End()}.Op().Add(o);
}
ex {
import "gioui.org/op";
import "gioui.org/op/clip";
var o *op.Ops;
var p clip.Path;
var sty clip.StrokeStyle;
var width float32;
p.Stroke(width, sty).Add(o) -> \
clip.Stroke{ \
Path:p.End(), \
Style: clip.StrokeStyle{ \
Width: width, \
}}.Op().Add(o);
}
```
Signed-off-by: Sebastien Binet <s@sbinet.org>
This commit is contained in:
committed by
Elias Naur
parent
7c5bcd3db8
commit
be89f8b945
+10
-4
@@ -36,7 +36,10 @@ func (rr RRect) Op(ops *op.Ops) Op {
|
||||
p.Begin(ops)
|
||||
p.Move(rr.Rect.Min)
|
||||
roundRect(&p, rr.Rect.Size(), rr.SE, rr.SW, rr.NW, rr.NE)
|
||||
return p.Outline()
|
||||
|
||||
return Outline{
|
||||
Path: p.End(),
|
||||
}.Op()
|
||||
}
|
||||
|
||||
// Add the rectangle clip.
|
||||
@@ -49,7 +52,6 @@ type Border struct {
|
||||
// Rect is the bounds of the border.
|
||||
Rect f32.Rectangle
|
||||
Width float32
|
||||
Style StrokeStyle
|
||||
// The corner radii.
|
||||
SE, SW, NW, NE float32
|
||||
}
|
||||
@@ -58,11 +60,15 @@ type Border struct {
|
||||
func (b Border) Op(ops *op.Ops) Op {
|
||||
var p Path
|
||||
p.Begin(ops)
|
||||
|
||||
p.Move(b.Rect.Min)
|
||||
roundRect(&p, b.Rect.Size(), b.SE, b.SW, b.NW, b.NE)
|
||||
|
||||
return p.Stroke(b.Width, b.Style)
|
||||
return Stroke{
|
||||
Path: p.End(),
|
||||
Style: StrokeStyle{
|
||||
Width: b.Width,
|
||||
},
|
||||
}.Op()
|
||||
}
|
||||
|
||||
// Add the border clip.
|
||||
|
||||
Reference in New Issue
Block a user