@@ -984,7 +984,7 @@ def draw(self):
984984 image (im7 , 0 , im4 .height , height = self .height - im1 .height - im4 .height , color = clr )
985985 image (im8 , self .width - im8 .width , im4 .height , height = self .height - im2 .height - im5 .height , color = clr )
986986 image (im9 , im4 .width , im6 .height , width = self .width - im7 .width - im8 .width , height = self .height - im3 .height - im6 .height , color = clr )
987-
987+
988988 def on_mouse_enter (self , mouse ):
989989 mouse .cursor = DEFAULT
990990
@@ -1090,14 +1090,15 @@ def __getattr__(self, k):
10901090 def apply (self , spacing = 0 ):
10911091 """ Adjusts the position and size of the controls to match the layout.
10921092 """
1093- pass
1093+ self .width = max (control .width for control in self )
1094+ self .height = max (control .height for control in self )
10941095
10951096 def __repr__ (self ):
10961097 return "Layout(type=%s)" % repr (self .__class__ .__name__ .lower ())
10971098
10981099 # Debug mode:
10991100 #def draw(self):
1100- # rect(0, 0, self.width, self.height, fill=None, stroke=(1,1,1, 0.5), strokestyle="dotted" )
1101+ # rect(0, 0, self.width, self.height, fill=None, stroke=(0, 0.5,1,1) )
11011102
11021103#--- Layout: Labeled ----------------------------------------------------------------------------------
11031104
@@ -1159,28 +1160,25 @@ def apply(self, spacing=10):
11591160 # adjusting mw at the start will make controls wider to line out with the total width,
11601161 # adjusting it at the end would just ensure that the layout is wide enough.
11611162 mw = max (mw , control .width )
1162- w1 = max ([ caption .width for caption in self .captions ] )
1163- w2 = max ([ control .width for control in self .controls ] )
1163+ w1 = max (caption .width for caption in self .captions )
1164+ w2 = max (control .width for control in self .controls )
11641165 w2 = min (w2 , mw )
11651166 dx = 0
11661167 dy = 0
11671168 for caption , control in reversed (zip (self .captions , self .controls )):
1168- caption .x = dx + w1 - caption .width # halign right.
1169- control .x = dx + w1 + (w1 > 0 and spacing )
1170- caption .y = dy + 0.5 * (control .height - caption .height ) # valign center.
1171- control .y = dy
11721169 if isinstance (control , Layout ) and control .height > caption .height * 2 :
11731170 caption .y = dy + control .height - caption .height # valign top.
11741171 if isinstance (control , (Label , Button , Slider , Field )):
11751172 control ._set_width (mw )
11761173 control ._pack ()
1174+ caption .x = dx + w1 - caption .width # halign right.
1175+ control .x = dx + w1 + (w1 > 0 and spacing )
1176+ caption .y = dy + 0.5 * (control .height - caption .height ) # valign center.
1177+ control .y = dy
11771178 dy += max (caption .height , control .height , 10 ) + spacing
1178- self .width = w1 + w2 + (w1 > 0 and spacing )
1179+ self .width = w1 + max ( w2 , mw ) + (w1 > 0 and spacing )
11791180 self .height = dy - spacing
11801181
1181- #def draw(self):
1182- # rect(0, 0, self.width, self.height, fill=None, stroke=[1,1,1,1])
1183-
11841182TOP , CENTER = "top" , "center"
11851183
11861184class Row (Labeled ):
@@ -1201,18 +1199,18 @@ def apply(self, spacing=10):
12011199 """
12021200 mw = self ._maxwidth
12031201 da = self ._align == TOP and 1.0 or 0.5
1204- h1 = max ([ control .height for control in self .controls ] )
1205- h2 = max ([ caption .height for caption in self .captions ] )
1202+ h1 = max (control .height for control in self .controls )
1203+ h2 = max (caption .height for caption in self .captions )
12061204 dx = 0
12071205 dy = 0
12081206 for caption , control in zip (self .captions , self .controls ):
1207+ if isinstance (control , (Label , Button , Slider , Field )):
1208+ control ._set_width (mw )
1209+ control ._pack ()
12091210 caption .x = dx + 0.5 * max (control .width - caption .width , 0 ) # halign center
12101211 control .x = dx + 0.5 * max (caption .width - control .width , 0 ) # halign center
12111212 caption .y = dy + h1 + (h2 > 0 and spacing )
12121213 control .y = dy + da * (h1 - control .height ) # valign center
1213- if isinstance (control , (Label , Button , Slider , Field )):
1214- control ._set_width (mw )
1215- control ._pack ()
12161214 dx += max (caption .width , control .width , 10 ) + spacing
12171215 self .width = dx - spacing
12181216 self .height = h1 + h2 + (h2 > 0 and spacing )
0 commit comments