Loading...
Searching...
No Matches
juce::ComponentBoundsConstrainer Class Reference

## Detailed Description

A class that imposes restrictions on a Component's size or position.

This is used by classes such as ResizableCornerComponent, ResizableBorderComponent and ResizableWindow.

The base class can impose some basic size and position limits, but you can also subclass this for custom uses.

See also
  ResizableCornerComponent, ResizableBorderComponent, ResizableWindow

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

- juce_gui_basics/layout/juce_ComponentBoundsConstrainer.h

Inheritance diagram for juce::ComponentBoundsConstrainer:

## Public Member Functions

| ComponentBoundsConstrainer () noexcept
| When first created, the object will not impose any restrictions on the components.
virtual | ~ComponentBoundsConstrainer ()
| Destructor.
void | setMinimumWidth (int minimumWidth) noexcept
| Imposes a minimum width limit.
int | getMinimumWidth () const noexcept
| Returns the current minimum width.
void | setMaximumWidth (int maximumWidth) noexcept
| Imposes a maximum width limit.
int | getMaximumWidth () const noexcept
| Returns the current maximum width.
void | setMinimumHeight (int minimumHeight) noexcept
| Imposes a minimum height limit.
int | getMinimumHeight () const noexcept
| Returns the current minimum height.
void | setMaximumHeight (int maximumHeight) noexcept
| Imposes a maximum height limit.
int | getMaximumHeight () const noexcept
| Returns the current maximum height.
void | setMinimumSize (int minimumWidth, int minimumHeight) noexcept
| Imposes a minimum width and height limit.
void | setMaximumSize (int maximumWidth, int maximumHeight) noexcept
| Imposes a maximum width and height limit.
void | setSizeLimits (int minimumWidth, int minimumHeight, int maximumWidth, int maximumHeight) noexcept
| Set all the maximum and minimum dimensions.
void | setMinimumOnscreenAmounts (int minimumWhenOffTheTop, int minimumWhenOffTheLeft, int minimumWhenOffTheBottom, int minimumWhenOffTheRight) noexcept
| Sets the amount by which the component is allowed to go off-screen.
int | getMinimumWhenOffTheTop () const noexcept
| Returns the minimum distance the bounds can be off-screen.
int | getMinimumWhenOffTheLeft () const noexcept
| Returns the minimum distance the bounds can be off-screen.
int | getMinimumWhenOffTheBottom () const noexcept
| Returns the minimum distance the bounds can be off-screen.
int | getMinimumWhenOffTheRight () const noexcept
| Returns the minimum distance the bounds can be off-screen.
void | setFixedAspectRatio (double widthOverHeight) noexcept
| Specifies a width-to-height ratio that the resizer should always maintain.
double | getFixedAspectRatio () const noexcept
| Returns the aspect ratio that was set with setFixedAspectRatio().
virtual void | checkBounds (Rectangle< int > &bounds, const Rectangle< int > &previousBounds, const Rectangle< int > &limits, bool isStretchingTop, bool isStretchingLeft, bool isStretchingBottom, bool isStretchingRight)
| This callback changes the given coordinates to impose whatever the current constraints are set to be.
virtual void | resizeStart ()
| This callback happens when the resizer is about to start dragging.
virtual void | resizeEnd ()
| This callback happens when the resizer has finished dragging.
void | setBoundsForComponent (Component *component, Rectangle< int > bounds, bool isStretchingTop, bool isStretchingLeft, bool isStretchingBottom, bool isStretchingRight)
| Checks the given bounds, and then sets the component to the corrected size.
void | checkComponentBounds (Component *component)
| Performs a check on the current size of a component, and moves or resizes it if it fails the constraints.
virtual void | applyBoundsToComponent (Component &, Rectangle< int > bounds)
| Called by setBoundsForComponent() to apply a new constrained size to a component.

## Constructors and Destructors

## ComponentBoundsConstrainer()

juce::ComponentBoundsConstrainer::ComponentBoundsConstrainer | ( |  | ) |

noexcept

When first created, the object will not impose any restrictions on the components.

Referenced by applyBoundsToComponent(), juce::BorderedComponentBoundsConstrainer::getWrappedConstrainer(), and ~ComponentBoundsConstrainer().

## ~ComponentBoundsConstrainer()

virtual juce::ComponentBoundsConstrainer::~ComponentBoundsConstrainer | ( |  | ) |

virtual

Destructor.

References ComponentBoundsConstrainer().

## Member Functions

## setMinimumWidth()

void juce::ComponentBoundsConstrainer::setMinimumWidth | ( | int | minimumWidth | ) |

noexcept

Imposes a minimum width limit.

References setMinimumWidth().

Referenced by setMinimumWidth().

## getMinimumWidth()

int juce::ComponentBoundsConstrainer::getMinimumWidth | ( |  | ) | const

inline noexcept

Returns the current minimum width.

References getMinimumWidth().

Referenced by getMinimumWidth().

## setMaximumWidth()

void juce::ComponentBoundsConstrainer::setMaximumWidth | ( | int | maximumWidth | ) |

noexcept

Imposes a maximum width limit.

## getMaximumWidth()

int juce::ComponentBoundsConstrainer::getMaximumWidth | ( |  | ) | const

inline noexcept

Returns the current maximum width.

## setMinimumHeight()

void juce::ComponentBoundsConstrainer::setMinimumHeight | ( | int | minimumHeight | ) |

noexcept

Imposes a minimum height limit.

## getMinimumHeight()

int juce::ComponentBoundsConstrainer::getMinimumHeight | ( |  | ) | const

inline noexcept

Returns the current minimum height.

## setMaximumHeight()

void juce::ComponentBoundsConstrainer::setMaximumHeight | ( | int | maximumHeight | ) |

noexcept

Imposes a maximum height limit.

## getMaximumHeight()

int juce::ComponentBoundsConstrainer::getMaximumHeight | ( |  | ) | const

inline noexcept

Returns the current maximum height.

## setMinimumSize()

void juce::ComponentBoundsConstrainer::setMinimumSize | ( | int | minimumWidth,
|  | int | minimumHeight )

noexcept

Imposes a minimum width and height limit.

## setMaximumSize()

void juce::ComponentBoundsConstrainer::setMaximumSize | ( | int | maximumWidth,
|  | int | maximumHeight )

noexcept

Imposes a maximum width and height limit.

## setSizeLimits()

void juce::ComponentBoundsConstrainer::setSizeLimits | ( | int | minimumWidth,
|  | int | minimumHeight,
|  | int | maximumWidth,
|  | int | maximumHeight )

noexcept

Set all the maximum and minimum dimensions.

## setMinimumOnscreenAmounts()

void juce::ComponentBoundsConstrainer::setMinimumOnscreenAmounts | ( | int | minimumWhenOffTheTop,
|  | int | minimumWhenOffTheLeft,
|  | int | minimumWhenOffTheBottom,
|  | int | minimumWhenOffTheRight )

noexcept

Sets the amount by which the component is allowed to go off-screen.

The values indicate how many pixels must remain on-screen when dragged off one of its parent's edges, so e.g. if minimumWhenOffTheTop is set to 10, then when the component goes off the top of the screen, its y-position will be clipped so that there are always at least 10 pixels on-screen. In other words, the lowest y-position it can take would be (10 - the component's height).

If you pass 0 or less for one of these amounts, the component is allowed to move beyond that edge completely, with no restrictions at all.

If you pass a very large number (i.e. larger that the dimensions of the component itself), then the component won't be allowed to overlap that edge at all. So e.g. setting minimumWhenOffTheLeft to 0xffffff will mean that the component will bump into the left side of the screen and go no further.

## getMinimumWhenOffTheTop()

int juce::ComponentBoundsConstrainer::getMinimumWhenOffTheTop | ( |  | ) | const

inline noexcept

Returns the minimum distance the bounds can be off-screen.

See also
  setMinimumOnscreenAmounts

## getMinimumWhenOffTheLeft()

int juce::ComponentBoundsConstrainer::getMinimumWhenOffTheLeft | ( |  | ) | const

inline noexcept

Returns the minimum distance the bounds can be off-screen.

See also
  setMinimumOnscreenAmounts

## getMinimumWhenOffTheBottom()

int juce::ComponentBoundsConstrainer::getMinimumWhenOffTheBottom | ( |  | ) | const

inline noexcept

Returns the minimum distance the bounds can be off-screen.

See also
  setMinimumOnscreenAmounts

## getMinimumWhenOffTheRight()

int juce::ComponentBoundsConstrainer::getMinimumWhenOffTheRight | ( |  | ) | const

inline noexcept

Returns the minimum distance the bounds can be off-screen.

See also
  setMinimumOnscreenAmounts

## setFixedAspectRatio()

void juce::ComponentBoundsConstrainer::setFixedAspectRatio | ( | double | widthOverHeight | ) |

noexcept

Specifies a width-to-height ratio that the resizer should always maintain.

If the value is 0, no aspect ratio is enforced. If it's non-zero, the width will always be maintained as this multiple of the height.

See also
  setResizeLimits

## getFixedAspectRatio()

double juce::ComponentBoundsConstrainer::getFixedAspectRatio | ( |  | ) | const

noexcept

Returns the aspect ratio that was set with setFixedAspectRatio().

If no aspect ratio is being enforced, this will return 0.

## checkBounds()

virtual void juce::ComponentBoundsConstrainer::checkBounds | ( | Rectangle< int > & | bounds,
|  | const Rectangle< int > & | previousBounds,
|  | const Rectangle< int > & | limits,
|  | bool | isStretchingTop,
|  | bool | isStretchingLeft,
|  | bool | isStretchingBottom,
|  | bool | isStretchingRight )

virtual

This callback changes the given coordinates to impose whatever the current constraints are set to be.

Parameters

  bounds | the target position that should be examined and adjusted
  previousBounds | the component's current size
  limits | the region in which the component can be positioned
  isStretchingTop | whether the top edge of the component is being resized
  isStretchingLeft | whether the left edge of the component is being resized
  isStretchingBottom | whether the bottom edge of the component is being resized
  isStretchingRight | whether the right edge of the component is being resized

Reimplemented in juce::BorderedComponentBoundsConstrainer.

References checkBounds().

Referenced by checkBounds().

## resizeStart()

virtual void juce::ComponentBoundsConstrainer::resizeStart | ( |  | ) |

virtual

This callback happens when the resizer is about to start dragging.

References resizeStart().

Referenced by resizeStart().

## resizeEnd()

virtual void juce::ComponentBoundsConstrainer::resizeEnd | ( |  | ) |

virtual

This callback happens when the resizer has finished dragging.

References resizeEnd().

Referenced by resizeEnd().

## setBoundsForComponent()

void juce::ComponentBoundsConstrainer::setBoundsForComponent | ( | Component * | component,
|  | Rectangle< int > | bounds,
|  | bool | isStretchingTop,
|  | bool | isStretchingLeft,
|  | bool | isStretchingBottom,
|  | bool | isStretchingRight )

Checks the given bounds, and then sets the component to the corrected size.

References setBoundsForComponent().

Referenced by setBoundsForComponent().

## checkComponentBounds()

void juce::ComponentBoundsConstrainer::checkComponentBounds | ( | Component * | component | ) |

Performs a check on the current size of a component, and moves or resizes it if it fails the constraints.

References checkComponentBounds().

Referenced by checkComponentBounds().

## applyBoundsToComponent()

virtual void juce::ComponentBoundsConstrainer::applyBoundsToComponent | ( | Component & | ,
|  | Rectangle< int > | bounds )

virtual

Called by setBoundsForComponent() to apply a new constrained size to a component.

By default this just calls setBounds(), but is virtual in case it's needed for extremely cunning purposes.

References applyBoundsToComponent(), ComponentBoundsConstrainer(), and JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR.

Referenced by applyBoundsToComponent().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited