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

An empty layout item that expands into empty space based on its size configuration. More...

Inherits BLayoutItem.

Public Member Functions

 BSpaceLayoutItem (BMessage *archive)
 Constructs a BSpaceLayoutItem from an archive message. More...
 
 BSpaceLayoutItem (BSize minSize, BSize maxSize, BSize preferredSize, BAlignment alignment)
 Create a space layout item with specific properties. More...
 
virtual ~BSpaceLayoutItem ()
 Destructor. More...
 
virtual BAlignment Alignment ()
 Returns the requested alignment for this item. More...
 
virtual status_t Archive (BMessage *into, bool deep=true) const
 Archive the object into a BMessage. More...
 
virtual BRect Frame ()
 Return the bounding frame of this item. More...
 
virtual bool IsVisible ()
 Return the current local visibility of this item. More...
 
virtual BSize MaxSize ()
 Returns the maximum desirable size for this item. More...
 
virtual BSize MinSize ()
 Returns the minimum desirable size for this item. More...
 
virtual BSize PreferredSize ()
 Returns the preferred size for this item. More...
 
virtual void SetExplicitAlignment (BAlignment alignment)
 Set this item's explicit alignment, to be used in Alignment(). More...
 
virtual void SetExplicitMaxSize (BSize size)
 Set this item's explicit max size, to be used in MaxSize(). More...
 
virtual void SetExplicitMinSize (BSize size)
 Set this item's explicit min size, to be used in MinSize(). More...
 
virtual void SetExplicitPreferredSize (BSize size)
 Set this item's explicit preferred size, to be used in PreferredSize(). More...
 
virtual void SetFrame (BRect frame)
 Set the bounding frame of this item. More...
 
virtual void SetVisible (bool visible)
 Set the visibility of this space layout item. More...
 
- Public Member Functions inherited from BLayoutItem
 BLayoutItem (BMessage *from)
 Archive constructor. More...
 
BLayoutLayout () const
 Returns the BLayout this BLayoutItem resides in. More...
 
virtual status_t Perform (perform_code d, void *arg)
 Perform some action (Internal method defined for binary compatibility purposes).
 
bool RemoveSelf ()
 Remove this layout item from the BLayout it is a part of. More...
 
virtual BViewView ()
 Return the BView this item is representing, or NULL if it does not represent any view. More...
 
virtual bool HasHeightForWidth ()
 Returns whether or not this BLayoutItem's height constraints are dependent on its width. More...
 
virtual void GetHeightForWidth (float width, float *min, float *max, float *preferred)
 Get this BLayoutItem's height constraints for a given width. More...
 
void SetExplicitSize (BSize size)
 Set the explicity size to size. More...
 
void AlignInFrame (BRect frame)
 Position this BLayoutItem within frame, given the value returned by Alignment(), and the size constraints for this item. More...
 
virtual void InvalidateLayout (bool children=false)
 Invalidate the layout of this item, or the object it represents. More...
 
virtual void Relayout (bool immediate=false)
 Relayout any children or onscreen data this item contains. Often this request is forwarded to another object. More...
 
void * LayoutData () const
 Retrieve arbitrary data attached to this BLayoutItem. More...
 
void SetLayoutData (void *data)
 Attach arbitrary data to this BLayoutItem. More...
 
- Public Member Functions inherited from BArchivable
 BArchivable ()
 Constructor. Does nothing. More...
 
 BArchivable (BMessage *from)
 Constructor. Does important behind-the-scenes work in the unarchiving process. More...
 
virtual ~BArchivable ()
 Destructor. Does nothing. More...
 

Static Public Member Functions

static BSpaceLayoutItemCreateGlue ()
 Create a layout item that acts like glue. More...
 
static BSpaceLayoutItemCreateHorizontalStrut (float width)
 Create a layout item that horizontally expands to a maximum width. More...
 
static BSpaceLayoutItemCreateVerticalStrut (float height)
 Create a layout item that vertically expands to a maximum height. More...
 
static BArchivableInstantiate (BMessage *from)
 Instantiate the item from the message from. More...
 
- Static Public Member Functions inherited from BArchivable
static BArchivableInstantiate (BMessage *archive)
 Static member to restore objects from messages. More...
 

Additional Inherited Members

- Protected Member Functions inherited from BLayoutItem
virtual status_t AllArchived (BMessage *into) const
 Method relating to the use of BArchiver. More...
 
virtual status_t AllUnarchived (const BMessage *from)
 Method relating to the use of BUnarchiver. More...
 
virtual void LayoutInvalidated (bool children)
 Hook called from InvalidateLayout(). More...
 
virtual void AttachedToLayout ()
 Hook called when this object is attached to a BLayout (via BLayout::AddItem()) More...
 
virtual void DetachedFromLayout (BLayout *layout)
 Hook called when this object is attached to a BLayout (via BLayout::RemoveItem()) More...
 
virtual void AncestorVisibilityChanged (bool shown)
 Hook called when this BLayoutItem's ancestors change visibility, effectively hiding or showing this item. More...
 

Detailed Description

An empty layout item that expands into empty space based on its size configuration.

This class is a specialized layout item, that is used to distribute space within one of the layouts. The layout item can be manually configured, but there are also two default varieties.

The first variety is the glue variety. Glue is an element that expands to the maximum space that is available. Let's say, you have a horizontal BGroupLayout. You want a button on the left, and a button on the right, with empty space in the middle. The middle element can be a glue element. The glue will push the right button all the way to the end of the available space. If the host view gets larger, the glue will expand. You can use the static method BSpaceLayoutItem::CreateGlue() to easily create a glue element.

Another variety is the strut. A is a layout item with no minimum size, and a maximum size. This means that the item might be smaller than the maximum size, but it will never be larger than the maximum size. You can use the static methods BSpaceLayoutItem::CreateVerticalStrut() and BSpaceLayoutItem::CreateHorizontalStrut() to create a strut item.

The default constructor allows you to create a layout item with custom minimum sizes, maximum sizes, preferred sizes and alignments.

See also
Where applicable, the Layout API builder classes have convenience methods to add glue or struts. See BLayoutBuilder::Group<ParentBuilder>::AddGlue() or BLayoutBuilder::Group<ParentBuilder>::AddStrut().
Since
Haiku R1

Constructor & Destructor Documentation

◆ BSpaceLayoutItem() [1/2]

BSpaceLayoutItem::BSpaceLayoutItem ( BSize  minSize,
BSize  maxSize,
BSize  preferredSize,
BAlignment  alignment 
)

Create a space layout item with specific properties.

See the CreateGlue(), CreateVerticalStrut() and CreateHorizontalStruct static methods to create common space items.

Parameters
minSizeThe minimum size for this item.
maxSizeThe maximum size for this item.
preferredSizeThe preferred size for this item.
alignmentThe alignment of this item.
Since
Haiku R1

◆ BSpaceLayoutItem() [2/2]

BSpaceLayoutItem::BSpaceLayoutItem ( BMessage archive)

Constructs a BSpaceLayoutItem from an archive message.

This method is usually not called directly, if you want to build a space layout item from an archived message you should call Instantiate() instead because it can handle errors properly.

Parameters
archiveThe BMessage that contains the space layout item.
Since
Haiku R1

◆ ~BSpaceLayoutItem()

BSpaceLayoutItem::~BSpaceLayoutItem ( )
virtual

Destructor.

Since
Haiku R1

Member Function Documentation

◆ Alignment()

BAlignment BSpaceLayoutItem::Alignment ( )
virtual

Returns the requested alignment for this item.

The value returned from this method is used in BLayoutItem::AlignInFrame(), which BLayouts use to position and resize items. In a vertical BGroupLayout, for example, although each item recieves the same horizontal area, each item can use that area differently, aligning to the left, right or center for example.

Since
Haiku R1

Implements BLayoutItem.

◆ Archive()

virtual status_t BSpaceLayoutItem::Archive ( BMessage into,
bool  deep = true 
) const
virtual

Archive the object into a BMessage.

You should call this method from your derived implementation as it adds the data needed to instantiate your object to the message.

Parameters
intoThe message you store your object in.
deepIf true, all children of this object should be archived as well.
Return values
B_OKThe archive operation was successful.
B_BAD_VALUENULL archive message.
B_ERRORThe archive operation failed.
Since
BeOS R3

Reimplemented from BLayoutItem.

◆ CreateGlue()

static BSpaceLayoutItem * BSpaceLayoutItem::CreateGlue ( )
static

Create a layout item that acts like glue.

This type of space layout item has no minimum size, and expands to the maximum available space in all directions.

Returns
Creates a new BSpaceLayoutItem and returns ownership to the caller.
Since
Haiku R1

Referenced by BLayoutBuilder::Group< ParentBuilder >::AddGlue(), and BLayoutBuilder::Grid< ParentBuilder >::AddGlue().

◆ CreateHorizontalStrut()

static BSpaceLayoutItem * BSpaceLayoutItem::CreateHorizontalStrut ( float  width)
static

Create a layout item that horizontally expands to a maximum width.

The item has no minimum size, meaning that if the total available width is smaller than the maximum width, the strut will use the available space.

Parameters
widthThe maximum width.
Returns
Creates a new BSpaceLayoutItem and returns ownership to the caller.
Since
Haiku R1

Referenced by BLayoutBuilder::Group< ParentBuilder >::AddStrut().

◆ CreateVerticalStrut()

static static BSpaceLayoutItem * BSpaceLayoutItem::CreateVerticalStrut ( float  height)
static

Create a layout item that vertically expands to a maximum height.

The item has no minimum size, meaning that if the total available height is smaller than the maximum width, the strut will use the available space.

Parameters
heightThe maximum height.
Returns
Creates a new BSpaceLayoutItem and returns ownership to the caller.
Since
Haiku R1

Referenced by BLayoutBuilder::Group< ParentBuilder >::AddStrut().

◆ Frame()

BRect BSpaceLayoutItem::Frame ( )
virtual

Return the bounding frame of this item.

The returned BRect is in the coordinate system of the target view of the BLayout this item belongs to.

Since
Haiku R1

Implements BLayoutItem.

◆ Instantiate()

static BArchivable * BSpaceLayoutItem::Instantiate ( BMessage from)
static

Instantiate the item from the message from.

Since
Haiku R1

◆ IsVisible()

bool BSpaceLayoutItem::IsVisible ( )
virtual

Return the current local visibility of this item.

The visibility is set explicitly through SetVisible(). By default, the layout item is visible.

Since
Haiku R1

Implements BLayoutItem.

◆ MaxSize()

BSize BSpaceLayoutItem::MaxSize ( )
virtual

Returns the maximum desirable size for this item.

Since
Haiku R1

Implements BLayoutItem.

◆ MinSize()

BSize BSpaceLayoutItem::MinSize ( )
virtual

Returns the minimum desirable size for this item.

Since
Haiku R1

Implements BLayoutItem.

◆ PreferredSize()

BSize BSpaceLayoutItem::PreferredSize ( )
virtual

Returns the preferred size for this item.

Since
Haiku R1

Implements BLayoutItem.

◆ SetExplicitAlignment()

void BSpaceLayoutItem::SetExplicitAlignment ( BAlignment  alignment)
virtual

Set this item's explicit alignment, to be used in Alignment().

Since
Haiku R1

Implements BLayoutItem.

◆ SetExplicitMaxSize()

void BSpaceLayoutItem::SetExplicitMaxSize ( BSize  size)
virtual

Set this item's explicit max size, to be used in MaxSize().

Since
Haiku R1

Implements BLayoutItem.

◆ SetExplicitMinSize()

void BSpaceLayoutItem::SetExplicitMinSize ( BSize  size)
virtual

Set this item's explicit min size, to be used in MinSize().

This forces the minimal size for the item and overrides any constraints that would normally be used to compute it. Most importantly, the minimal size of children is ignored, so setting this can lead to the children not fitting the view.

Since
Haiku R1

Implements BLayoutItem.

◆ SetExplicitPreferredSize()

void BSpaceLayoutItem::SetExplicitPreferredSize ( BSize  size)
virtual

Set this item's explicit preferred size, to be used in PreferredSize().

Since
Haiku R1

Implements BLayoutItem.

◆ SetFrame()

void BSpaceLayoutItem::SetFrame ( BRect  frame)
virtual

Set the bounding frame of this item.

frame is in the coordinate system of the target view of the BLayout that this item belongs to.

Since
Haiku R1

Implements BLayoutItem.

◆ SetVisible()

void BSpaceLayoutItem::SetVisible ( bool  visible)
virtual

Set the visibility of this space layout item.

Parameters
visibleThe desired visibility of the layout item.
Since
Haiku R1

Implements BLayoutItem.