enaml

Enaml Looper horizontal layout


By default the below code will lay out each GroupBox object vertically stacked (one underneath the other).

enamldef Main(Window):
    attr model

    Container:
        constraints = [ hbox(items) ]

        Container: items:
            Looper:
                iterable << model.l              # model.l = some list of atom objects
                    GroupBox:
                        title << loop_item.name                
                        CheckBox:
                            checked := loop_item.active

How can i lay them out in a looper such that they are horizontally stacked (left to right) instead?

I can't find any information on this in the enaml docs / API.


Solution

  • You can either supply your own constraints which do what you want, such as the hbox helper: https://github.com/nucleic/enaml/blob/master/examples/layout/basic/hbox.enaml#L34

    Or use one of the convenience Container subclasses, like HGroup: https://github.com/nucleic/enaml/blob/master/examples/widgets/h_group.enaml#L46 https://github.com/nucleic/enaml/blob/master/enaml/widgets/h_group.py#L17

    The Enaml examples will probably answer a lot of your entry-level questions: https://github.com/nucleic/enaml/tree/master/examples