Expressions and symbols

RelativeRectangle labelRect;
Expression labelHeight(20);
labelRect.right=RelativeCoordinate("parent.width - 30");"parent.height / 2") - labelHeight/Expression(2));


While the above works, its kinda clumsy(deliberately so for clarity). What i’m wondering is if there’s a way to define a symbol for an expression(without using markers). In this case I want labelHeight to be 20… If that’s somehow possible then I could simplify the top definition to be

 RelativeCoordinate("parent.height/2 - labelHeight/2");

And then i’m hoping changing the symbol labelHeight to a different number would update the RelativeRectangle with no interference by me!
Does that make sense?


Sure you can i created a very elaborate expression subsystem in my app (with math functions etc), you just need to subclass Expression::Scope and pass your own to the Expression you are evaluating, you can supply your own symbols and functions.


Thanks Atom, I’m still trying to wrap my head around everything with expressions. Seems very powerful.

For what I want though would this(Custom scope) work? I think RelativeRectangle’s applyToComponent is used to set the bounds and it seems to always supply a null scope which then makes a RelativeRectangleLocalScope.

Do you use expressions and custom Symbols/Functions to setBounds? (Without needing to manually evaluate the expression?)


I use expressions for lots of stuff, didn’t use them for relative bounds etc. I use them to evaluate certain values so that end users have flexibility when setting some stuff. Have a look here: and look for the evaluateFunction () and getSymbolValue () methods (those are Expression::Scope methods)
For the functions and their parameters: the method is evaluateFormulaFunction ()


Thanks Atom, that’s very useful for the future.

I looked more at the sources, and a markerlist seems to be the way to go. I was keeping away from them because I didn’t want to have to subclass all the child components. However it seems Jules has thought ahead(as usual) and checks the parent component for a markerlist. So I think that will work for me!


Just a follow up, this works great(using a marker list in my containing component)



transferButton->setComponentID("transferButton"); // Important for other Expressions to reference this component...
transferButton->setBounds("indent+5,parent.height / 2 - buttonHeight/2,left+buttonWidth,top+buttonHeight"); // keeps vertically centred in parent

And sure enough, later on changing


updates the bounds properly.

(I wanted to do this for buttons whose image is generated dynamically into an image with text drawn into it(with dropshadows and stuff), and depending on the font size preferences this button’s dimensions should grow). So then I can set constants in the marker list by querying the image for its ideal dimensions when the font size changes.