Cleanup center item offset API

This commit is contained in:
Marco Pesenti Gritti 2007-11-05 12:04:15 +01:00
parent 32fc5d3161
commit ee8712d1c4
2 changed files with 8 additions and 8 deletions

View File

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

View File

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