Improved layout strategy

This commit is contained in:
Marco Pesenti Gritti 2006-09-09 12:23:01 +02:00
parent 678cab55f9
commit 2b1a11fb66
2 changed files with 54 additions and 19 deletions

33
sugar/canvas/GridBox.py Normal file
View File

@ -0,0 +1,33 @@
import goocanvas
from sugar.canvas.GridLayout import GridGroup
from sugar.canvas.GridLayout import GridConstraints
class GridBox(GridGroup, goocanvas.Item):
VERTICAL = 0
HORIZONTAL = 1
def __init__(self, direction, size, padding):
if direction == GridBox.VERTICAL:
GridGroup.__init__(self, 1, size)
else:
GridGroup.__init__(self, size, 1)
self._direction = direction
self._padding = padding
def add_child(self, item, position=-1):
if position == -1:
position = self.get_n_children()
if self._direction == GridBox.HORIZONTAL:
col = position
row = 0
else:
col = 0
row = position
constraints = GridConstraints(col, row, 1, 1, self._padding)
self._layout.set_constraints(item, constraints)
GridGroup.add_child(self, item, position)

View File

@ -43,23 +43,18 @@ class GridLayout:
return [x, y, width, height]
def layout_canvas_group(self, group):
i = 0
while i < group.get_n_children():
item = group.get_child(i)
def layout_canvas_item(self, item):
group = item.get_parent()
[x, y, width, height] = self._get_geometry(group, item)
[x, y, width, height] = self._get_geometry(group, item)
item.props.x = x
item.props.y = y
item.props.x = x
item.props.y = y
try:
item.props.width = width
item.props.height = height
except:
item.props.size = width
i += 1
try:
item.props.width = width
item.props.height = height
except:
item.props.size = width
def layout_screen(self, screen):
for window in screen.get_windows():
@ -85,13 +80,19 @@ class GridGroup(goocanvas.Group):
matrix.translate(self._x, self._y)
self.set_transform(matrix)
def _update_layout(self):
i = 0
while i < self.get_n_children():
self._layout.layout_canvas_item(self.get_child(i))
i += 1
def do_set_property(self, pspec, value):
if pspec.name == 'width':
self._width = value
self._layout.layout_canvas_group(self)
self._update_layout()
elif pspec.name == 'height':
self._height = value
self._layout.layout_canvas_group(self)
self._update_layout()
elif pspec.name == 'x':
self._x = value
self._update_position()
@ -127,5 +128,6 @@ class GridGroup(goocanvas.Group):
def get_layout(self):
return self._layout
def __child_added_cb(self, child, position):
self._layout.layout_canvas_group(self)
def __child_added_cb(self, group, position):
item = group.get_child(position)
self._layout.layout_canvas_item(item)