JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ComponentBoundsConstrainer Class Reference

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

#include <juce_ComponentBoundsConstrainer.h>

Inheritance diagram for juce::ComponentBoundsConstrainer:
Collaboration diagram for juce::ComponentBoundsConstrainer:

Public Member Functions

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

Private Attributes

double aspectRatio = 0
 
int maxH = 0x3fffffff
 
int maxW = 0x3fffffff
 
int minH = 0
 
int minOffBottom = 0
 
int minOffLeft = 0
 
int minOffRight = 0
 
int minOffTop = 0
 
int minW = 0
 

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

@tags{GUI}

Constructor & Destructor Documentation

◆ ComponentBoundsConstrainer()

juce::ComponentBoundsConstrainer::ComponentBoundsConstrainer ( )
noexcept

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

◆ ~ComponentBoundsConstrainer()

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

Destructor.

Member Function Documentation

◆ 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.

◆ 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
boundsthe target position that should be examined and adjusted
previousBoundsthe component's current size
limitsthe region in which the component can be positioned
isStretchingTopwhether the top edge of the component is being resized
isStretchingLeftwhether the left edge of the component is being resized
isStretchingBottomwhether the bottom edge of the component is being resized
isStretchingRightwhether the right edge of the component is being resized

Reimplemented in juce::StandaloneFilterWindow::DecoratorConstrainer.

Referenced by juce::StandaloneFilterWindow::DecoratorConstrainer::checkBounds().

◆ 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.

◆ 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.

◆ getMaximumHeight()

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

Returns the current maximum height.

◆ getMaximumWidth()

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

Returns the current maximum width.

References juce::gl::maxW.

◆ getMinimumHeight()

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

Returns the current minimum height.

◆ getMinimumWhenOffTheBottom()

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

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

See also
setMinimumOnscreenAmounts

◆ getMinimumWhenOffTheLeft()

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

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

See also
setMinimumOnscreenAmounts

◆ getMinimumWhenOffTheRight()

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

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

See also
setMinimumOnscreenAmounts

◆ getMinimumWhenOffTheTop()

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

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

See also
setMinimumOnscreenAmounts

◆ getMinimumWidth()

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

Returns the current minimum width.

References juce::gl::minW.

◆ resizeEnd()

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

This callback happens when the resizer has finished dragging.

◆ resizeStart()

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

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

◆ 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.

◆ 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

◆ setMaximumHeight()

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

Imposes a maximum height limit.

◆ setMaximumSize()

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

Imposes a maximum width and height limit.

◆ setMaximumWidth()

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

Imposes a maximum width limit.

◆ setMinimumHeight()

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

Imposes a minimum height limit.

◆ 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.

◆ setMinimumSize()

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

Imposes a minimum width and height limit.

◆ setMinimumWidth()

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

Imposes a minimum width limit.

◆ setSizeLimits()

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

Set all the maximum and minimum dimensions.

Member Data Documentation

◆ aspectRatio

double juce::ComponentBoundsConstrainer::aspectRatio = 0
private

◆ maxH

int juce::ComponentBoundsConstrainer::maxH = 0x3fffffff
private

◆ maxW

int juce::ComponentBoundsConstrainer::maxW = 0x3fffffff
private

◆ minH

int juce::ComponentBoundsConstrainer::minH = 0
private

◆ minOffBottom

int juce::ComponentBoundsConstrainer::minOffBottom = 0
private

◆ minOffLeft

int juce::ComponentBoundsConstrainer::minOffLeft = 0
private

◆ minOffRight

int juce::ComponentBoundsConstrainer::minOffRight = 0
private

◆ minOffTop

int juce::ComponentBoundsConstrainer::minOffTop = 0
private

◆ minW

int juce::ComponentBoundsConstrainer::minW = 0
private

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