All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Public Member Functions | List of all members
BLayoutBuilder::Base< ParentBuilder > Class Template Reference

Base for all other layout builders in the BLayoutBuilder namespace. More...

Inherited by BLayoutBuilder::Cards< ParentBuilder >, BLayoutBuilder::Grid< ParentBuilder >, BLayoutBuilder::Group< ParentBuilder >, BLayoutBuilder::Menu< ParentBuilder >, and BLayoutBuilder::Split< ParentBuilder >.

Public Member Functions

ParentBuilder & End ()
 Returns this builder's parent.
 
void SetParent (ParentBuilder *parent)
 Internal method for use by BLayoutBuilder::Base subclasses, this is essential to the builder stack semantics.
 

Detailed Description

template<typename ParentBuilder>
class BLayoutBuilder::Base< ParentBuilder >

Base for all other layout builders in the BLayoutBuilder namespace.

This class provides the stack-like semantics for its subclasses. The BLayoutBuilder::Group, BLayoutBuilder::Grid and BLayoutBuilder::Split all provide methods such as AddGrid() AddGroup() and AddSplit(), which make a new builder, place it on top of your builder stack and return it. Now you are operating on the new builder. When you call the End() method on the new builder, you are returned the one you had previously been using. At any point, you are calling methods on whatever builder currently resides on the top of the stack. Here's an example of how these classes work.

@ B_HORIZONTAL
Definition: InterfaceDefs.h:194
BLayoutBuilder::Base subclass for building BGroupLayouts.
Definition: LayoutBuilder.h:53

At this point our stack just contains a single builder, it looks like this:

.AddGrid()

Now there is a Grid builder on top of the stack, so it looks like this

Notice that the Grid on top of the stack is not a plain Grid<>, but a nested type from the Group<> class. This is an essential part of the builder classes, as this is what allows you to pop builders off the stack and get the correct type in return.

.AddSplit()

Now our stack looks like this:

This could continue ad. nauseam, but at some point, you may finish with a builder, and you might want to continue manipulating the builder below it on the stack. To do this, you simply call the End() method like so:

.End()

And now the stack is back to this:

So you are again working with the grid builder. You can add more BLayoutItems or BViews, or even more builders. Here's how it will all look together.

// working with the Group builder
// working with the Group<>::GridBuilder
// working with the Group<>::GridBuilder::SplitBuilder
.End()
// back to the Group<>::GridBuilder
ParentBuilder & End()
Returns this builder's parent.
Definition: LayoutBuilder.h:436
SplitBuilder AddSplit(orientation orientation, float spacing, int32 column, int32 row, int32 columnCount=1, int32 rowCount=1)
Definition: LayoutBuilder.h:980
GridBuilder AddGrid(float horizontal=B_USE_DEFAULT_SPACING, float vertical=B_USE_DEFAULT_SPACING, float weight=1.0f)
Add a new viewless BGridLayout as a child to the layout that this builder represents and return a Gri...
Definition: LayoutBuilder.h:600

Note that the C++ language does not impose any sequence points in such method chains. This means the arguments to all calls may be evaluated in an unexpected order. For exemple, the following code may not result in adding the 3 views in rows 0, 1 and 2 in the target grid:

// Don't do this!
int row = 0;
.Add(viewA, row++)
.Add(viewB, row++)
.Add(viewC, row++);
BLayoutBuilder::Base subclass for building BGridLayouts.
Definition: LayoutBuilder.h:133
ThisBuilder & Add(BView *view, int32 column, int32 row, int32 columnCount=1, int32 rowCount=1)
Add a BView to the BGridLayout this builder represents.
Definition: LayoutBuilder.h:868
Since
Haiku R1

Member Function Documentation

◆ End()

template<typename ParentBuilder >
ParentBuilder & BLayoutBuilder::Base< ParentBuilder >::End
inline

Returns this builder's parent.

Since
Haiku R1

◆ SetParent()

template<typename ParentBuilder >
void BLayoutBuilder::Base< ParentBuilder >::SetParent ( ParentBuilder *  parent)
inline