aboutsummaryrefslogtreecommitdiff
path: root/lib/HVSplit.py
blob: d52af8eea9859fc30415bf1be4572c30d0e1d71b (plain)
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
# HVSplit contains generic code for HSplit and VSplit.
# HSplit and VSplit are specializations to either dimension.

# XXX This does not yet stretch/shrink children if there is too much
# XXX or too little space in the split dimension.
# XXX (NB There is no interface to ask children for stretch preferences.)

from Split import Split

class HVSplit() = Split():
 #
 def create(self, (parent, hv)):
 # hv is 0 or 1 for HSplit or VSplit
 self = Split.create(self, parent)
 self.hv = hv
 return self
 #
 def minsize(self, m):
 hv, vh = self.hv, 1 - self.hv
 size = [0, 0]
 for c in self.children:
 csize = c.minsize(m)
 if csize[vh] > size[vh]: size[vh] = csize[vh]
 size[hv] = size[hv] + csize[hv]
 return size[0], size[1]
 #
 def getbounds(self):
 return self.bounds
 #
 def setbounds(self, bounds):
 self.bounds = bounds
 hv, vh = self.hv, 1 - self.hv
 mf = self.parent.beginmeasuring
 size = self.minsize(mf())
 # XXX not yet used! Later for stretching
 maxsize_hv = bounds[1][hv] - bounds[0][hv]
 origin = [self.bounds[0][0], self.bounds[0][1]]
 for c in self.children:
 size = c.minsize(mf())
 corner = [0, 0]
 corner[vh] = bounds[1][vh]
 corner[hv] = origin[hv] + size[hv]
 c.setbounds((origin[0], origin[1]), \
 (corner[0], corner[1]))
 origin[hv] = corner[hv]
 # XXX stretch
 # XXX too-small
 #

class HSplit() = HVSplit():
 def create(self, parent):
 return HVSplit.create(self, (parent, 0))

class VSplit() = HVSplit():
 def create(self, parent):
 return HVSplit.create(self, (parent, 1))