mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
op/clip: expose Circle.Path and RRect.Path.
These can be nicely used together with clip.Stroke. Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+14
-19
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
@@ -23,24 +22,20 @@ type Border struct {
|
||||
func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
|
||||
dims := w(gtx)
|
||||
sz := dims.Size
|
||||
|
||||
rr := float32(gtx.Px(b.CornerRadius))
|
||||
st := op.Save(gtx.Ops)
|
||||
width := gtx.Px(b.Width)
|
||||
sz.X -= width
|
||||
sz.Y -= width
|
||||
op.Offset(f32.Point{
|
||||
X: float32(width) * 0.5,
|
||||
Y: float32(width) * 0.5,
|
||||
}).Add(gtx.Ops)
|
||||
clip.Border{
|
||||
Rect: f32.Rectangle{
|
||||
Max: layout.FPt(sz),
|
||||
},
|
||||
NE: rr, NW: rr, SE: rr, SW: rr,
|
||||
Width: float32(width),
|
||||
}.Add(gtx.Ops)
|
||||
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
st.Load()
|
||||
width := float32(gtx.Px(b.Width))
|
||||
|
||||
r := f32.Rectangle{Max: layout.FPt(sz)}
|
||||
r = r.Add(f32.Point{X: width * 0.5, Y: width * 0.5})
|
||||
|
||||
paint.FillShape(gtx.Ops,
|
||||
b.Color,
|
||||
clip.Stroke{
|
||||
Path: clip.UniformRRect(r, rr).Path(gtx.Ops),
|
||||
Style: clip.StrokeStyle{Width: width},
|
||||
}.Op(),
|
||||
)
|
||||
|
||||
return dims
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user