Loading...
Searching...
No Matches
StretchableLayoutManager Class Reference

For laying out a set of components, where the components have preferred sizes and size limits, but where they are allowed to stretch to fill the available space. More...

#include <juce_StretchableLayoutManager.h>

Public Member Functions

 StretchableLayoutManager ()
 Creates an empty layout.
 
 ~StretchableLayoutManager ()
 Destructor.
 
void setItemLayout (int itemIndex, double minimumSize, double maximumSize, double preferredSize)
 For a numbered item, this sets its size limits and preferred size.
 
bool getItemLayout (int itemIndex, double &minimumSize, double &maximumSize, double &preferredSize) const
 For a numbered item, this returns its size limits and preferred size.
 
void clearAllItems ()
 Clears all the properties that have been set with setItemLayout() and resets this object to its initial state.
 
void layOutComponents (Component **components, int numComponents, int x, int y, int width, int height, bool vertically, bool resizeOtherDimension)
 Takes a set of components that correspond to the layout's items, and positions them to fill a space.
 
int getItemCurrentPosition (int itemIndex) const
 Returns the current position of one of the items.
 
int getItemCurrentAbsoluteSize (int itemIndex) const
 Returns the current size of one of the items.
 
double getItemCurrentRelativeSize (int itemIndex) const
 Returns the current size of one of the items.
 
void setItemPosition (int itemIndex, int newPosition)
 Moves one of the items, shifting along any other items as necessary in order to get it to the desired position.
 

Detailed Description

For laying out a set of components, where the components have preferred sizes and size limits, but where they are allowed to stretch to fill the available space.

For example, if you have a component containing several other components, and each one should be given a share of the total size, you could use one of these to resize the child components when the parent component is resized. Then you could add a StretchableLayoutResizerBar to easily let the user rescale them.

A StretchableLayoutManager operates only in one dimension, so if you have a set of components stacked vertically on top of each other, you'd use one to manage their heights. To build up complex arrangements of components, e.g. for applications with multiple nested panels, you would use more than one StretchableLayoutManager. E.g. by using two (one vertical, one horizontal), you could create a resizable spreadsheet-style table.

E.g.

class MyComp : public Component
{
MyComp()
{
myLayout.setItemLayout (0, // for item 0
50, 100, // must be between 50 and 100 pixels in size
-0.6); // and its preferred size is 60% of the total available space
myLayout.setItemLayout (1, // for item 1
-0.2, -0.6, // size must be between 20% and 60% of the available space
50); // and its preferred size is 50 pixels
}
void resized()
{
// make a list of two of our child components that we want to reposition
Component* comps[] = { myComp1, myComp2 };
// this will position the 2 components, one above the other, to fit
// vertically into the rectangle provided.
myLayout.layOutComponents (comps, 2,
0, 0, getWidth(), getHeight(),
true);
}
};
The base class for all JUCE user-interface objects.
Definition juce_Component.h:48
For laying out a set of components, where the components have preferred sizes and size limits,...
Definition juce_StretchableLayoutManager.h:95
void layOutComponents(Component **components, int numComponents, int x, int y, int width, int height, bool vertically, bool resizeOtherDimension)
Takes a set of components that correspond to the layout's items, and positions them to fill a space.
void setItemLayout(int itemIndex, double minimumSize, double maximumSize, double preferredSize)
For a numbered item, this sets its size limits and preferred size.
See also
StretchableLayoutResizerBar

Constructor & Destructor Documentation

◆ StretchableLayoutManager()

StretchableLayoutManager::StretchableLayoutManager ( )

Creates an empty layout.

You'll need to add some item properties to the layout before it can be used to resize things - see setItemLayout().

◆ ~StretchableLayoutManager()

StretchableLayoutManager::~StretchableLayoutManager ( )

Destructor.

Member Function Documentation

◆ setItemLayout()

void StretchableLayoutManager::setItemLayout ( int itemIndex,
double minimumSize,
double maximumSize,
double preferredSize )

For a numbered item, this sets its size limits and preferred size.

Parameters
itemIndexthe index of the item to change.
minimumSizethe minimum size that this item is allowed to be - a positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space (e.g -0.5 is 50%)
maximumSizethe maximum size that this item is allowed to be - a positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space
preferredSizethe size that this item would like to be, if there's enough room. A positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space
See also
getItemLayout

◆ getItemLayout()

bool StretchableLayoutManager::getItemLayout ( int itemIndex,
double & minimumSize,
double & maximumSize,
double & preferredSize ) const

For a numbered item, this returns its size limits and preferred size.

Parameters
itemIndexthe index of the item.
minimumSizethe minimum size that this item is allowed to be - a positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space (e.g -0.5 is 50%)
maximumSizethe maximum size that this item is allowed to be - a positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space
preferredSizethe size that this item would like to be, if there's enough room. A positive number indicates an absolute size in pixels. A negative number indicates a proportion of the available space
Returns
false if the item's properties hadn't been set
See also
setItemLayout

◆ clearAllItems()

void StretchableLayoutManager::clearAllItems ( )

Clears all the properties that have been set with setItemLayout() and resets this object to its initial state.

◆ layOutComponents()

void StretchableLayoutManager::layOutComponents ( Component ** components,
int numComponents,
int x,
int y,
int width,
int height,
bool vertically,
bool resizeOtherDimension )

Takes a set of components that correspond to the layout's items, and positions them to fill a space.

This will try to give each item its preferred size, whether that's a relative size or an absolute one.

Parameters
componentsan array of components that correspond to each of the numbered items that the StretchableLayoutManager object has been told about with setItemLayout()
numComponentsthe number of components in the array that is passed-in. This should be the same as the number of items this object has been told about.
xthe left of the rectangle in which the components should be laid out
ythe top of the rectangle in which the components should be laid out
widththe width of the rectangle in which the components should be laid out
heightthe height of the rectangle in which the components should be laid out
verticallyif true, the components will be positioned in a vertical stack, so that they fill the height of the rectangle. If false, they will be placed side-by-side in a horizontal line, filling the available width
resizeOtherDimensionif true, this means that the components will have their other dimension resized to fit the space - i.e. if the 'vertically' parameter is true, their x-positions and widths are adjusted to fit the x and width parameters; if 'vertically' is false, their y-positions and heights are adjusted to fit the y and height parameters.

◆ getItemCurrentPosition()

int StretchableLayoutManager::getItemCurrentPosition ( int itemIndex) const

Returns the current position of one of the items.

This is only a valid call after layOutComponents() has been called, as it returns the last position that this item was placed at. If the layout was vertical, the value returned will be the y position of the top of the item, relative to the top of the rectangle in which the items were placed (so for example, item 0 will always have position of 0, even in the rectangle passed in to layOutComponents() wasn't at y = 0). If the layout was done horizontally, the position returned is the item's left-hand position, again relative to the x position of the rectangle used.

See also
getItemCurrentSize, setItemPosition

◆ getItemCurrentAbsoluteSize()

int StretchableLayoutManager::getItemCurrentAbsoluteSize ( int itemIndex) const

Returns the current size of one of the items.

This is only meaningful after layOutComponents() has been called, as it returns the last size that this item was given. If the layout was done vertically, it'll return the item's height in pixels; if it was horizontal, it'll return its width.

See also
getItemCurrentRelativeSize

◆ getItemCurrentRelativeSize()

double StretchableLayoutManager::getItemCurrentRelativeSize ( int itemIndex) const

Returns the current size of one of the items.

This is only meaningful after layOutComponents() has been called, as it returns the last size that this item was given. If the layout was done vertically, it'll return a negative value representing the item's height relative to the last size used for laying the components out; if the layout was done horizontally it'll be the proportion of its width.

See also
getItemCurrentAbsoluteSize

◆ setItemPosition()

void StretchableLayoutManager::setItemPosition ( int itemIndex,
int newPosition )

Moves one of the items, shifting along any other items as necessary in order to get it to the desired position.

Calling this method will also update the preferred sizes of the items it shuffles along, so that they reflect their new positions.

(This is the method that a StretchableLayoutResizerBar uses to shift the items about when it's dragged).

Parameters
itemIndexthe item to move
newPositionthe absolute position that you'd like this item to move to. The item might not be able to always reach exactly this position, because other items may have minimum sizes that constrain how far it can go

The documentation for this class was generated from the following file:
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram