func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64) {
	c := &boxLayoutCell{
		widget: widget,
		fill:   fill,
		view:   NewViewPort(b.view, 0, 0, 0, 0),
	}
	c.widget.SetView(c.view)
	if index < 0 {
		index = 0
	}
	if index > len(b.cells) {
		index = len(b.cells)
	}
	b.cells = append(b.cells, c)
	copy(b.cells[index+1:], b.cells[index:])
	b.cells[index] = c
	widget.Watch(b)
	b.layout()
	b.PostEventWidgetContent(b)
}
InsertWidget inserts a widget at the given offset.  Offset 0 is the
front.  If the index is longer than the number of widgets, then it
just gets appended to the end.
package views
import (
	"github.com/gdamore/tcell"
)
type BoxLayout struct {
	view    View
	orient  Orientation
	style   tcell.Style  
	cells   []*boxLayoutCell
	width   int
	height  int
	changed bool
	WidgetWatchers
}
type boxLayoutCell struct {
	widget Widget
	fill   float64  
	pad    int      
	frac   float64  
	view   *ViewPort
}
func (b *BoxLayout) hLayout() {
	w, h := b.view.Size()
	totf := 0.0
	for _, c := range b.cells {
		x, y := c.widget.Size()
		totf += c.fill
		b.width += x
		if y > b.height {
			b.height = y
		}
		c.pad = 0
		c.frac = 0
	}
	extra := w - b.width
	if extra < 0 {
		extra = 0
	}
	resid := extra
	if totf == 0 {
		resid = 0
	}
	for _, c := range b.cells {
		if c.fill > 0 {
			c.frac = float64(extra) * c.fill / totf
			c.pad = int(c.frac)
			c.frac -= float64(c.pad)
			resid -= c.pad
		}
	}
	for resid > 0 {
		var best *boxLayoutCell
		for _, c := range b.cells {
			if c.fill == 0 {
				continue
			}
			if best == nil || c.frac > best.frac {
				best = c
			}
		}
		best.pad++
		best.frac = 0
		resid--
	}
	x, y, xinc := 0, 0, 0
	for _, c := range b.cells {
		cw, _ := c.widget.Size()
		xinc = cw + c.pad
		cw += c.pad
		c.view.Resize(x, y, cw, h)
		x += xinc
	}
}
func (b *BoxLayout) vLayout() {
	w, h := b.view.Size()
	totf := 0.0
	for _, c := range b.cells {
		x, y := c.widget.Size()
		b.height += y
		totf += c.fill
		if x > b.width {
			b.width = x
		}
		c.pad = 0
		c.frac = 0
	}
	extra := h - b.height
	if extra < 0 {
		extra = 0
	}
	resid := extra
	if totf == 0 {
		resid = 0
	}
	for _, c := range b.cells {
		if c.fill > 0 {
			c.frac = float64(extra) * c.fill / totf
			c.pad = int(c.frac)
			c.frac -= float64(c.pad)
			resid -= c.pad
		}
	}
	for resid > 0 {
		var best *boxLayoutCell
		for _, c := range b.cells {
			if c.fill == 0 {
				continue
			}
			if best == nil || c.frac > best.frac {
				best = c
			}
		}
		best.pad++
		best.frac = 0
		resid--
	}
	x, y, yinc := 0, 0, 0
	for _, c := range b.cells {
		_, ch := c.widget.Size()
		yinc = ch + c.pad
		ch += c.pad
		c.view.Resize(x, y, w, ch)
		y += yinc
	}
}
func (b *BoxLayout) layout() {
	if b.view == nil {
		return
	}
	b.width, b.height = 0, 0
	switch b.orient {
	case Horizontal:
		b.hLayout()
	case Vertical:
		b.vLayout()
	default:
		panic("Bad orientation")
	}
	b.changed = false
}
func (b *BoxLayout) Resize() {
	b.layout()
	for i := range b.cells {
		b.cells[i].widget.Resize()
	}
	b.PostEventWidgetResize(b)
}
func (b *BoxLayout) Draw() {
	if b.view == nil {
		return
	}
	if b.changed {
		b.layout()
	}
	b.view.Fill('*', b.style)
	w, h := b.view.Size()
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			b.view.SetContent(x, y, ' ', nil, b.style)
		}
	}
	for i := range b.cells {
		b.cells[i].widget.Draw()
	}
}
func (b *BoxLayout) Size() (int, int) {
	return b.width, b.height
}
func (b *BoxLayout) SetView(view View) {
	b.changed = true
	b.view = view
	for _, c := range b.cells {
		c.view.SetView(view)
	}
}
func (b *BoxLayout) HandleEvent(ev tcell.Event) bool {
	switch ev.(type) {
	case *EventWidgetContent:
		b.changed = true
		b.PostEventWidgetContent(b)
		return true
	}
	for _, c := range b.cells {
		if c.widget.HandleEvent(ev) {
			return true
		}
	}
	return false
}
func (b *BoxLayout) AddWidget(widget Widget, fill float64) {
	c := &boxLayoutCell{
		widget: widget,
		fill:   fill,
		view:   NewViewPort(b.view, 0, 0, 0, 0),
	}
	widget.SetView(c.view)
	b.cells = append(b.cells, c)
	b.changed = true
	widget.Watch(b)
	b.layout()
	b.PostEventWidgetContent(b)
}