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

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

Am 16.08.2010, 21:40 Uhr, schrieb Stephan Assmus <superstippi@xxxxxx>:

Am 16.08.2010 00:46, schrieb Clemens:

after a long time I wrote a gui app again and I was amazed how easy it is to setup a basic view layout with the layout engine and the layout friendly 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 needed? Can we provide a default BWindow layout to omit the SetLayout call or set one in AddChild if needed? I feel the SetLayout call is not very intuitive.

At first I always found this step unintuitive as well, but once you know 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 not 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 passing the window pointer to the builder, I believe. We should advertise those forms in the examples. Of course adding a default vertical BGroupLayout to 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 in the way you described it above.


Other related posts: