github.com/jmigpin/editor@v1.6.0/ui/shadow.go (about)

     1  package ui
     2  
     3  import (
     4  	"github.com/jmigpin/editor/util/uiutil/widget"
     5  )
     6  
     7  var (
     8  	ShadowsOn     = true
     9  	shadowMaxDiff = 0.25
    10  )
    11  
    12  func WrapInTopShadowOrSeparator(ctx widget.ImageContext, content widget.Node) widget.Node {
    13  	if ShadowsOn {
    14  		s := widget.NewTopShadow(ctx, content)
    15  		s.MaxDiff = shadowMaxDiff
    16  		s2 := &topShadow2{s}
    17  		return s2
    18  	} else {
    19  		bl := widget.NewBoxLayout()
    20  		bl.YAxis = true
    21  		rect := widget.NewRectangle(ctx)
    22  		rect.SetThemePaletteNamePrefix("shadowsep_")
    23  		rect.Size.Y = separatorWidth
    24  		bl.Append(rect, content)
    25  		bl.SetChildFlex(content, true, true)
    26  		bl.SetChildFill(rect, true, true)
    27  		return bl
    28  	}
    29  }
    30  
    31  //----------
    32  
    33  func WrapInBottomShadowOrNone(ctx widget.ImageContext, content widget.Node) widget.Node {
    34  	if !ShadowsOn {
    35  		return content
    36  	}
    37  	s := widget.NewBottomShadow(ctx, content)
    38  	s.MaxDiff = shadowMaxDiff
    39  	s2 := &bottomShadow2{s}
    40  	return s2
    41  }
    42  
    43  //----------
    44  
    45  type topShadow2 struct {
    46  	*widget.TopShadow
    47  }
    48  
    49  func (s *topShadow2) OnThemeChange() {
    50  	ff := s.FirstChild().Embed().TreeThemeFontFace()
    51  	s.TopShadow.Height = UIThemeUtil.ShadowHeight(ff)
    52  }
    53  
    54  //----------
    55  
    56  type bottomShadow2 struct {
    57  	*widget.BottomShadow
    58  }
    59  
    60  func (s *bottomShadow2) OnThemeChange() {
    61  	ff := s.FirstChild().Embed().TreeThemeFontFace()
    62  	s.BottomShadow.Height = UIThemeUtil.ShadowHeight(ff)
    63  }