1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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)
}
}
|