Each window can have a layout manager. Even a Label can have one, probably
needs one, when a pictogram is shown next to the text.
A layout manager is assigned to a window when constructed:
where Layout is a module that implements at least the methods
add_child(), user_width(), user_height() and pack().
Predefined X, Y, Width, Height
Each layout manager has its own ways of dealing with those values. Some may
ignore it, others may use it. For example, VLayout and HLayout ignore three out
of four of these values.
My Widget is too big/small!
Layout managers have the freedom to set the place and size of the
children. Actually, that is their task! Your widgets should be able to cope
with that. Layout managers may implement hints like :expand=>true,
:weight=>2.4, :align=>"left" to adjust size and placement, but need not.
In particular, the Window Manager in an X environment has the absolute,
given right to place and dimension a toplevel window to its liking. For
instance, on PDA's, some Window Managers give applications invariably (almost)
the full screen, without taking any request from the application itself into
Ignoring the Window Manager
and you can do the rest yourself. Use with care. Use seldomly.
Building your Own Widget
A widget has the user-space, for which it specifies the width and height with
user_width() and user_height(). Added to that for the total dimensions are
space and border. The border can look just like space when no relief is
The Window widget will pass the total width and height to the parent window,
your widget does not have to provide for this.
Some lower graphics engines can not deal with windows of size zero, so your
user_width() and user_height() should not return zero (but it is caught by the
default total_width() and total_height()).
Building your Own Layout Manager
The layout manager should place and resize all children from a window when its
pack() method is called. It may choose not to map some children, in which case
they need not be resized or placed, either.
Before packing, the layout manager will be asked the user_width() and
user_height() it would like to use. As such, the layout manager can use these
functions to precompute values, precisely once (not when pack() is called a
An empty window with a defined layout manager, but no children has a default
width/height (specifically, on creation). That sucks, since those dimensions
are used on popup.