Hi Tzu-ping,
Your analysis is pretty much dead on - the two constraints solutions are both mathematically legitimate, assuming there's no other constraints.
The catch is that AFAICT, there *are* other constraints under Cocoa that aren't publicly advertised. At the very least, there's an enforced minimum size on some widgets (e.g., text inputs); I suspect there's also some internal preferencing of expansion (e.g., text labels expand rather than buttons). It's these extra constraints that make the system non-ambiguous.
Constraints of this style *can* be implemented using pure Cassowary constraints... as long as you know what they are. Under GTK, I've added a couple of constraints to the widgets themselves in an attempt to get them right. However, I'm not convinced that I've got them all correct - there are a couple of edge cases where GTK doesn't behave quite right.
So - unfortunately, I don't have an easy answer here. There is a mailing list for the Cassowary algorithm:
and the list seems to be have some readers with inside (or at least, very well informed) knowledge of the internals of Apple's Cassowary implementation. I've been intending to post there to see if I can get some of my blanks filled in.
Yours,
Russ Magee %-)