Rewrite canvas box layout

This commit is contained in:
Marco Pesenti Gritti 2006-09-17 03:35:14 +02:00
parent 27b2e0080b
commit e48c135ae9
2 changed files with 18 additions and 10 deletions

View File

@ -18,26 +18,34 @@ class CanvasBox(goocanvas.Group):
def set_constraints(self, item, width, height): def set_constraints(self, item, width, height):
self._constraints[item] = [width, height] self._constraints[item] = [width, height]
def _layout(self): def _layout(self, start_item):
x = self._padding if start_item == -1:
y = self._padding start_item = self.get_n_children() - 1
pos = 0
i = 0 i = 0
while i < self.get_n_children(): while i < self.get_n_children():
item = self.get_child(i) item = self.get_child(i)
[width, height] = self._constraints[item] [width, height] = self._constraints[item]
self._grid.set_constraints(item, x, y, width, height) pos += self._padding
if self._orientation == CanvasBox.VERTICAL: if self._orientation == CanvasBox.VERTICAL:
y += height + self._padding x = self._padding
y = pos
pos += height + self._padding
else: else:
x += width + self._padding x = pos
y = self._padding
pos += width + self._padding
if i >= start_item:
self._grid.set_constraints(item, x, y, width, height)
i += 1 i += 1
def _child_added_cb(self, item, position): def _child_added_cb(self, item, position):
self._layout() self._layout(position)
def _child_removed_cb(self, item, position): def _child_removed_cb(self, item, position):
self._layout() self._layout(position)

View File

@ -22,7 +22,7 @@ class Menu(gtk.Window):
def __init__(self, grid, title, color_scheme=MenuColorScheme()): def __init__(self, grid, title, color_scheme=MenuColorScheme()):
gtk.Window.__init__(self, gtk.WINDOW_POPUP) gtk.Window.__init__(self, gtk.WINDOW_POPUP)
self._width = 13 self._width = 15
self._grid = grid self._grid = grid
self._action_box = None self._action_box = None
self._color_scheme = color_scheme self._color_scheme = color_scheme
@ -51,7 +51,7 @@ class Menu(gtk.Window):
self._canvas.set_model(model) self._canvas.set_model(model)
def _create_action_box(self): def _create_action_box(self):
separator = goocanvas.Path(data='M 15 0 L 185 0', line_width=3, separator = goocanvas.Path(data='M 15 0 L 215 0', line_width=3,
stroke_color=self._color_scheme.separator) stroke_color=self._color_scheme.separator)
self._grid.set_constraints(separator, 0, 4) self._grid.set_constraints(separator, 0, 4)
self._root.add_child(separator) self._root.add_child(separator)