Hacker News new | ask | show | jobs
by melloclello 3374 days ago
As I remember, an early CSS proposal included the Cassowary constraints solver engine, but they decided not to go with it because either a fast implementation didn't exist at the time, or they were worried users wouldn't find the system intuitive?
2 comments

I remember that the Cassowary constraint system was implemented in Apple's app development framework, and people reporting that it was hell to work with after building anything beyond minimal complexity.

Also, there is an actual GSS implementation by thegrid.io

https://gridstylesheets.org/

I've worked with Auto Layout a bit.

- The GUI built into Xcode is usable once you learn its quirks (e.g. how to swap the relationship in a constraint so that it doesn't say that the right edge of some button needs to be -5pt from the left edge of the button next to it).

- The ObjC/Swift API is bad.

- It handles RTL languages excellently: by default, constraints are expressed in terms of leading/trailing edges, but can be literal left/right if you want.

- It deals poorly with adding and removing views from a hierarchy: removing a view discards all of its constraints, so you need to have logic to reestablish them.

Unfortunately, there are horror stories about performance tanking with an OS update or taking on exponential properties, like this one which lead the team to develop a non-constraint-based layout framework:

https://realm.io/news/slug-nick-snyder-layoutkit/

It leads me to wonder if unpredictable performance is a limitation of constraint solving… or at least to be cautious with current implementations. Maybe an API that only makes known-fast relationships possible would help.

To be fair, the blame isn't on the Cassowary approach, but Xcode's god awful Interface Builder UI.
Ah, what a world that would have been!
Probably people were trying to talk to the constraint system by typing code manually, rather than using a graphical editor. All the CAD systems with a constraint engine let you deal with it graphically, which is straightforward.
For comparison, here's what Autodesk Inventor's 2D sketch mode is like.

- If you draw a line, and it's close to horizontal or vertical, it gets a horizontal or vertical constraint. The constraint shows as a symbol and you can click on it and hit DEL if you don't want it.

- If you start a line from very close to another line, or close to another point, the endpoint is constrained to touch that line or point.

- You can explicitly select various constraints from a menu bar, such as "parallel", "collinear", "coincident", "tangent", and then select two lines, which applies the constraint. This works on lines, circles, arcs, and splines.

- If you try to add a conflicting constraint, you get an error message and the constraint won't be applied. Constraints do not have priorities; all constraints are enforced.

- You can explicitly dimension something, and give it an absolute length or angle, or some function of other dimensions.

- Anything that isn't constrained can be dragged and moved. There's a counter of the number of unconstrained degrees of freedom, and when everything is locked by some constraint, the message "Fully constrained" appears. All unconstrained degrees of freedom are displayed as straight or curved arrows, indicating how something could be moved.

- The hard cases, such as making a arc tangent to a line, or circles tangent to each other, work right.

It's a really easy way to set up geometry for parts you're going to make. This is all part of a much larger system for full 3D machine design, but the sketch module is close to what you'd want for web layout.