# HG changeset patch # User Goffi # Date 1525000214 -7200 # Node ID 27b4ceb977c7a775a6ec842726ffc1c0b8fce039 # Parent f4522b7c3318e842128fc46690a06015d7167a7c widgets handler: keep proportion on resize diff -r f4522b7c3318 -r 27b4ceb977c7 cagou/core/widgets_handler.py --- a/cagou/core/widgets_handler.py Sun Apr 29 12:23:52 2018 +0200 +++ b/cagou/core/widgets_handler.py Sun Apr 29 13:10:14 2018 +0200 @@ -388,18 +388,39 @@ def __init__(self, **kwargs): super(WidgetsHandlerLayout, self).__init__(**kwargs) + self._layout_size = None # size used for the last layout fbind = self.fbind update = self._trigger_layout fbind('children', update) fbind('parent', update) - fbind('size', update) + fbind('size', self.adjust_prop) fbind('pos', update) @property def default_widget(self): return G.host.default_wid['factory'](G.host.default_wid, None, None) + def adjust_prop(self, handler, new_size): + """Adjust children proportion + + useful when this widget is resized (e.g. when going to fullscreen) + """ + if len(self.children) > 1: + old_width, old_height = self._layout_size + if not old_width or not old_height: + # we don't want division by zero + return self._trigger_layout(handler, new_size) + width_factor = float(self.width) / old_width + height_factor = float(self.height) / old_height + for child in self.children: + child.width *= width_factor + child.height *= height_factor + child.x *= width_factor + child.y *= height_factor + self._trigger_layout(handler, new_size) + def do_layout(self, *args): + self._layout_size = self.size[:] for child in self.children: # XXX: left must be calculated before right and bottom before top # because they are the pos, and are used to caculate size (right and top)