1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#------------------------------------------------------------------------------
# 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'
|