Content Hugging and Compression Resistance

69 views
Skip to first unread message

Sēndá Lǐ

unread,
May 26, 2017, 9:06:40 AM5/26/17
to overconstrained
Hi, I am playing with the cassowary android. Since there is not too much documents, i don't know how to do the content hugging and compression resistance on iOS.

Are there any demo or explanation on that?
Also, I don't understand what is the "Strength" and "Weight". There is only one priority number on iOS.

Cacaodev cacaodev

unread,
May 26, 2017, 10:23:47 AM5/26/17
to overconstrained
In the Apple Autolayout system (iOs or macOs), content hugging and compression resistance on a dimension generate 2 constraints:

For example, for the width variable:

Anti Compression: width >= intrinsicSize.width (Anti Compression priority)
Content Hugging : width <= intrinsicSize.width (content Hugging priority)

These 2 constraints also act as a replacement for a stay variables which are nonexistent in Autolayout.

Concerning the priority, I am doing this:

Priority 0-999 <=> strength = c.Strength.medium / weight = priority
Priority 1000  <=> strength = c.Strength.required


Hope it helps,
cacaodev

Ken Ferry

unread,
May 26, 2017, 12:15:24 PM5/26/17
to overconstrained
Also, fwiw, Cocoa’s priority is like Cassowary’s strength, except cassowary only supports four levels. Weight is not in auto layout.
--
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.

Cacaodev cacaodev

unread,
May 26, 2017, 12:30:58 PM5/26/17
to overconstrained
Although, after posting this message, i have read here a post from Ken Ferry quoting Greg Badros saying "weight is not a concept". So let me take back the last part about how priority translates to Strength&Weight.

Greg Badros

unread,
May 27, 2017, 7:07:56 PM5/27/17
to overcon...@googlegroups.com
I *think* that Cocoa's single priority ends up meaning that there's no scalar priority you can give to a constraint to ensure that it is always satisfied in preference to other constraints.  The point of using a tuple of scalars instead of a single number was so that you can have tiers of constraints that are deemed strictly more important than everything at lesser levels.  I.e., in original Cassowary, if constraint C1 is Strong and all the other constraints are Medium or Weak, then no number of other constraints can be satisfied instead of satisfying C1.  I don't think that's true of the single-scalar priority. 

(And also note there's nothing fundamental about 4 strengths -- the tuple could've been 10 long or whatever.)

If my understanding of how the Cassowary-in-Cocoa implementation works is correct, it's interesting (and surprising a little bit) to me that this difference didn't matter in practice for folks.

Greg

On Fri, May 26, 2017 at 9:30 AM, Cacaodev cacaodev <caca...@gmail.com> wrote:
Although, after posting this message, i have read here a post from Ken Ferry quoting Greg Badros saying "weight is not a concept". So let me take back the last part about how priority translates to Strength&Weight.

--
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 overconstrained+unsubscribe@googlegroups.com.

Ken Ferry

unread,
May 28, 2017, 3:24:15 AM5/28/17
to overcon...@googlegroups.com
It’s a actually a bit reverse - Cocoa’s priority is like strength, not weight. Each different priority is a full tier. As you say, four is arbitrary; you can make each floating point number a full tier. 

(Implementation-wise, the coefficients of variables in the the objective row are vectors in an infinite dimensional vector space with only finintely many non-zero entries in each vector.)

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to overconstrain...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages