github.com/Seikaijyu/gio@v0.0.1/widget/border.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package widget 4 5 import ( 6 "image" 7 "image/color" 8 9 "github.com/Seikaijyu/gio/layout" 10 "github.com/Seikaijyu/gio/op/clip" 11 "github.com/Seikaijyu/gio/op/paint" 12 "github.com/Seikaijyu/gio/unit" 13 ) 14 15 // Border lays out a widget and draws a border inside it. 16 type Border struct { 17 Color color.NRGBA 18 CornerRadius unit.Dp 19 Width unit.Dp 20 } 21 22 func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions { 23 dims := w(gtx) 24 sz := dims.Size 25 26 rr := gtx.Dp(b.CornerRadius) 27 width := gtx.Dp(b.Width) 28 whalf := (width + 1) / 2 29 sz.X -= whalf * 2 30 sz.Y -= whalf * 2 31 32 r := image.Rectangle{Max: sz} 33 r = r.Add(image.Point{X: whalf, Y: whalf}) 34 35 paint.FillShape(gtx.Ops, 36 b.Color, 37 clip.Stroke{ 38 Path: clip.UniformRRect(r, rr).Path(gtx.Ops), 39 Width: float32(width), 40 }.Op(), 41 ) 42 43 return dims 44 }