[haiku-development] Re: BBox and layout

  • From: Alex Wilson <yourpalal2@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 6 May 2012 15:03:16 -0600

> Hi,
> just had these two problems with a BBox:
> 1) I added a menu field as a label for a BBox and a layout to the BBox. In
> this case in DoLayout *) the label view is removed, BView::DoLayout called
> and the label is added again. The comment says this is because the label
> should not be layouted. The problem is that AddChild triggers a relayout
> which results in an infinite loop.

Uh oh!

> My first solution is to just leave the label added to the BBox while
> calling BView::DoLayout and just move it back to the right position
> afterwards. This works fine but why BView::DoLayout layouts the label view
> at all? I mean the label is not part of any layout class so it should be
> ignored or what is the policy here?

The reason the label is laid out is because it is a child of the view, and
all children are part of the layout (or a nested layout). The removal of
the child for the layout is the way to circumvent this. The infinite loop
should be avoidable using the {Disable|Enable}LayoutInvalidation() methods.

2) When setting a layout to a BBox its a bit annoying to set the correct
> layout inset so that the content is exactly within the inner BBox frame. It
> would be nice to have some convenient function to set the inset to the
> layout. Or even better: the layout of a BBox is moved automatically into
> the inner frame so that it is not event possible to place a layout item
> outside the inner frame. What do you think?

It is annoying indeed. One solution would be to add a BLayout subclass that
does a BBox layout, including the label and a single nested item (possibly
another BLayout). Otherwise, if you wanted to keep the current system, but
let BBox manage the insets of the layout it is assigned that could be done
if SetInsets() were a part of BLayout(). Currently it's not, but it is
implemented by all layouts (assuming BCardLayout does), so it could be
alright to make it part of BLayout. If there were a layout at some point
that couldn't reasonably support insets, it would be ok if it just ignored
whatever insets the user set.


Other related posts: