github.com/jmigpin/editor@v1.6.0/util/uiutil/widget/shadow.go (about) 1 package widget 2 3 import ( 4 "image" 5 6 "github.com/jmigpin/editor/util/imageutil" 7 ) 8 9 type TopShadow struct { 10 ENode 11 Height int 12 MaxDiff float64 13 ctx ImageContext 14 } 15 16 func NewTopShadow(ctx ImageContext, content Node) *TopShadow { 17 s := &TopShadow{ctx: ctx, MaxDiff: 0.30, Height: 10} 18 s.Append(content) 19 return s 20 } 21 22 func (s *TopShadow) OnChildMarked(child Node, newMarks Marks) { 23 if newMarks.HasAny(MarkNeedsLayout) { 24 s.MarkNeedsLayout() 25 } 26 if newMarks.HasAny(MarkNeedsPaint | MarkChildNeedsPaint) { 27 s.MarkNeedsPaint() 28 } 29 } 30 31 func (s *TopShadow) ChildsPaintTree() { 32 // childs are painted first at the top of Paint() 33 } 34 func (s *TopShadow) Paint() { 35 s.ENode.ChildsPaintTree() 36 37 r := s.Bounds 38 r.Max.Y = r.Min.Y + s.Height 39 r = r.Intersect(s.Bounds) 40 41 imageutil.PaintShadow(s.ctx.Image(), r, s.Height, s.MaxDiff) 42 } 43 44 //---------- 45 46 type BottomShadow struct { 47 *BoxLayout 48 Height int 49 MaxDiff float64 50 ctx ImageContext 51 content Node 52 } 53 54 func NewBottomShadow(ctx ImageContext, content Node) *BottomShadow { 55 s := &BottomShadow{ 56 ctx: ctx, MaxDiff: 0.30, Height: 10, content: content, 57 } 58 59 s.BoxLayout = NewBoxLayout() 60 s.YAxis = true 61 62 bsp := &BottomShadowPart{bs: s} 63 64 s.Append(content, bsp) 65 s.SetChildFlex(content, false, false) 66 s.SetChildFill(bsp, true, false) 67 68 return s 69 } 70 71 //---------- 72 73 type BottomShadowPart struct { 74 ENode 75 bs *BottomShadow 76 } 77 78 func (s *BottomShadowPart) Measure(hint image.Point) image.Point { 79 w := image.Point{0, s.bs.Height} 80 w = imageutil.MinPoint(w, hint) 81 return w 82 } 83 func (s *BottomShadowPart) Paint() { 84 imageutil.PaintShadow(s.bs.ctx.Image(), s.Bounds, s.bs.Height, s.bs.MaxDiff) 85 } 86 87 //----------