[haiku-development] Re: BBox and layout

On Fri, 11 May 2012 01:14:21 +1200, Ingo Weinhold <ingo_weinhold@xxxxxx> wrote:

BLayout* layout = new BGroupLayout();
box->SetLayout(layout);
    // sets the content area offset
layout->SetInset(..);
    // overwrites the offset again

So this would goes wrong quite often because you can't expect developers
keeping the order when to call SetLayout.

It can go wrong, but particularly with the default insets I would challenge
that it happens very often. I think in most cases people wouldn't meddle
with the insets at all. It's not possible to prevent people from using the
API incorectly in either case.

However, BBox setter and getter
for a default inset are a solution but IMHO not very intuitive...

IMO they are. Using default values that can be changed by setters is a
common idiom in the interface kit/layout API (e.g. think of the default
spacing).

What I meant with not very intuitive is that you have to call BBox::SetContentAreaInset() to set the layout inset. Normally you would call BLayout::SetInset(). Furthermore, all sub-sequential calls to BLayout::SetLayout ignore the BBox inset.


Point 1. should work fine but from my own experience I would just try to
call SetLayout on the BBox to set the layout in the content area. That
would result in a messed up BBox.

Again, we cannot always prevent people from using the API incorrectly.
Particularly when they don't manage to RTFM. :-)

no one RTFM :-)


Another problem occurs if you want, for
whatever reasons, a content layout that is bigger than the content area.
You can't do that in this solution.

I guess you could set negative insets.

Yes right this child layout approach would definitely be a solution. However, SetContentLayout compared to SetLayout makes the dev to RTFM -> bad! Overwriting SetLayout and let BBox::SetLayout call _SetContentLayout would be a solution here (hacky, though and would change internal behaviour).


I don't think BView::SetInset is duplicated functionality. One can see
BView as a kind of a special "super layout" that holds only one child
layout. From this point of view it also deserves a SetInset method like a
real BLayout.

I can only repeat my reasoning: It would be rarely used functionality
(mainly for BBox, where such an API would therefore be better placed) and
you can easily achieve the same by nesting layouts. An additional layout is
cheap, so there really is nothing speaking against doing that.


Its really not a common case but it is handy for all types of container views. For example, to display a layout created by an external source with an intended inset. Sure, that can be solved by adding a container layout with a fix inset but hmmmm don't like it.... setting the inset to BView directly seems to be more straight forward.

Regards,
        Clemens

Other related posts: