Hbox Equal Widths ExampleΒΆ

hbox_equal_widths

An example of the `hbox` layout helper with auxiliary constraints.

This example is nearly identical to the `hbox.enaml` example. However,
this time we add some auxiliary constraints to make the buttons equal
widths. When resizing the window, each button is therefore guaranteed
to expand by the same amount.
$ enaml-run hbox_equal_widths
../_images/ex_hbox_equal_widths.png
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
""" An example of the `hbox` layout helper with auxiliary constraints.

This example is nearly identical to the `hbox.enaml` example. However,
this time we add some auxiliary constraints to make the buttons equal
widths. When resizing the window, each button is therefore guaranteed
to expand by the same amount.

<< autodoc-me >>
"""
from enaml.layout.api import hbox
from enaml.widgets.api import Window, Container, PushButton


enamldef Main(Window):
    Container:
        constraints = [
            hbox(pb1, pb2, pb3),
            pb1.width == pb2.width,
            pb2.width == pb3.width,
        ]
        PushButton: pb1:
            text = 'Spam'
        PushButton: pb2:
            text = 'Long Name Foo'
        PushButton: pb3:
            text = 'Bar'