github.com/jmigpin/editor@v1.6.0/util/uiutil/widget/splbg.go (about)

     1  package widget
     2  
     3  // Wraps a StartPercentLayout with a node that fills the first space background.
     4  type SplBg struct {
     5  	ENode
     6  	Spl *StartPercentLayout
     7  	Bg  Node
     8  }
     9  
    10  func NewSplBg(bg Node) *SplBg {
    11  	l := &SplBg{
    12  		Spl: NewStartPercentLayout(),
    13  		Bg:  bg,
    14  	}
    15  	l.Append(l.Bg, l.Spl)
    16  	return l
    17  }
    18  
    19  func (l *SplBg) OnChildMarked(child Node, newMarks Marks) {
    20  	if child == l.Spl {
    21  		// need layout to adjust the bg node
    22  		if newMarks.HasAny(MarkNeedsLayout) {
    23  			l.MarkNeedsLayout()
    24  		}
    25  	}
    26  }
    27  
    28  func (l *SplBg) Layout() {
    29  	if l.Spl.ChildsLen() > 0 {
    30  		// layout SPL first to calc "Bg" size based on SPL first child
    31  		l.Spl.Layout()
    32  
    33  		// redimension "Bg" to match first row start
    34  		min := &l.Spl.FirstChild().Embed().Bounds.Min
    35  		max := &l.Bg.Embed().Bounds.Max
    36  		if l.Spl.YAxis {
    37  			max.Y = min.Y
    38  		} else {
    39  			max.X = min.X
    40  		}
    41  	}
    42  }