From 6aadff4e87d9f4325ff8dc398f659047088c66db Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 7 Sep 2006 11:36:04 +0200 Subject: [PATCH] Simple grid layout --- sugar/canvas/GridLayout.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sugar/canvas/GridLayout.py diff --git a/sugar/canvas/GridLayout.py b/sugar/canvas/GridLayout.py new file mode 100644 index 00000000..224f42cb --- /dev/null +++ b/sugar/canvas/GridLayout.py @@ -0,0 +1,40 @@ +class GridConstraints: + def __init__(x, y, width, height): + self.x = x + self.y = y + self.width = width + self.height = height + +class GridLayout: + def __init__(self, rows, cols): + self._rows = rows + self._cols = cols + + self._constraints = {} + + def set_constraints(component, constraints): + self._constraints[component] = constraints + + def _get_geometry(self, container, component): + constraints = self._constraints[component] + if constraints: + x = constraints.x * component.props.width / self._rows + y = constraints.y * component.props.height / self._cols + width = constraints.width * component.props.width / self._rows + height = constraints.height * component.props.height / self._cols + + return [x, y, width, height] + else: + return [0, 0, 0, 0] + + def layout_canvas_group(group): + i = 0 + while i < group.get_n_children(): + item = group.get_child(i) + + [x, y, width, height] = self._get_geometry(group, item) + + item.props.x = x + item.props.y = y + item.props.width = width + item.props.height = height