From 4bca49f807544bd948a5f5f78e3787411252650f Mon Sep 17 00:00:00 2001 From: Petter Rodhelind Date: Thu, 22 Feb 2018 23:15:13 +0100 Subject: first commit --- testfiles/column.txt | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 testfiles/column.txt (limited to 'testfiles/column.txt') 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) + } +} -- cgit v1.2.3