# Override Layout Constraints Example

An example which demonstrates overriding `layout_constraints`.

This example shows how one can override `layout_constraints` method from enaml syntax to generate custom constraints using procedural code. This can be useful for complex layout scenarios where generating constraints from a single expression would be difficult or impossible.

Tip

To see this example in action, download it from `override_layout_constraints` and run:

    $ enaml-run override_layout_constraints.enaml

## Screenshot

## Example Enaml Code

    #------------------------------------------------------------------------------
    # Copyright (c) 2015-2024, Nucleic Development Team.
    #
    # Distributed under the terms of the Modified BSD License.
    #
    # The full license is in the file LICENSE, distributed with this software.
    #------------------------------------------------------------------------------
    """ An example which demonstrates overriding `layout_constraints`.

    This example shows how one can override `layout_constraints` method from
    enaml syntax to generate custom constraints using procedural code. This
    can be useful for complex layout scenarios where generating constraints
    from a single expression would be difficult or impossible.

    << autodoc-me >>
    """
    from itertools import zip_longest

    from enaml.layout.api import align, grid
    from enaml.widgets.api import Window, Container, Field, Label, PushButton

    enamldef Main(Window):
        title = 'Custom Constraints'
        Container:
            layout_constraints => ():
                rows = []
                widgets = self.visible_widgets()
                row_iters = (iter(widgets),) * 2
                rows = list(zip_longest(*row_iters))
                return [grid(*rows)] + [align('v_center', *row) for row in rows]
            Label:
                text = 'Name'
            Field:
                pass
            Label:
                text = 'Surname'
            Field:
                pass
            PushButton:
                text = 'Click me'