package main type Columns []*Column type Column struct { x, y int w, h int windows []*Window } // Add adds a new column and resizes. It returns the index of the newly created column. func (cs Columns) Add() Columns { nw, nh := screen.Size() var nx, ny int if len(cs) > 0 { nx = cs[len(cs)-1].x + cs[len(cs)-1].w/2 nw = cs[len(cs)-1].w / 2 cs[len(cs)-1].w /= 2 } newcol := &Column{nx, ny, nw, nh, nil} newwin := NewWindow("") newcol.windows = append(newcol.windows, newwin) cs = append(cs, newcol) return cs } func (c *Column) AddWindow(win *Window) { c.windows = append(c.windows, win) c.ResizeInternal() } func (c *Column) Resize(x, y, w, h int) { c.x, c.y = x, y c.w, c.h = w, h c.ResizeInternal() } func (c *Column) ResizeInternal() { var n int for i := range c.windows { if c.windows[i].visible { n++ } } remainder := c.h % n for i, win := range c.windows { if i == 0 { win.Resize(c.x, c.y, c.w, c.h/n+remainder) continue } win.Resize(c.x, c.y+(c.h/n)*(i)+remainder, c.w, c.h/n) } }