blob: 36192a707d8032bd99044e9bd71deb037b2f6d71 [file] [log] [blame]
Guido van Rossum2e449671990-11-05 19:44:36 +00001# HVSplit contains generic code for HSplit and VSplit.
2# HSplit and VSplit are specializations to either dimension.
3
Guido van Rossum52acae61991-01-23 13:41:53 +00004# XXX This does not yet stretch/shrink children if there is too much
5# XXX or too little space in the split dimension.
6# XXX (NB There is no interface to ask children for stretch preferences.)
7
Guido van Rossum2e449671990-11-05 19:44:36 +00008from Split import Split
9
10class HVSplit() = Split():
11 #
12 def create(self, (parent, hv)):
13 # hv is 0 or 1 for HSplit or VSplit
14 self = Split.create(self, parent)
15 self.hv = hv
16 return self
17 #
18 def minsize(self, m):
19 hv, vh = self.hv, 1 - self.hv
20 size = [0, 0]
21 for c in self.children:
22 csize = c.minsize(m)
23 if csize[vh] > size[vh]: size[vh] = csize[vh]
24 size[hv] = size[hv] + csize[hv]
25 return size[0], size[1]
26 #
27 def getbounds(self):
28 return self.bounds
29 #
30 def setbounds(self, bounds):
31 self.bounds = bounds
32 hv, vh = self.hv, 1 - self.hv
33 mf = self.parent.beginmeasuring
34 size = self.minsize(mf())
35 # XXX not yet used! Later for stretching
36 maxsize_hv = bounds[1][hv] - bounds[0][hv]
37 origin = [self.bounds[0][0], self.bounds[0][1]]
38 for c in self.children:
39 size = c.minsize(mf())
40 corner = [0, 0]
41 corner[vh] = bounds[1][vh]
42 corner[hv] = origin[hv] + size[hv]
43 c.setbounds((origin[0], origin[1]), \
44 (corner[0], corner[1]))
45 origin[hv] = corner[hv]
46 # XXX stretch
47 # XXX too-small
48 #
49
50class HSplit() = HVSplit():
51 def create(self, parent):
52 return HVSplit.create(self, (parent, 0))
53
54class VSplit() = HVSplit():
55 def create(self, parent):
56 return HVSplit.create(self, (parent, 1))