35 auto type = RelativeCoordinate::StandardStrings::getTypeOf (symbol);
37 if (type == RelativeCoordinate::StandardStrings::width)
return Expression ((
double) component.
getWidth());
38 if (type == RelativeCoordinate::StandardStrings::height)
return Expression ((
double) component.
getHeight());
42 if (
auto* marker = findMarker (component, symbol, list))
43 return Expression (marker->position.getExpression().evaluate (*
this));
75 list =
mlh->getMarkers (
true);
78 marker = list->getMarker (name);
81 if (marker ==
nullptr)
85 list =
mlh->getMarkers (
false);
88 marker = list->getMarker (name);
99RelativeCoordinatePositionerBase::ComponentScope::ComponentScope (Component& comp)
106 switch (RelativeCoordinate::StandardStrings::getTypeOf (symbol))
108 case RelativeCoordinate::StandardStrings::x:
109 case RelativeCoordinate::StandardStrings::left:
return Expression ((
double) component.
getX());
110 case RelativeCoordinate::StandardStrings::y:
111 case RelativeCoordinate::StandardStrings::top:
return Expression ((
double) component.
getY());
112 case RelativeCoordinate::StandardStrings::width:
return Expression ((
double) component.
getWidth());
113 case RelativeCoordinate::StandardStrings::height:
return Expression ((
double) component.
getHeight());
114 case RelativeCoordinate::StandardStrings::right:
return Expression ((
double) component.
getRight());
115 case RelativeCoordinate::StandardStrings::bottom:
return Expression ((
double) component.
getBottom());
116 case RelativeCoordinate::StandardStrings::parent:
117 case RelativeCoordinate::StandardStrings::unknown:
125 if (
auto* marker = MarkerListScope::findMarker (*parent, symbol, list))
169 switch (RelativeCoordinate::StandardStrings::getTypeOf (symbol))
171 case RelativeCoordinate::StandardStrings::x:
172 case RelativeCoordinate::StandardStrings::left:
173 case RelativeCoordinate::StandardStrings::y:
174 case RelativeCoordinate::StandardStrings::top:
175 case RelativeCoordinate::StandardStrings::width:
176 case RelativeCoordinate::StandardStrings::height:
177 case RelativeCoordinate::StandardStrings::right:
178 case RelativeCoordinate::StandardStrings::bottom:
179 positioner.registerComponentListener (component);
182 case RelativeCoordinate::StandardStrings::parent:
183 case RelativeCoordinate::StandardStrings::unknown:
189 if (MarkerListScope::findMarker (*parent, symbol, list) !=
nullptr)
191 positioner.registerMarkerListListener (list);
198 positioner.registerMarkerListListener (mlh->getMarkers (
true));
199 positioner.registerMarkerListListener (mlh->getMarkers (
false));
208 return ComponentScope::getSymbolValue (symbol);
213 if (
Component*
const targetComp = (scopeName == RelativeCoordinate::Strings::parent)
215 : findSiblingComponent (scopeName))
223 positioner.registerComponentListener (*parent);
225 positioner.registerComponentListener (component);
236RelativeCoordinatePositionerBase::RelativeCoordinatePositionerBase (
Component& comp)
241RelativeCoordinatePositionerBase::~RelativeCoordinatePositionerBase()
243 unregisterListeners();
258 if (
getComponent().getParentComponent() == &changed && ! registeredOk)
264 jassert (sourceComponents.contains (&comp));
265 sourceComponents.removeFirstMatchingValue (&comp);
266 registeredOk =
false;
277 sourceMarkerLists.removeFirstMatchingValue (
markerList);
280void RelativeCoordinatePositionerBase::apply()
284 unregisterListeners();
285 registeredOk = registerCoordinates();
288 applyToComponentBounds();
291bool RelativeCoordinatePositionerBase::addCoordinate (
const RelativeCoordinate&
coord)
299bool RelativeCoordinatePositionerBase::addPoint (
const RelativePoint& point)
301 const bool ok = addCoordinate (point.x);
302 return addCoordinate (point.y) && ok;
305void RelativeCoordinatePositionerBase::registerComponentListener (Component& comp)
307 if (! sourceComponents.contains (&comp))
309 comp.addComponentListener (
this);
310 sourceComponents.add (&comp);
314void RelativeCoordinatePositionerBase::registerMarkerListListener (MarkerList*
const list)
316 if (list !=
nullptr && ! sourceMarkerLists.contains (list))
318 list->addListener (
this);
319 sourceMarkerLists.add (list);
323void RelativeCoordinatePositionerBase::unregisterListeners()
325 for (
int i = sourceComponents.size(); --i >= 0;)
326 sourceComponents.getUnchecked (i)->removeComponentListener (
this);
328 for (
int i = sourceMarkerLists.size(); --i >= 0;)
329 sourceMarkerLists.getUnchecked (i)->removeListener (
this);
331 sourceComponents.clear();
332 sourceMarkerLists.clear();
Positioner(Component &component) noexcept
Creates a Positioner which can control the specified component.
Component & getComponent() const noexcept
Returns the component that this positioner controls.
The base class for all JUCE user-interface objects.
Component * findChildWithID(StringRef componentID) const noexcept
Looks for a child component with the specified ID.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
int getBottom() const noexcept
Returns the y coordinate of the bottom edge of this component.
int getHeight() const noexcept
Returns the component's height in pixels.
int getX() const noexcept
Returns the x coordinate of the component's left edge.
int getY() const noexcept
Returns the y coordinate of the top of this component.
int getWidth() const noexcept
Returns the component's width in pixels.
int getRight() const noexcept
Returns the x coordinate of the component's right-hand edge.
Used as a callback by the Scope::visitRelativeScope() method.
When evaluating an Expression object, this class is used to resolve symbols and perform functions tha...
virtual Expression getSymbolValue(const String &symbol) const
Returns the value of a symbol.
virtual void visitRelativeScope(const String &scopeName, Visitor &visitor) const
Creates a Scope object for a named scope, and then calls a visitor to do some kind of processing with...
A class for dynamically evaluating simple numeric expressions.
double evaluate() const
Evaluates this expression, without using a Scope.
Represents a marker in a MarkerList.
RelativeCoordinate position
The marker's position.
Holds a set of named marker points along a one-dimensional axis.
Used for resolving a RelativeCoordinate expression in the context of a component.
String getScopeUID() const override
Returns some kind of globally unique ID that identifies this scope.
void visitRelativeScope(const String &scopeName, Visitor &) const override
Creates a Scope object for a named scope, and then calls a visitor to do some kind of processing with...
Expression getSymbolValue(const String &symbol) const override
Returns the value of a symbol.
Expression getSymbolValue(const String &symbol) const override
Returns the value of a symbol.
void visitRelativeScope(const String &scopeName, Visitor &visitor) const override
Creates a Scope object for a named scope, and then calls a visitor to do some kind of processing with...
Base class for Component::Positioners that are based upon relative coordinates.
void componentBeingDeleted(Component &) override
Called when the component is in the process of being deleted.
void componentChildrenChanged(Component &) override
Called when the component has children added or removed, or their z-order changes.
void markersChanged(MarkerList *) override
Called when something in the given marker list changes.
void componentParentHierarchyChanged(Component &) override
Called to indicate that the component's parents have changed.
void componentMovedOrResized(Component &, bool, bool) override
Called when the component's position or size changes.
void markerListBeingDeleted(MarkerList *) override
Called when the given marker list is being deleted.
const Expression & getExpression() const
Returns the expression that defines this coordinate.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
int pointer_sized_int
A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Expression getSymbolValue(const String &symbol) const override
Returns the value of a symbol.
void visitRelativeScope(const String &scopeName, Visitor &visitor) const override
Creates a Scope object for a named scope, and then calls a visitor to do some kind of processing with...
String getScopeUID() const override
Returns some kind of globally unique ID that identifies this scope.
A base class for objects that want to provide a MarkerList.
static const String parent
"parent"