diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-22 23:15:13 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2018-02-22 23:15:13 +0100 |
commit | 4bca49f807544bd948a5f5f78e3787411252650f (patch) | |
tree | 5014acfd25b349488fd8116dccccac714bedb65d /testfiles/column.txt | |
download | poe-4bca49f807544bd948a5f5f78e3787411252650f.tar.gz poe-4bca49f807544bd948a5f5f78e3787411252650f.tar.bz2 poe-4bca49f807544bd948a5f5f78e3787411252650f.zip |
first commit
Diffstat (limited to 'testfiles/column.txt')
-rw-r--r-- | testfiles/column.txt | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/testfiles/column.txt b/testfiles/column.txt new file mode 100644 index 0000000..d7f24cf --- /dev/null +++ b/testfiles/column.txt @@ -0,0 +1,58 @@ +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) + } +} |