Simple grid layout

This commit is contained in:
Marco Pesenti Gritti 2006-09-07 11:36:04 +02:00
parent f40485aad4
commit 6aadff4e87

View File

@ -0,0 +1,40 @@
class GridConstraints:
def __init__(x, y, width, height):
self.x = x
self.y = y
self.width = width
self.height = height
class GridLayout:
def __init__(self, rows, cols):
self._rows = rows
self._cols = cols
self._constraints = {}
def set_constraints(component, constraints):
self._constraints[component] = constraints
def _get_geometry(self, container, component):
constraints = self._constraints[component]
if constraints:
x = constraints.x * component.props.width / self._rows
y = constraints.y * component.props.height / self._cols
width = constraints.width * component.props.width / self._rows
height = constraints.height * component.props.height / self._cols
return [x, y, width, height]
else:
return [0, 0, 0, 0]
def layout_canvas_group(group):
i = 0
while i < group.get_n_children():
item = group.get_child(i)
[x, y, width, height] = self._get_geometry(group, item)
item.props.x = x
item.props.y = y
item.props.width = width
item.props.height = height