Improved layout strategy
This commit is contained in:
parent
678cab55f9
commit
2b1a11fb66
33
sugar/canvas/GridBox.py
Normal file
33
sugar/canvas/GridBox.py
Normal 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)
|
@ -43,23 +43,18 @@ class GridLayout:
|
|||||||
|
|
||||||
return [x, y, width, height]
|
return [x, y, width, height]
|
||||||
|
|
||||||
def layout_canvas_group(self, group):
|
def layout_canvas_item(self, item):
|
||||||
i = 0
|
group = item.get_parent()
|
||||||
while i < group.get_n_children():
|
[x, y, width, height] = self._get_geometry(group, item)
|
||||||
item = group.get_child(i)
|
|
||||||
|
|
||||||
[x, y, width, height] = self._get_geometry(group, item)
|
item.props.x = x
|
||||||
|
item.props.y = y
|
||||||
|
|
||||||
item.props.x = x
|
try:
|
||||||
item.props.y = y
|
item.props.width = width
|
||||||
|
item.props.height = height
|
||||||
try:
|
except:
|
||||||
item.props.width = width
|
item.props.size = width
|
||||||
item.props.height = height
|
|
||||||
except:
|
|
||||||
item.props.size = width
|
|
||||||
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
def layout_screen(self, screen):
|
def layout_screen(self, screen):
|
||||||
for window in screen.get_windows():
|
for window in screen.get_windows():
|
||||||
@ -85,13 +80,19 @@ class GridGroup(goocanvas.Group):
|
|||||||
matrix.translate(self._x, self._y)
|
matrix.translate(self._x, self._y)
|
||||||
self.set_transform(matrix)
|
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):
|
def do_set_property(self, pspec, value):
|
||||||
if pspec.name == 'width':
|
if pspec.name == 'width':
|
||||||
self._width = value
|
self._width = value
|
||||||
self._layout.layout_canvas_group(self)
|
self._update_layout()
|
||||||
elif pspec.name == 'height':
|
elif pspec.name == 'height':
|
||||||
self._height = value
|
self._height = value
|
||||||
self._layout.layout_canvas_group(self)
|
self._update_layout()
|
||||||
elif pspec.name == 'x':
|
elif pspec.name == 'x':
|
||||||
self._x = value
|
self._x = value
|
||||||
self._update_position()
|
self._update_position()
|
||||||
@ -127,5 +128,6 @@ class GridGroup(goocanvas.Group):
|
|||||||
def get_layout(self):
|
def get_layout(self):
|
||||||
return self._layout
|
return self._layout
|
||||||
|
|
||||||
def __child_added_cb(self, child, position):
|
def __child_added_cb(self, group, position):
|
||||||
self._layout.layout_canvas_group(self)
|
item = group.get_child(position)
|
||||||
|
self._layout.layout_canvas_item(item)
|
||||||
|
Loading…
Reference in New Issue
Block a user