Layout basics
Factor handbook > UI framework > Building user interfaces > Gadget hierarchy and layouts

Next:Pack layouts


Gadgets are arranged in a hierarchy, and all visible gadgets except for instances of world are contained in a parent gadget.

Managing the gadget hierarchy:
add-gadget ( parent child -- parent )

unparent ( gadget -- )

add-gadgets ( parent children -- parent )

clear-gadget ( gadget -- )


The children of a gadget are available via the children slot.

Working with gadget children:
gadget-child ( gadget -- child )

nth-gadget ( n gadget -- child )

each-child ( gadget quot -- )

child? ( parent child -- ? )


Working with gadget parents:
parents ( gadget -- seq )

each-parent ( gadget quot -- ? )

find-parent ( gadget quot -- parent )


Adding children, removing children and performing certain other operations initiates relayout requests automatically. In other cases, relayout may have to be triggered explicitly. There is no harm from doing this several times in a row as consecutive relayout requests are coalesced.
relayout ( gadget -- )

relayout-1 ( gadget -- )


Gadgets implement a generic word to inform their parents of their preferred size:
pref-dim* ( gadget -- dim )


To get a gadget's preferred size, do not call the above word, instead use pref-dim, which caches the result.