Public Member Functions | Static Public Member Functions | List of all members
StackLayout Class Reference

The StackLayout class lines up child controls horizontally or vertically. More...

#include <StackLayout.h>

Inheritance diagram for StackLayout:
LayoutManager LayoutItem RefCounted< IRefCounted > IRefCounted HStackLayout VStackLayout

Public Member Functions

LayoutDirection GetDirection () const
 Gets the layout direction. More...
 
void SetDirection (LayoutDirection direction)
 Sets the layout direction. More...
 
void AddSpacing (int size)
 Adds a Spacing item to the stack. More...
 
void AddStretch (int stretch=0)
 Adds a blank item with a given Stretch Factor to the stack. More...
 
void AddControl (LayoutControl *ctl, int stretch=0, LayoutAlignment alignment=Align_None)
 Adds a control to the stack. More...
 
void AddLayout (LayoutManager *layout, int stretch=0)
 Adds a child LayoutManager to the stack. More...
 
void SetSpacing (int spacing)
 Sets the horizontal and vertical spacing between items in the layout. More...
 
int GetSpacing () const
 Gets the spacing between items in the layout. More...
 
bool SetStretchFactor (LayoutControl *ctl, int stretch)
 Sets the stretch factor for a given control. More...
 
bool SetStretchFactor (LayoutManager *layout, int stretch)
 Sets the stretch factor for a given layout. More...
 
void SetStretchFactor (int index, int stretch)
 Sets the stretch factor for the item at a given index. More...
 
int GetStretchFactor (int index) const
 Retrieves the stretch factor for the item at a given index. More...
 
virtual BSize GetDesiredSize () const override
 Returns the desired size for this layout item. More...
 
virtual BSize GetMinimumSize () const override
 Returns the minimum size for this layout item. More...
 
virtual BSize GetMaximumSize () const override
 Returns the maximum size for this layout item. More...
 
virtual bool HasHeightForWidth () const override
 Returns whether this layout's preferred height depends on its width. More...
 
virtual int GetHeightForWidth (int width) const override
 Returns the preferred height for this layout item, given the width. More...
 
virtual int GetMinimumHeightForWidth (int width) const override
 Returns the minimum height for this layout item, given the width. More...
 
virtual LayoutOrientations GetExpandingOrientations () const override
 Returns whether this layout item can make use of more space than GetDesiredSize(). More...
 
virtual void Invalidate () override
 Resets the layout's rectangle then calls Update() More...
 
virtual void SetDirty () override
 Resets the layout's rectangle then calls Update() More...
 
virtual LayoutItemItemAt (int index) const override
 Retrieves the item at index in the layout and returns the item. More...
 
virtual LayoutItemTakeAt (int index) override
 Removes the item at index from the layout, and returns the item. More...
 
virtual size_t Count () const override
 Returns the number of items in this layout. More...
 
virtual void SetGeometry (const BRect &rect) override
 Sets the geometry for this layout item to the given rectangle. More...
 
- Public Member Functions inherited from LayoutManager
virtual void AddItem (LayoutItem *item)=0
 Adds a LayoutItem to this Layout Manager. More...
 
virtual int IndexOf (LayoutControl *ctl) const
 Searches for the control in this layout (not including child layouts). More...
 
virtual int IndexOf (LayoutItem *item) const
 Searches for the LayoutItem in this layout (not including child layouts). More...
 
void WindowSizeDoLayout (const BSize &size)
 Notifies this LayoutManager that the Window size has changed and all child items should be laid out accordingly. More...
 
void VisibleDoLayout ()
 Notifies this LayoutManager that the layout has changed visibility and all child items should be laid out accordingly. More...
 
void ItemSizeDoLayout ()
 Notifies this LayoutManager that a child has changed size and all child items should be laid out accordingly. More...
 
LayoutManagerGetMainLayout ()
 Retrieves the main LayoutManager associated with this Layout Manager. More...
 
LayoutManagerGetSharedSizeGroupBoundary ()
 Retrieves the next Shared Size Group Boundary associated with this Layout Manager. More...
 
LayoutManagerGetParentLayout () const
 Retrieves the parent LayoutManager associated with this Layout Manager. More...
 
void SetParentLayout (LayoutManager *)
 Sets the parent LayoutManager for this Layout Manager. More...
 
LayoutControlGetParentControl () const
 Retrieves the parent LayoutControl associated with this Layout Manager. More...
 
void SetParentControl (LayoutControl *)
 Sets the parent LayoutControl for this Layout Manager. More...
 
int GetMargin () const
 Retrieves the margin for the LayoutManager, but only if all 4 margins are the same. Otherwise, -1 is returned. More...
 
void SetMargin (int margin)
 Sets the 4 margins for the LayoutManager to the same value. More...
 
void SetLayoutMargins (int left, int top, int right, int bottom)
 Sets the 4 margins for the LayoutManager. More...
 
void SetLayoutMargins (const Margins &margins)
 Sets the margins for the LayoutManager. More...
 
void GetLayoutMargins (int *left, int *top, int *right, int *bottom) const
 Gets the 4 margins for the LayoutManager. More...
 
Margins GetLayoutMargins () const
 Gets the 4 margins for the LayoutManager. More...
 
BRect GetContentsRect () const
 Gets the bounding rectangle for the contents in the LayoutManager. More...
 
bool SetAlignment (LayoutControl *ctl, LayoutAlignment alignment)
 Sets the alignment for a child control. More...
 
bool SetAlignment (LayoutManager *layout, LayoutAlignment alignment)
 Sets the alignment for a child layout. More...
 
bool Activate ()
 Invalidates the layout item then updates it. More...
 
void Update ()
 Invalidates the layout item without updating it. More...
 
void RemoveControl (LayoutControl *ctl)
 Removes a child control. More...
 
void RemoveItem (LayoutItem *item)
 Removes a child item. More...
 
int GetTotalHeightForWidth (int width) const
 Retrieves the required height for a given width. More...
 
BSize GetTotalMinimumSize () const
 Retrieves the total minimum size for the layout. More...
 
BSize GetTotalMaximumSize () const
 Retrieves the total maximum size for the layout. More...
 
BSize GetTotalDesiredSize () const
 Retrieves the total desired size for the layout. More...
 
void SetEnabled (bool)
 Sets whether the layout is enabled. More...
 
bool IsEnabled () const
 Determines whether the layout is enabled. More...
 
void SetTopLevel (bool)
 Sets whether the layout is top-level. More...
 
bool IsTopLevel () const
 Determines whether the layout is top-level. More...
 
void SetSharedSizeGroupBoundary (bool)
 Sets whether the layout is a Shared Group Boundary. More...
 
bool IsSharedSizeGroupBoundary () const
 Determines whether the layout is a Shared Group Boundary. More...
 
virtual bool IsEmpty () const override
 Returns whether the layout item is empty. More...
 
virtual bool IsVisible () const override
 Returns whether the layout item is visible. More...
 
virtual BRect GetGeometry () const override
 Retrieves the geometry for this layout item. More...
 
virtual LayoutManagerGetLayout () override
 If the concrete item is a LayoutManager, it can be retrieved using GetLayout(). More...
 
- Public Member Functions inherited from LayoutItem
virtual BSize GetSize () const
 Returns the geometry's size for this layout item. More...
 
virtual LayoutControlGetControl ()
 If the concrete item is a LayoutControl, it can be retrieved using GetControl(). More...
 
LayoutAlignment GetAlignment () const
 Returns the alignment within the layout for this layout item. More...
 
void SetAlignment (LayoutAlignment alignment)
 Sets the alignment within the layout for this layout item. More...
 
- Public Member Functions inherited from RefCounted< IRefCounted >
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 
UInt32 AddRef () const
 
UInt32 Release () const
 
 RefCounted ()
 
 RefCounted (RefCounted const &rhs)
 
RefCountedoperator= (RefCounted const &rhs)
 
UInt32 GetRefCount () const
 

Static Public Member Functions

static StackLayoutCreate (LayoutDirection direction=LD_TopToBottom, LayoutControl *parent=0)
 Creates a StackLayout Layout Manager. More...
 

Additional Inherited Members

- Protected Member Functions inherited from RefCounted< IRefCounted >
virtual ~RefCounted ()
 
- Protected Member Functions inherited from IRefCounted
virtual ~IRefCounted ()
 
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 

Detailed Description

The StackLayout class lines up child controls horizontally or vertically.

StackLayout takes the space it gets from its parent layout or from the parent control, divides it up into a row of boxes, and makes each managed control fill one box.

If the StackLayout's orientation is Horizontal the boxes are placed in a row, with suitable sizes. Each control (or other box) will get at least its minimum size and at most its maximum size. Any excess space is shared according to the stretch factors.

If the StackLayout's orientation is Vertical, the boxes are placed in a column, again with suitable sizes.

The easiest way to create a StackLayout is to use one of the convenience classes, e.g. HStackLayout (for Horizontal boxes) or VStackLayout (for Vertical boxes). You can also use the StackLayout constructor directly, specifying its direction as LeftToRight, RightToLeft, TopToBottom, or BottomToTop.

If the StackLayout is not the top-level layout (i.e. it is not managing all of the control's area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout->AddLayout(). Once you have done this, you can add boxes to the StackLayout using one of four functions:

AddControl() to add a control to the StackLayout and set the control's stretch factor. (The stretch factor is along the row of boxes.)

AddSpacing() to create an empty box; this is one of the functions you use to create nice and spacious dialogs. See below for ways to set margins.

AddStretch() to create an empty, stretchable box.

AddLayout() to add a box containing another LayoutManager to the row and set that layout's stretch factor.

Use InsertControl(), InsertSpacing(), InsertStretch() or InsertLayout() to insert a box at a specified position in the layout.

StackLayout also includes two margin widths:

SetLayoutMargins() sets the width of the outer border on each side of the control. This is the width of the reserved space along each of the StackLayout's four sides.

SetSpacing() sets the width between neighboring boxes. (You can use AddSpacing() to get more space at a particular spot.)

The margin default is 0. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.

To remove a control from a layout, call RemoveControl(). Calling LayoutControl::Hide() on a control also effectively removes the control from the layout until LayoutControl::Show() is called.

You will almost always want to use VStackLayout and HStackLayout rather than StackLayout because of their convenient Create methods.

Member Function Documentation

void AddControl ( LayoutControl ctl,
int  stretch = 0,
LayoutAlignment  alignment = Align_None 
)

Adds a control to the stack.

Parameters
[in]ctlthe LayoutControl being added
[in]stretchthe Stretch Factor of the control being added
[in]alignmentthe alignment to use for the control being added
void AddLayout ( LayoutManager layout,
int  stretch = 0 
)

Adds a child LayoutManager to the stack.

Parameters
[in]layoutthe LayoutManager being added as a child to the layout
[in]stretchthe Stretch Factor of the blank item added to the stack
void AddSpacing ( int  size)

Adds a Spacing item to the stack.

Parameters
[in]sizethe size of the spacing to add. This size is in pixels.
void AddStretch ( int  stretch = 0)

Adds a blank item with a given Stretch Factor to the stack.

Parameters
[in]stretchthe Stretch Factor of the blank item added to the stack.
virtual size_t Count ( ) const
overridevirtual

Returns the number of items in this layout.

Implements LayoutManager.

static StackLayout* Create ( LayoutDirection  direction = LD_TopToBottom,
LayoutControl parent = 0 
)
static

Creates a StackLayout Layout Manager.

Parameters
[in]directionThe LayoutDirection for the new layout
[in]parentThe parent LayoutControl
Returns
A pointer to the new StackLayout object.
virtual BSize GetDesiredSize ( ) const
overridevirtual

Returns the desired size for this layout item.

Implements LayoutItem.

LayoutDirection GetDirection ( ) const

Gets the layout direction.

Returns
the direction of this StackLayout
virtual LayoutOrientations GetExpandingOrientations ( ) const
overridevirtual

Returns whether this layout item can make use of more space than GetDesiredSize().

A value of LO_Vertical or LO_Horizontal means that it wants to grow in only one dimension, whereas LO_Vertical | LO_Horizontal means that it wants to grow in both dimensions.

Reimplemented from LayoutManager.

virtual int GetHeightForWidth ( int  width) const
overridevirtual

Returns the preferred height for this layout item, given the width.

Parameters
[in]widthThe width for which to retrieve the preferred height.

Reimplemented from LayoutItem.

virtual BSize GetMaximumSize ( ) const
overridevirtual

Returns the maximum size for this layout item.

Reimplemented from LayoutManager.

virtual int GetMinimumHeightForWidth ( int  width) const
overridevirtual

Returns the minimum height for this layout item, given the width.

Parameters
[in]widthThe width for which to retrieve the minimum height.

Reimplemented from LayoutItem.

virtual BSize GetMinimumSize ( ) const
overridevirtual

Returns the minimum size for this layout item.

Reimplemented from LayoutManager.

int GetSpacing ( ) const
virtual

Gets the spacing between items in the layout.

If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it return -1.

Reimplemented from LayoutManager.

int GetStretchFactor ( int  index) const

Retrieves the stretch factor for the item at a given index.

virtual bool HasHeightForWidth ( ) const
overridevirtual

Returns whether this layout's preferred height depends on its width.

For GridLayout, it depends on whether the layout items in the rows and columns have a height for width.

Reimplemented from LayoutItem.

virtual void Invalidate ( )
overridevirtual

Resets the layout's rectangle then calls Update()

Reimplemented from LayoutManager.

virtual LayoutItem* ItemAt ( int  index) const
overridevirtual

Retrieves the item at index in the layout and returns the item.

If there is no such item, the function returns NULL.

Parameters
[in]indexThe index of the item to retrieve. Items are numbered consecutively from 0.

Implements LayoutManager.

void SetDirection ( LayoutDirection  direction)

Sets the layout direction.

Parameters
[in]directionthe new direction of this StackLayout
virtual void SetDirty ( )
overridevirtual

Resets the layout's rectangle then calls Update()

Reimplemented from LayoutManager.

virtual void SetGeometry ( const BRect rect)
overridevirtual

Sets the geometry for this layout item to the given rectangle.

Parameters
[in]rectThe rectangle of the new geometry for the layout item.

Reimplemented from LayoutManager.

void SetSpacing ( int  spacing)
virtual

Sets the horizontal and vertical spacing between items in the layout.

Parameters
[in]spacingThe amount of space between items in the layout.

Reimplemented from LayoutManager.

bool SetStretchFactor ( LayoutControl ctl,
int  stretch 
)

Sets the stretch factor for a given control.

bool SetStretchFactor ( LayoutManager layout,
int  stretch 
)

Sets the stretch factor for a given layout.

void SetStretchFactor ( int  index,
int  stretch 
)

Sets the stretch factor for the item at a given index.

virtual LayoutItem* TakeAt ( int  index)
overridevirtual

Removes the item at index from the layout, and returns the item.

If there is no such item, the function does nothing and returns NULL.

Parameters
[in]indexThe index of the item to remove. Items are numbered consecutively from 0.

Implements LayoutManager.


The documentation for this class was generated from the following file:

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.