Files
gio-patched/widget/border.go
T
Elias Naur 94d242d18c 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>
2020-11-05 16:32:19 +01:00

41 lines
803 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package widget
import (
"image/color"
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/unit"
)
// Border lays out a widget and draws a border inside it.
type Border struct {
Color color.RGBA
CornerRadius unit.Value
Width unit.Value
}
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.Push(gtx.Ops)
width := gtx.Px(b.Width)
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.Pop()
return dims
}