Stay variables, what's the point?

94 views
Skip to first unread message

Alex Birkett

unread,
Oct 8, 2014, 3:34:07 AM10/8/14
to overcon...@googlegroups.com
Hi,

I'm new to cassowary and I'm trying to get my head around the basics. I think I now understand what a stay variable is after reading this constructor:

    public ClEditOrStayConstraint(ClVariable var, ClStrength strength, double weight) {
        super(strength, weight);
        _variable = var;
        _expression = new ClLinearExpression(_variable, -1.0, _variable.getValue());
    }

If I understand correctly it's an expression that sets a variable to its own initial value.

An expression that sets a variable to a value is obviously useful. I don't understand the point of setting a variable to it's own initial value though. It just confuses newbies like me. Why not just have an expression that sets a variable to a value? Then nobody would ever need to explain the concept of stays.

In the java implementation at least, if I want to change the value of the stay variable. I need to re-add it to the solver.

Any comments. Have I misunderstood?

Thanks,

Alex

Ken Ferry

unread,
Oct 8, 2014, 4:48:46 AM10/8/14
to overcon...@googlegroups.com
Think about how when you resize a window, the window always stays at whatever size it is when you let go of the mouse.

Stay constraints are like that. A stay says, "don't change this unless you have to. If you _do_ have to change it, then try to stick at the new value, forgetting the original entirely."


--
You received this message because you are subscribed to the Google Groups "overconstrained" group.
To unsubscribe from this group and stop receiving emails from it, send an email to overconstrain...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Birkett

unread,
Oct 8, 2014, 5:26:11 AM10/8/14
to overcon...@googlegroups.com
Thanks, Ken! Just to clarify, does the solver treat the linear expression created by the stay constraint as a special case?

Or to put it a different way, how is this code different from adding a stay variable (assuming the strength is the same a stay variable)?

            ClVariable myvar = new ClVariable();
            double INITAL_VALUE = 100;
            solver.addConstraint(new ClLinearEquation(new ClLinearExpression(myvar, -1.0, INITAL_VALUE)));

kenf...@gmail.com

unread,
Oct 10, 2014, 1:05:13 AM10/10/14
to overcon...@googlegroups.com
On Wednesday, Oct 8, 2014 at 5:26 AM, Alex Birkett <al...@birkett.co.uk>, wrote:
Thanks, Ken! Just to clarify, does the solver treat the linear expression created by the stay constraint as a special case?

Or to put it a different way, how is this code different from adding a stay variable (assuming the strength is the same a stay variable)?

            ClVariable myvar = new ClVariable();
            double INITAL_VALUE = 100;
            solver.addConstraint(new ClLinearEquation(new ClLinearExpression(myvar, -1.0, INITAL_VALUE)));
Yes, this is different. In the window resize example from before, if this was used instead of a stay constraint then the window would snap back to its original frame every time you let go of the mouse. 

Cacaodev cacaodev

unread,
Oct 10, 2014, 3:03:12 PM10/10/14
to overcon...@googlegroups.com

Le mercredi 8 octobre 2014 09:34:07 UTC+2, Alex Birkett a écrit :

In the java implementation at least, if I want to change the value of the stay variable. I need to re-add it to the solver.

Hi, I am using the javascript version of cassowary and I also had issues with externally modified stay variables. All I can say is that there were "unexpected behavior" (very difficult to reduce) and the only way to fix them was to remove and re-add stay variables with their new values and constant.
I submitted a test to this repository showing that the constant (constraint.expression.constant) in the stayConstraint is not updated when the value is successfully edited. Is it a bug or i'm missing something ?
I would be very interested if you have an example of a stay variable who refuses to change its value or the constant it is supposed to stick to.

Martin.
N.B: I am currently trying to implement autolayout into cappuccino, a javascript framework: https://github.com/cacaodev/cappuccino/tree/Autolayout
Reply all
Reply to author
Forward
0 new messages