forked from joejulian/gio
be89f8b945
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>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package clip
|
|
|
|
// Stroke represents a stroked path.
|
|
type Stroke struct {
|
|
Path PathSpec
|
|
Style StrokeStyle
|
|
}
|
|
|
|
// Op returns a clip operation representing the stroke.
|
|
func (s Stroke) Op() Op {
|
|
return Op{
|
|
path: s.Path,
|
|
stroke: s.Style,
|
|
}
|
|
}
|
|
|
|
// StrokeStyle describes how a path should be stroked.
|
|
type StrokeStyle struct {
|
|
Width float32 // Width of the stroked path.
|
|
|
|
// Miter is the limit to apply to a miter joint.
|
|
// The zero Miter disables the miter joint; setting Miter to +∞
|
|
// unconditionally enables the miter joint.
|
|
Miter float32
|
|
Cap StrokeCap // Cap describes the head or tail of a stroked path.
|
|
Join StrokeJoin // Join describes how stroked paths are collated.
|
|
}
|
|
|
|
// StrokeCap describes the head or tail of a stroked path.
|
|
type StrokeCap uint8
|
|
|
|
const (
|
|
// FlatCap caps stroked paths with a flat cap, joining the right-hand
|
|
// and left-hand sides of a stroked path with a straight line.
|
|
FlatCap StrokeCap = iota
|
|
|
|
// SquareCap caps stroked paths with a square cap, joining the right-hand
|
|
// and left-hand sides of a stroked path with a half square of length
|
|
// the stroked path's width.
|
|
SquareCap
|
|
|
|
// RoundCap caps stroked paths with a round cap, joining the right-hand and
|
|
// left-hand sides of a stroked path with a half disc of diameter the
|
|
// stroked path's width.
|
|
RoundCap
|
|
)
|
|
|
|
// StrokeJoin describes how stroked paths are collated.
|
|
type StrokeJoin uint8
|
|
|
|
const (
|
|
// BevelJoin joins path segments with sharp bevels.
|
|
BevelJoin StrokeJoin = iota
|
|
|
|
// RoundJoin joins path segments with a round segment.
|
|
RoundJoin
|
|
)
|