On 2020-12-17 22:49, josef Reidinger wrote:
To get nice box centered at middle of screen, but content in box left aligned use HBox( HStretch, VBox( VStretch, Left(<content>), VStretch ), HStretch )
This is really just an overly complex way of writing
HVCenter( Left( content ) )
HBox( HStretch(), content, HStretch() )
is the same as
HCenter( content )
and it's the same in the other dimension, i.e. VBox( VStretch(), content, VStretch() )
I feel it's time to repeat that very basic presentation I once gave at a YaST workshop in Prague back in 2005 or 2006 (unfortunately, I don't seem to have those slides anymore).
Our layouts have become mind-bogglingly complex; layout widgets are always added, sometimes counteracting each other, sometimes just doing nothing. Often enough it's very hard to find out why it behaves like it does simply because of the sheer number of layers upon layers.
Back many years ago I had added the YDialogSpy (Ctrl-Shift-Alt-Y) mostly to visualize what level of layout elements correspond to what screen area. I found that it helps a lot to just invoke it; very often it's surprising to see how large or how small any of those layout boxes really are. Please use it!
I believe that most of the insecurity that our developers have about layouts comes from not really understanding a widget's stretchability in both dimensions and how this changes when you put it into an alignment widget (Left, Right, Top, Bottom, HCenter, VCenter, HVCenter) and how layout stretch items (HStretch, VStretch) and spacings interact with the layout algorithm.
In general, if there are several ways to achieve the same layout, use the simpler one. If a part of a layout is blown up too large, put it into a squash widget (HSquash, VSquash, HVSquash) to "let out air". If it then becomes too small, put a MinSize (or MinWidth or MinHeight) inside it. And normally it's a good idea to add a margin (MarginBox) around it if it's the outermost layout level in a dialog:
MarginBox( 3, 1, # add some border around it HVSquash( # squeeze out excess space MinSize( 42, 7, # enforce minimum size content ) ) )
That's a lot simpler and a lot less error-prone than cascading tons of extra VBox, HBox, VStretch, HStretch, VSpacing, HSpacing as we see so often in our dialogs. And the layout engine will give you much more predictable results, too.
Kind regards + Merry Christmas, everyone!