[haiku-development] Re: Haiku Layout tutorial

  • From: Stephan Assmus <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 29 Sep 2009 09:55:45 +0200

On 2009-09-29 at 00:31:32 [+0200], Ryan Leavengood <leavengood@xxxxxxxxx> 
wrote:
> On Mon, Sep 28, 2009 at 6:21 PM, Stephan Assmus <superstippi@xxxxxx> 
> wrote:
> >
> > Actually, it's not supposed to be complicated. Why do you think it is 
> > so?
> 
> Well I haven't really tried yet, so maybe it isn't so complicated to 
> create layout friendly views. When I get around to it I can let you know. 
> But I think people have definitely had some problems with the layout 
> system so I think it still has room for improvement.

Well, before you actually tried this yourself, don't make such statements, 
because I would be afraid of them sticking in peoples heads. ;-)

Making a layout-friendly view is actually very easy.

1) You use the layout-friendly BView constructor:

MyView::MyView(...)
        :
        BView("name", flags)
{ ...

This will make sure that the B_SUPPORTS_LAYOUT flag is set on the view.

2) You implement at least GetPreferredSize() or MinSize(). (Just look at 
src/kits/interface/View.cpp to see that either one would work.)

3) Optionally, you can also implement PreferredSize() and MaxSize() as well 
as the LayoutAlignment() method. Alternatively, you can 
SetExplicit[Min|Max|Preferred]Size(). Really important is only MaxSize(), 
in case you want to restrict your view from becomming too big.

Especially since 3) is optional, this is really not any more complicated 
than implementing GetPreferredSize() as in the old days.

Best regards,
-Stephan

Other related posts: