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. | |
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.
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 | ( | ) |
Destructor.
void StretchableLayoutManager::setItemLayout | ( | int | itemIndex, |
double | minimumSize, | ||
double | maximumSize, | ||
double | preferredSize ) |
For a numbered item, this sets its size limits and preferred size.
itemIndex | the index of the item to change. |
minimumSize | the 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%) |
maximumSize | the 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 |
preferredSize | the 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 |
bool StretchableLayoutManager::getItemLayout | ( | int | itemIndex, |
double & | minimumSize, | ||
double & | maximumSize, | ||
double & | preferredSize ) const |
For a numbered item, this returns its size limits and preferred size.
itemIndex | the index of the item. |
minimumSize | the 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%) |
maximumSize | the 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 |
preferredSize | the 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 |
void StretchableLayoutManager::clearAllItems | ( | ) |
Clears all the properties that have been set with setItemLayout() and resets this object to its initial state.
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.
components | an array of components that correspond to each of the numbered items that the StretchableLayoutManager object has been told about with setItemLayout() |
numComponents | the 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. |
x | the left of the rectangle in which the components should be laid out |
y | the top of the rectangle in which the components should be laid out |
width | the width of the rectangle in which the components should be laid out |
height | the height of the rectangle in which the components should be laid out |
vertically | if 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 |
resizeOtherDimension | if 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. |
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.
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.
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.
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).
itemIndex | the item to move |
newPosition | the 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 |