Basic Autolayout question

this doesn’t really apply to Xojo (yet) as AL is used only in the iOS product (for now)… but the question might become more relavant if/when AL comes to Desktop.
But in anycase, I’m trying to get a handle on simple basic generic Autolayout

Suppose one wanted to duplicate the LockLeft/Top/Right/Bottom feature… should be a simple thing.
for Left and top…
you would set a “left constraint” that is X units from the screen left side and a “top constraint” that is Y units from the top… so when the window was resized the Left and Top would stay in place

but what would the proper values be for right and bottom?
I would think that it would be

leftC        = child.X
topC       = child.Y
rightC      = parent.width - child.x + child.width
bottomC = parent.height - child.y + child.height

 rightConstraint   = NSLayoutConstraint(item       : child,
                                               attribute  : .right,
                                               relatedBy  : .equal,
                                               toItem     : parentView,
                                               attribute  : .right,
                                               multiplier : 1.0,
                                               constant   : rightC)

Am I even is the right ballpark here?

Close. You wouldn’t set right & bottom though. You’d actually set Width & Height constraints.
Yes. That would work.

Keep in mind that the constraint system already knows about “right” as well as “width” so you wouldn’t need all of those calculations.

Confused… that would make sense if I wanted to lock all four… but I was inferring that any combination of those may or may not be turned off…

So if I wanted to lock to the right, and have the child stay “X” pixels from the parent edge as the parent changed size.

You’d say Child.Right should stay “X” pixels from Parent.Right (or another control’s Left).

Greg… here is a question that relates directly to Xojo, and I’m asking for educational purposes (I like to know how things work)

For Xojo controls locks (left/top/right/bottom) and I correct in assuming that Xojo does NOT invoke autolayout constraints in the compiled code. The reason I make this assumption is (all related to DESKTOP not to iOS)

  • Autolayout came out long after Xojo/RealBasic did
  • Autolayout is (or so it seems) to be limited mostly to macOS type code

If that is true what does Xojo do behind the scenes to provide this function? Its a rather simple scheme (lock one or more sides of the control to the corresponding side of the container (window or groupbox etc)

I thought I’d teach myself about AL by trying to duplicate something I already knew about. And the strange thing is I have something that works… But… if I lock the right and/or bottom of Control B, then Control A freaks out . Note , since I’m trying to learn AL, I’m not doing this in Xojo at the moment, but since it seems AL is the “future” I want to be prepared.

I have 6 constraints… Left/Top/Right/Bottom/Height/Width
Height and Width are active… UNLESS both Left/Right or Top/Bottom are active

Am I correct in assuming this is merely a thought experiment? Or have you actually built a cassowary-style constraint solver in Xojo?

A thought experiment… trying to figure out how AL constraints work and interact with each other… To be honest… have No idea what a “cassowary-style” solver would be :slight_smile:

Cassowary IS Autolayout.

https://en.wikipedia.org/wiki/Cassowary_(software)

[quote=408613:@Greg O’Lone]Cassowary IS Autolayout.

https://en.wikipedia.org/wiki/Cassowary_(software)[/quote]

Huh, dèjávu. Just before that paper was published, I did a class in grad school, taught by Alan Borning and Greg Badros was the TA. Two of us created a constraint solver in Java for generic layout issues. Who knew.