5 from . import container
8 class _document_widget:
9 def __init__(self,w,align=None):
10 #w.rect.w,w.rect.h = w.resize()
13 if align != None: self.align = align
15 class Document(container.Container):
16 """A document is a container that structures widgets in a left-to-right flow."""
18 def __init__(self,**params):
19 params.setdefault('cls','document')
20 container.Container.__init__(self,**params)
21 self.layout = layout.Layout(pygame.Rect(0,0,self.rect.w,self.rect.h))
23 def add(self,e,align=None):
24 """Add a widget to the document flow.
28 align -- alignment (None,-1,0,1)
31 dw = _document_widget(e,align)
35 self.widgets.append(e)
39 self.layout._widgets.remove(e._c_dw)
40 self.widgets.remove(e)
44 def block(self,align):
45 """Start a new block given the alignment (-1, 0, 1)"""
46 self.layout.add(align)
48 def space(self, size):
49 """Add a spacer given the size."""
53 """Add a line break, given the height."""
54 self.layout.add((0, height))
56 def resize(self,width=None,height=None):
57 if self.style.width: width = self.style.width
58 if self.style.height: height = self.style.height
60 for w in self.widgets:
61 w.rect.w,w.rect.h = w.resize()
63 if (width != None and w.rect.w > width) or (height != None and w.rect.h > height):
64 w.rect.w,w.rect.h = w.resize(width,height)
67 dw.rect = pygame.Rect(0,0,w.rect.w,w.rect.h)
69 if width == None: width = 65535
70 self.layout.rect = pygame.Rect(0,0,width,0)
75 for w in self.widgets:
76 #xt,xl,xb,xr = w.getspacing()
78 w.style.x,w.style.y,w.rect.w,w.rect.h = dw.rect.x,dw.rect.y,dw.rect.w,dw.rect.h
80 w.rect.x,w.rect.y = w.style.x,w.style.y
81 _max_w = max(_max_w,w.rect.right)
83 #self.rect.w = _max_w #self.layout.rect.w
84 #self.rect.h = self.layout.rect.h
85 #print 'document',_max_w,self.layout.rect.h
86 return _max_w,self.layout.rect.h