blob: 4f0bd01fd941abf3e316dbb279710c471bdc7779 [file] [log] [blame]
Guido van Rossum2d844d11991-04-07 13:41:50 +00001# A FormSplit lets you place its children exactly where you want them
2# (including silly places!).
3# It does no explicit geometry management except moving its children
4# when it is moved.
5# The interface to place children is as follows.
6# Before you add a child, you may specify its (left, top) position
7# relative to the FormSplit. If you don't specify a position for
8# a child, it goes right below the previous child; the first child
9# goes to (0, 0) by default.
10# NB: This places data attributes named form_* on its children.
11# XXX Yes, I know, there should be options to do all sorts of relative
12# placement, but for now this will do.
13
14from Split import Split
15
16class FormSplit() = Split():
17 #
18 def create(self, parent):
19 self.next_left = self.next_top = 0
20 self.last_child = None
21 return Split.create(self, parent)
22 #
23 def minsize(self, m):
24 max_width, max_height = 0, 0
25 for c in self.children:
26 c.form_width, c.form_height = c.minsize(m)
27 max_width = max(max_width, c.form_width + c.form_left)
28 max_height = max(max_height, c.form_height + c.form_top)
29 return max_width, max_height
30 #
31 def getbounds(self):
32 return self.bounds
33 #
34 def setbounds(self, bounds):
35 self.bounds = bounds
36 fleft, ftop = bounds[0]
37 for c in self.children:
38 left, top = c.form_left + fleft, c.form_top + ftop
39 right, bottom = left + c.form_width, top + c.form_height
40 c.setbounds((left, top), (right, bottom))
41 #
42 def placenext(self, (left, top)):
43 self.next_left = left
44 self.next_top = top
45 self.last_child = None
46 #
47 def addchild(self, child):
48 if self.last_child:
49 width, height = \
50 self.last_child.minsize(self.beginmeasuring())
51 self.next_top = self.next_top + height
52 child.form_left = self.next_left
53 child.form_top = self.next_top
54 Split.addchild(self, child)
55 self.last_child = child
56 #