[haiku-development] Re: BBox and layout

On Wed, 16 May 2012 01:21:58 +1200, Ingo Weinhold <ingo_weinhold@xxxxxx> wrote:

After giving it a another thought I still think SetInset should be in
BView for consistency reasons. As said before BView is a special
layout/layout item. It's somehow an artificial BLayoutItem or BLayout. It can be added into a layout and handled like a normal BLayoutItem. For this reason when adding a SetInset to BLayout it should also be added to BView
(similar to the layout related size getter and setter in BView).

I can't quite follow this train of thought. BView is essentially a
BLayoutItem (and it really would be, had that been possible to implement in a binary compatible way). I don't see how that implies that because BLayout
has insets BView should have insets, too.

yes BView is a hybrid of an BLayoutItem and a BLayout, BView would not only be a BLayoutItem, it would be a BLayout. For all important BLayout methods there are already equivalent methods in BView.

The BView, as a BLayout, has no "Add*" layout method but just one SetLayout method because it can exactly hold one layout.


There is a clear separation of concerns: A layout gets a rectangular area
and arranges layout items in it. One layout property are the insets for the
original area. BView has two roles: As a simple layout item with size and
alignment constraints and as an entity that drives the layout process.
Neither role requires or even benefits from insets.

As said above the second role is the role of a layout. In this role a SetInset would remove the need to add another layout just for the sake of adding a container inset.

Since border style and label of the BBox can also be set any time after
construction, insets would have to be updated then as well. Furthermore the
size constraints of the label view can change, which would also have that
implication. That is in practice you can't easily override the insets for a
BBox.

bummer, yes SetInset cannot provide a clean solution in a label resize event. However, I would still hide the BBoxLayout complexity and make it working by overwriting BBox::SetLayout and BBox::SetInset.

A BBoxLayout::AddItem call to set a single layout is confusing for the
user, i.e. does it means that multiple layouts can be assigned to a BBox?

As written above, I'd add BBox::SetContent() methods (and a BLayoutItem*
constructor version -- there already is one for a BView* child) to simplify
and clarify the API.

But there is still the problem that the user could try to use SetLayout to set the content layout. (that would happened for user like me :) ) This confusion can be avoided by using the more general BView api.

Such a BBox API also doesn't require any knowledge of "layout internals". I think it's at least as easy to grasp that a BBox is a frame with a content item that one can set as how certain insets would add up and that the label
view isn't managed by the layout.


The more basic and simpler view on a BBox is that it's just a simple BView that does some drawing and sets a default inset for the layout.

Regards,
        Clemens

Other related posts: