Skip to content

Commit

Permalink
Fix the grid layout helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins authored and brett-patterson committed Jun 25, 2014
1 parent 520167e commit 31fe591
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
10 changes: 5 additions & 5 deletions enable/constraints_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,16 @@ def _content_box_constraints(self):
contents_top = cns.contents_top
contents_bottom = cns.contents_bottom

# Add these to the namespace, but don't use them
# Add these to the namespace, but don't use them here
cns.contents_width = contents_right - contents_left
cns.contents_height = contents_top - contents_bottom
cns.contents_v_center = contents_bottom + cns.contents_height / 2.0
cns.contents_h_center = contents_left + cns.contents_width / 2.0

return [contents_left == cns.left + self.padding_left,
contents_bottom == cns.bottom + self.padding_bottom,
contents_right == cns.right - self.padding_right,
contents_top == cns.top - self.padding_top,
return [contents_left == cns.left,
contents_bottom == cns.bottom,
contents_right == cns.left + cns.width,
contents_top == cns.bottom + cns.height,
]

def _update_fixed_constraints(self):
Expand Down
2 changes: 1 addition & 1 deletion enable/layout/debug_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update_from_constraints(self, layout_mgr):
"""
self.boxes = defaultdict(Coords)
if layout_mgr is not None:
if layout_mgr is not None and layout_mgr._constraints:
for constraint in layout_mgr._constraints:
for expr in (constraint.lhs, constraint.rhs):
for term in expr.terms:
Expand Down
12 changes: 7 additions & 5 deletions enable/layout/layout_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,19 +670,19 @@ def _get_constraints(self, component):

# Add some neighbor relations to the row and column vars.
for r1, r2 in zip(row_vars[:-1], row_vars[1:]):
constraints.append(r1 <= r2)
constraints.append(r1 >= r2)
for c1, c2 in zip(col_vars[:-1], col_vars[1:]):
constraints.append(c1 <= c2)

# Setup the initial interior bounding box for the grid.
margins = self.margins
top_items = (self.top, EqSpacer(margins.top), row_vars[0])
bottom_items = (row_vars[-1], EqSpacer(margins.bottom), self.bottom)
bottom_items = (self.bottom, EqSpacer(margins.bottom), row_vars[-1])
top_items = (row_vars[0], EqSpacer(margins.top), self.top)
left_items = (self.left, EqSpacer(margins.left), col_vars[0])
right_items = (col_vars[-1], EqSpacer(margins.right), self.right)
helpers = [
AbutmentHelper('vertical', *top_items),
AbutmentHelper('vertical', *bottom_items),
AbutmentHelper('vertical', *top_items),
AbutmentHelper('horizontal', *left_items),
AbutmentHelper('horizontal', *right_items),
]
Expand Down Expand Up @@ -976,7 +976,7 @@ class AbutmentConstraintFactory(SequenceConstraintFactory):
#: lookup for a pair of items in order to make the constraint.
orientation_map = {
'horizontal': ('right', 'left'),
'vertical': ('bottom', 'top'),
'vertical': ('top', 'bottom'),
}

@classmethod
Expand Down Expand Up @@ -1018,6 +1018,8 @@ def from_items(cls, items, orientation, spacing):
"'horizontal'. Got %r instead.")
raise ValueError(msg % orientation)
first_name, second_name = orient
if orientation == 'vertical':
items.reverse()
return cls._make_cns(items, first_name, second_name, spacing)


Expand Down
13 changes: 8 additions & 5 deletions examples/enable/constraints_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from enable.api import Component, ComponentEditor, ConstraintsContainer
from enable.layout.layout_helpers import hbox, align, grid
from enable.layout.layout_helpers import hbox, vbox, align, grid, horizontal
from traits.api import HasTraits, Any, Instance, List, Property
from traitsui.api import Item, View, HGroup, TabularEditor
from traitsui.tabular_adapter import TabularAdapter
Expand Down Expand Up @@ -55,17 +55,20 @@ def _canvas_default(self):

parent.add(one, two, three, four)
parent.layout_constraints = [
hbox(one.constraints, two.constraints,
three.constraints, four.constraints),
grid([one.constraints, two.constraints],
[three.constraints, four.constraints]),
align('height', one.constraints, two.constraints,
three.constraints, four.constraints),
align('width', one.constraints, two.constraints,
three.constraints, four.constraints),

]

return parent

def _get_constraints(self):
return list(self.canvas._layout_manager._constraints)
if self.canvas._layout_manager._constraints:
return list(self.canvas._layout_manager._constraints)
return []

def _selected_constraints_changed(self, new):
if new is None or new == []:
Expand Down

0 comments on commit 31fe591

Please sign in to comment.