Cleanup center item offset API

master
Marco Pesenti Gritti 17 years ago
parent 32fc5d3161
commit ee8712d1c4

@ -382,8 +382,7 @@ class MeshBox(hippo.CanvasBox):
self._layout_box = hippo.CanvasBox(background_color=0xe2e2e2ff)
self.append(self._layout_box, hippo.PACK_EXPAND)
center_vertical_offset = - style.GRID_CELL_SIZE
self._layout = SpreadLayout(center_vertical_offset)
self._layout = SpreadLayout()
self._layout_box.set_layout(self._layout)
for buddy_model in self._model.get_buddies():
@ -466,7 +465,8 @@ class MeshBox(hippo.CanvasBox):
def _add_alone_buddy(self, buddy_model):
icon = BuddyIcon(self._shell, buddy_model)
if buddy_model.is_owner():
self._layout.add_center(icon)
vertical_offset = - style.GRID_CELL_SIZE
self._layout.add_center(icon, vertical_offset)
else:
self._layout.add(icon)

@ -169,18 +169,16 @@ class _Grid(gobject.GObject):
class SpreadLayout(gobject.GObject, hippo.CanvasLayout):
__gtype_name__ = 'SugarSpreadLayout'
def __init__(self, center_vertical_offset=0):
def __init__(self):
gobject.GObject.__init__(self)
self._center_vertical_offset = center_vertical_offset
min_width, width = self.do_get_width_request()
min_height, height = self.do_get_height_request(width)
self._grid = _Grid(width / _CELL_SIZE, height / _CELL_SIZE)
self._grid.connect('child-changed', self._grid_child_changed_cb)
def add_center(self, child):
def add_center(self, child, vertical_offset=0):
self._box.append(child)
width, height = self._get_child_grid_size(child)
@ -191,6 +189,7 @@ class SpreadLayout(gobject.GObject, hippo.CanvasLayout):
box_child = self._box.find_box_child(child)
box_child.grid_rect = None
box_child.vertical_offset = vertical_offset
def add(self, child):
self._box.append(child)
@ -225,10 +224,11 @@ class SpreadLayout(gobject.GObject, hippo.CanvasLayout):
rect.height * _CELL_SIZE,
origin_changed)
else:
vertical_offset = child.vertical_offset
min_w, child_width = child.get_width_request()
min_h, child_height = child.get_height_request(child_width)
child_x = x + (width - child_width) / 2
child_y = y + (height - child_height + self._center_vertical_offset) / 2
child_y = y + (height - child_height + vertical_offset) / 2
child.allocate(child_x, child_y, child_width, child_height,
origin_changed)

Loading…
Cancel
Save