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

## Detailed Description

Expresses a coordinate as a dynamically evaluated expression.

When using relative coordinates to position components, the following symbols are available:

- "left", "right", "top", "bottom" refer to the position of those edges in this component, so e.g. for a component whose width is always 100, you might set the right edge to the "left + 100".
- "[id].left", "[id].right", "[id].top", "[id].bottom", "[id].width", "[id].height", where [id] is the identifier of one of this component's siblings. A component's identifier is set with Component::setComponentID(). So for example if you want your component to always be 50 pixels to the right of the one called "xyz", you could set your left edge to be "xyz.right + 50".
- Instead of an [id], you can use the name "parent" to refer to this component's parent. Like any other component, these values are relative to their component's parent, so "parent.right" won't be very useful for positioning a component because it refers to a position with the parent's parent, but "parent.width" can be used for setting positions relative to the parent's size. E.g. to make a 10x10 component which remains 1 pixel away from its parent's bottom-right, you could use "right - 10, bottom - 10, parent.width - 1, parent.height - 1".
- The name of one of the parent component's markers can also be used as a symbol. For markers to be used, the parent component must implement its Component::getMarkers() method, and return at least one valid MarkerList. So if you want your component's top edge to be 10 pixels below the marker called "foobar", you'd set it to "foobar + 10".

See the Expression class for details about the operators that are supported, but for example if you wanted to make your component remains centred within its parent with a size of 100, 100, you could express it as:

myComp.setBounds (RelativeBounds ("parent.width / 2 - 50, parent.height / 2 - 50, left + 100, top + 100"));

or an alternative way to achieve the same thing:

myComp.setBounds (RelativeBounds ("right - 100, bottom - 100, parent.width / 2 + 50, parent.height / 2 + 50"));

Or if you wanted a 100x100 component whose top edge is lined up to a marker called "topMarker" and which is positioned 50 pixels to the right of another component called "otherComp", you could write:

myComp.setBounds (RelativeBounds ("otherComp.right + 50, topMarker, left + 100, top + 100"));

Be careful not to make your coordinate expressions recursive, though, or exceptions and assertions will be thrown!

See also
  RelativePoint, RelativeRectangle

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

- juce_gui_basics/positioning/juce_RelativeCoordinate.h

## Classes

struct | Strings
| A set of static strings that are commonly used by the RelativeCoordinate class. More...
struct | StandardStrings

## Public Member Functions

| RelativeCoordinate ()
| Creates a zero coordinate.
| RelativeCoordinate (const Expression &expression)
| RelativeCoordinate (const RelativeCoordinate &)
RelativeCoordinate & | operator= (const RelativeCoordinate &)
| RelativeCoordinate (RelativeCoordinate &&) noexcept
RelativeCoordinate & | operator= (RelativeCoordinate &&) noexcept
| RelativeCoordinate (double absoluteDistanceFromOrigin)
| Creates an absolute position from the parent origin on either the X or Y axis.
| RelativeCoordinate (const String &stringVersion)
| Recreates a coordinate from a string description.
| ~RelativeCoordinate ()
| Destructor.
bool | operator== (const RelativeCoordinate &) const noexcept
bool | operator!= (const RelativeCoordinate &) const noexcept
double | resolve (const Expression::Scope *evaluationScope) const
| Calculates the absolute position of this coordinate.
bool | references (const String &coordName, const Expression::Scope *evaluationScope) const
| Returns true if this coordinate uses the specified coord name at any level in its evaluation.
bool | isRecursive (const Expression::Scope *evaluationScope) const
| Returns true if there's a recursive loop when trying to resolve this coordinate's position.
bool | isDynamic () const
| Returns true if this coordinate depends on any other coordinates for its position.
void | moveToAbsolute (double absoluteTargetPosition, const Expression::Scope *evaluationScope)
| Changes the value of this coord to make it resolve to the specified position.
const Expression & | getExpression () const
| Returns the expression that defines this coordinate.
String | toString () const
| Returns a string which represents this coordinate.

## Constructors and Destructors

## RelativeCoordinate() [1/6]

juce::RelativeCoordinate::RelativeCoordinate | ( |  | ) |

Creates a zero coordinate.

Referenced by operator!=(), operator=(), operator=(), operator==(), RelativeCoordinate(), RelativeCoordinate(), RelativeCoordinate(), RelativeCoordinate(), and ~RelativeCoordinate().

## RelativeCoordinate() [2/6]

juce::RelativeCoordinate::RelativeCoordinate | ( | const Expression & | expression | ) |

## RelativeCoordinate() [3/6]

juce::RelativeCoordinate::RelativeCoordinate | ( | const RelativeCoordinate & |  | ) |

References RelativeCoordinate().

## RelativeCoordinate() [4/6]

juce::RelativeCoordinate::RelativeCoordinate | ( | RelativeCoordinate && |  | ) |

noexcept

References RelativeCoordinate().

## RelativeCoordinate() [5/6]

juce::RelativeCoordinate::RelativeCoordinate | ( | double | absoluteDistanceFromOrigin | ) |

Creates an absolute position from the parent origin on either the X or Y axis.

Parameters

  absoluteDistanceFromOrigin | the distance from the origin

References RelativeCoordinate().

## RelativeCoordinate() [6/6]

juce::RelativeCoordinate::RelativeCoordinate | ( | const String & | stringVersion | ) |

Recreates a coordinate from a string description.

The string will be parsed by ExpressionParser::parse().

Parameters

  stringVersion | the expression to use

See also
  toString

References RelativeCoordinate().

## ~RelativeCoordinate()

juce::RelativeCoordinate::~RelativeCoordinate | ( |  | ) |

Destructor.

References RelativeCoordinate().

## Member Functions

## operator=() [1/2]

RelativeCoordinate & juce::RelativeCoordinate::operator= | ( | const RelativeCoordinate & |  | ) |

References RelativeCoordinate().

## operator=() [2/2]

RelativeCoordinate & juce::RelativeCoordinate::operator= | ( | RelativeCoordinate && |  | ) |

noexcept

References RelativeCoordinate().

## operator==()

bool juce::RelativeCoordinate::operator== | ( | const RelativeCoordinate & |  | ) | const

noexcept

References RelativeCoordinate().

## operator!=()

bool juce::RelativeCoordinate::operator!= | ( | const RelativeCoordinate & |  | ) | const

noexcept

References RelativeCoordinate().

## resolve()

double juce::RelativeCoordinate::resolve | ( | const Expression::Scope * | evaluationScope | ) | const

Calculates the absolute position of this coordinate.

You'll need to provide a suitable Expression::Scope for looking up any coordinates that may be needed to calculate the result.

References resolve().

Referenced by resolve().

## references()

bool juce::RelativeCoordinate::references | ( | const String & | coordName,
|  | const Expression::Scope * | evaluationScope ) const

Returns true if this coordinate uses the specified coord name at any level in its evaluation.

This will recursively check any coordinates upon which this one depends.

References references().

Referenced by references().

## isRecursive()

bool juce::RelativeCoordinate::isRecursive | ( | const Expression::Scope * | evaluationScope | ) | const

Returns true if there's a recursive loop when trying to resolve this coordinate's position.

References isRecursive().

Referenced by isRecursive().

## isDynamic()

bool juce::RelativeCoordinate::isDynamic | ( |  | ) | const

Returns true if this coordinate depends on any other coordinates for its position.

References isDynamic().

Referenced by isDynamic().

## moveToAbsolute()

void juce::RelativeCoordinate::moveToAbsolute | ( | double | absoluteTargetPosition,
|  | const Expression::Scope * | evaluationScope )

Changes the value of this coord to make it resolve to the specified position.

Calling this will leave the anchor points unchanged, but will set this coordinate's absolute or relative position to whatever value is necessary to make its resultant position match the position that is provided.

References moveToAbsolute().

Referenced by moveToAbsolute().

## getExpression()

const Expression & juce::RelativeCoordinate::getExpression | ( |  | ) | const

inline

Returns the expression that defines this coordinate.

References getExpression().

Referenced by getExpression().

## toString()

String juce::RelativeCoordinate::toString | ( |  | ) | const

Returns a string which represents this coordinate.

For details of the string syntax, see the constructor notes.

### 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