def do_allocate(self, x, y, width, height, requested_width, requested_height, origin_changed): (columns, width) = self.__get_columns(width) # Shouldn't happen, do something sane if it does if height < self.__min_height: height = self.__min_height line_heights = layout_utils.compute_lengths(height, self.__line_min_height, self.__line_natural_height) # to_shrink = self.__natural_height - height # if to_shrink >= 0: # line_heights = copy.copy(self.__line_natural_height) # # We were allocated less than our natural height. We want to shrink lines # # as equally as possible, but no line more than it's maximum shrink. # # # # To do this, we process the lines in order of the available shrink from # # least available shrink to most # # # shrinks = [] # for i in range(0, self.__line_count): # shrinks.append((i, self.__line_natural_height[i] - self.__line_min_height[i])) # shrinks.sort(key=lambda t: t[1]) # lines_remaining = self.__line_count # for (i, shrink) in shrinks: # # If we can shrink the rest of the lines equally, do that. Otherwise # # shrink this line as much as possible # if shrink * lines_remaining >= to_shrink: # shrink = to_shrink // lines_remaining # line_heights[i] -= shrink # lines_remaining -= 1 # to_shrink -= shrink # else: # line_heights = self.__line_natural_height line_index = 0 line_item_count = 0 item_x = 0 item_y = 0 for box_child in self.__box.get_layout_children(): if (box_child.is_header or line_item_count == columns) and line_item_count > 0: item_y += line_heights[line_index] + self.__row_spacing line_item_count = 0 line_index += 1 item_x = 0 if box_child.is_header: box_child.allocate(x, y + item_y, width, line_heights[line_index], origin_changed) item_y += line_heights[line_index] + self.__row_spacing line_index += 1 else: new_x = ((line_item_count + 1) * (width + self.__column_spacing)) / columns item_width = new_x - item_x - self.__column_spacing box_child.allocate(x + item_x, y + item_y, item_width, line_heights[line_index], origin_changed) item_x = new_x line_item_count += 1
def __compute_row_heights(self, height): return layout_utils.compute_lengths(height, self.__min_heights, self.__natural_heights, self.__expand_rows)
def __compute_column_widths(self, width): return layout_utils.compute_lengths(width, self.__min_widths, self.__natural_widths, self.__expand_columns)