diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-05 16:53:34 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-05 16:53:34 (GMT) |
commit | 1b0e469dbd90572d2bf6e4b928d1022a99c447c3 (patch) | |
tree | 77d7143b0b37b975290fa20a0325938dd72d8f77 /sugar/graphics | |
parent | 924fe94b1697f96acc04ccc632b164c9256e1f35 (diff) |
More work on the views layout
Diffstat (limited to 'sugar/graphics')
-rw-r--r-- | sugar/graphics/snowflakelayout.py | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/sugar/graphics/snowflakelayout.py b/sugar/graphics/snowflakelayout.py index 611ecaa..afce0c8 100644 --- a/sugar/graphics/snowflakelayout.py +++ b/sugar/graphics/snowflakelayout.py @@ -9,63 +9,53 @@ class SnowflakeLayout: def __init__(self): self._root = None - self._children = [] self._r = 0 def set_root(self, icon): self._root = icon - def add_child(self, icon): - self._children.append(icon) - self._layout() + def _layout_root(self, box): + [width, height] = self._root.get_allocation() - def remove_child(self, icon): - self._children.remove(icon) - self._layout() + x = self._cx - (width / 2) + y = self._cy - (height / 2) - def _layout_root(self): - [width, height] = self._root.get_size_request() + box.move(self._root, int(x), int(y)) - matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) - matrix.translate(self._cx - (width / 2), self._cy - (height / 2)) - self._root.set_transform(matrix) - - def _layout_child(self, child, index): + def _layout_child(self, box, child, index): r = self._r - if (len(self._children) > 10): + if (len(box.get_children()) > 10): r += SnowflakeLayout._FLAKE_DISTANCE * (index % 3) - angle = 2 * math.pi / len(self._children) * index + angle = 2 * math.pi / len(box.get_children()) * index - [width, height] = child.get_size_request() + [width, height] = child.get_allocation() x = self._cx + math.cos(angle) * r - (width / 2) y = self._cy + math.sin(angle) * r - (height / 2) - matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) - matrix.translate(x, y) - child.set_transform(matrix) + box.move(child, int(x), int(y)) - def get_size(self): + def get_size(self, box): max_child_size = 0 - for child in self._children: - [width, height] = child.get_size_request() + for child in box.get_children(): + [width, height] = child.get_allocation() max_child_size = max (max_child_size, width) max_child_size = max (max_child_size, height) return self._r * 2 + max_child_size + \ SnowflakeLayout._FLAKE_DISTANCE * 2 - def _layout(self): + def layout(self, box): self._r = SnowflakeLayout._BASE_RADIUS + \ - SnowflakeLayout._CHILDREN_FACTOR * len(self._children) + SnowflakeLayout._CHILDREN_FACTOR * len(box.get_children()) - size = self.get_size() + size = self.get_size(box) self._cx = size / 2 self._cy = size / 2 - self._layout_root() + self._layout_root(box) index = 0 - for child in self._children: - self._layout_child(child, index) + for child in box.get_children(): + self._layout_child(box, child, index) index += 1 |