func (l *SplitterLayout) LayoutChildren() { s := l.outer.Size().Contract(l.Padding()) o := l.Padding().LT() children := l.outer.Children() splitterCount := len(children) / 2 splitterWidth := l.splitterWidth if l.orientation.Horizontal() { s.W -= splitterWidth * splitterCount } else { s.H -= splitterWidth * splitterCount } netWeight := float32(0.0) for i, c := range children { if isSplitter := (i & 1) == 1; !isSplitter { netWeight += l.weights[c.Control] } } d := 0 for i, c := range children { var cr math.Rect if isSplitter := (i & 1) == 1; !isSplitter { cm := c.Control.Margin() frac := l.weights[c.Control] / netWeight if l.orientation.Horizontal() { cw := int(float32(s.W) * frac) cr = math.CreateRect(d+cm.L, cm.T, d+cw-cm.R, s.H-cm.B) d += cw } else { ch := int(float32(s.H) * frac) cr = math.CreateRect(cm.L, d+cm.T, s.W-cm.R, d+ch-cm.B) d += ch } } else { if l.orientation.Horizontal() { cr = math.CreateRect(d, 0, d+splitterWidth, s.H) } else { cr = math.CreateRect(0, d, s.W, d+splitterWidth) } d += splitterWidth } c.Layout(cr.Offset(o).Canon()) } }
func (l *TableLayout) LayoutChildren() { s := l.outer.Size().Contract(l.outer.Padding()) o := l.outer.Padding().LT() cw, ch := s.W/l.columns, s.H/l.rows var cr math.Rect for _, c := range l.outer.Children() { cm := c.Control.Margin() cell := l.grid[c.Control] x, y := cell.x*cw, cell.y*ch w, h := x+cell.w*cw, y+cell.h*ch cr = math.CreateRect(x+cm.L, y+cm.T, w-cm.R, h-cm.B) c.Layout(cr.Offset(o).Canon()) } }