[haiku-development] Re: Automatically set window / view Layout

  • From: "Clemens Zeidler" <clemens.zeidler@xxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 17 Aug 2010 11:47:44 +1200

Am 17.08.2010, 11:24 Uhr, schrieb Alex Wilson <yourpalal2@xxxxxxxxx>:

after a long time I wrote a gui app again and I was amazed how easy it
to setup a basic view layout with the layout engine and the layout
constructors :-).

But when I run my program nothing showed up! The problem was that I
haven't call the SetLayout method. I remember I did this mistake
earlier so
maybe also other people will run into it. Why I have to set the layout
manually? Because the window does not know which kind of BLayout is
Can we provide a default BWindow layout to omit the SetLayout call or
one in AddChild if needed? I feel the SetLayout call is not very

 At first I always found this step unintuitive as well, but once you

the system better, it becomes clear why it's needed/useful: You can for example directly attach children to the otherwise inaccessible top-level BView. A regular layout with a BMenuBar and another view below it does
require another view above, but only a vertical BGroupLayout attached
"directly" to the window. In any case, there are forms of using the
BLayoutBuilder that does not require adding an extra layout, like
the window pointer to the builder, I believe. We should advertise those forms in the examples. Of course adding a default vertical BGroupLayout
the window, if there is none otherwise, would remove this pitfall.

Maybe ask in AddChild if the new view has a Layout and in this case add a default BGroupLayout to the (layout less) window? So you can still use it
the way you described it above.

One of the main problems with this is compatibility, for example, if
non-layouted window had a view added that was from an external source (eg.
translator's config view) that had a layout, the window would then have a
layout set and all the views would be re-added to the layout, so they
all end up in a vertical arrangement. This could cause some very confusing
bugs. After R1, it would probably be good to have a default layout, but
until then, I don't think it is feasible.

Plus, the layout builders Stippi mentioned are really handy!


Ok understand, and if we only add a layout if there are no other layout
less views attached to a window? (just guessing)

Closer, but no good, BButtons, for example don't have layouts, so in that
case it would not have a layout, even if you perhaps wanted one, so the
behaviour would become somewhat unpredictable. Also, this still doesn't
alleviate the problem that theoretically, one might have a
non-layout-supporting window that ends up with a layout.


Ah ok, then its really a > R1 thing. I think after R1 a default layout would be the case a normal user would expected and if you want to mess around without a layout you can call SetLayout(NULL)...


Other related posts: