def size(self, dialog): """ Recalculate the size of the Scrollable. @param dialog Dialog which contains us """ if dialog is None: return Widget.size(self, dialog) if self.is_fixed_size: self.width, self.height = self.max_width, self.max_height self.hscrollbar_height = dialog.theme["hscrollbar"]["left"]["image"].height self.vscrollbar_width = dialog.theme["vscrollbar"]["up"]["image"].width if self.root_group is None: # do we need to re-clone dialog groups? self.theme = dialog.theme self.batch = dialog.batch self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group) self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group) self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group) self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group) self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group) Wrapper.delete(self) # force children to abandon old groups Wrapper.size(self, self) # all children are to use our groups if self.always_show_scrollbars or (self.max_width and self.width > self.max_width): if self.hscrollbar is None: self.hscrollbar = HScrollbar(self.max_width) else: if self.hscrollbar is not None: self.hscrollbar.delete() self.hscrollbar = None if self.always_show_scrollbars or (self.max_height and self.height > self.max_height): if self.vscrollbar is None: self.vscrollbar = VScrollbar(self.max_height) else: if self.vscrollbar is not None: self.vscrollbar.delete() self.vscrollbar = None self.width = min(self.max_width or self.width, self.width) self.content_width = self.width self.height = min(self.max_height or self.height, self.height) self.content_height = self.height if self.hscrollbar is not None: self.hscrollbar.size(dialog) self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width)) self.height += self.hscrollbar.height if self.vscrollbar is not None: self.vscrollbar.size(dialog) self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height)) self.width += self.vscrollbar.width
def size(self, dialog): """ The default Wrapper wraps up its Widget snugly. @param dialog The Dialog which contains the Wrapper """ if dialog is None: return Widget.size(self, dialog) if self.content is not None: self.content.size(dialog) self.width, self.height = self.content.width, self.content.height else: self.width = self.height = 0
def size(self, dialog): """ Calculates size of the layout, based on its children. @param dialog The Dialog which contains the layout """ if dialog is None: return Widget.size(self, dialog) height = 0 if len(self.content) < 2: width = 0 else: width = -self.padding for item in self.content: item.size(dialog) height = max(height, item.height) width += item.width + self.padding self.width, self.height = width, height self.expandable = [x for x in self.content if x.is_expandable()]
def size(self, dialog): """Recalculates our size and the maximum widths and heights of each row and column in our table. @param dialog The Dialog within which we are contained """ if dialog is None: return Widget.size(self, dialog) self.max_heights = [0] * len(self.content) width = 0 for row in self.content: width = max(width, len(row)) self.max_widths = [self.padding] * width row_index = 0 for row in self.content: max_height = self.padding col_index = 0 for cell in row: if cell is not None: cell.size(dialog) width, height = cell.width, cell.height else: width = height = 0 max_height = max(max_height, height + self.padding) max_width = self.max_widths[col_index] max_width = max(max_width, width + self.padding) self.max_widths[col_index] = max_width col_index += 1 self.max_heights[row_index] = max_height row_index += 1 if self.max_widths: self.width = reduce(lambda x, y: x + y, self.max_widths) \ - self.padding else: self.width = 0 if self.max_heights: self.height = reduce(lambda x, y: x + y, self.max_heights) \ - self.padding else: self.height = 0
def size(self, dialog): """ Recalculate the size of the Scrollable. @param dialog Dialog which contains us """ if dialog is None: return Widget.size(self, dialog) if self.is_fixed_size: self.width, self.height = self.max_width, self.max_height self.hscrollbar_height = \ dialog.theme['hscrollbar']['left']['image'].height self.vscrollbar_width = \ dialog.theme['vscrollbar']['up']['image'].width if self.root_group is None: # do we need to re-clone dialog groups? self.theme = dialog.theme self.batch = dialog.batch self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group) self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group) self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group) self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group) self.highlight_group = pyglet.graphics.OrderedGroup( 3, self.root_group) Wrapper.delete(self) # force children to abandon old groups Wrapper.size(self, self) # all children are to use our groups if self.always_show_scrollbars or \ (self.max_width and self.width > self.max_width): if self.hscrollbar is None: self.hscrollbar = HScrollbar(self.max_width) else: if self.hscrollbar is not None: self.hscrollbar.delete() self.hscrollbar = None if self.always_show_scrollbars or \ (self.max_height and self.height > self.max_height): if self.vscrollbar is None: self.vscrollbar = VScrollbar(self.max_height) else: if self.vscrollbar is not None: self.vscrollbar.delete() self.vscrollbar = None self.width = min(self.max_width or self.width, self.width) self.content_width = self.width self.height = min(self.max_height or self.height, self.height) self.content_height = self.height if self.hscrollbar is not None: self.hscrollbar.size(dialog) self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width)) self.height += self.hscrollbar.height if self.vscrollbar is not None: self.vscrollbar.size(dialog) self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height)) self.width += self.vscrollbar.width