Basic Autolayout question

  1. 6 months ago

    Dave S

    Oct 3 San Diego, California USA

    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?

  2. Greg O

    Oct 3 Xojo Inc
    Edited 6 months ago

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

  3. Greg O

    Oct 3 Xojo Inc

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

  4. Dave S

    Oct 3 San Diego, California USA

    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.

  5. Greg O

    Oct 3 Xojo Inc

    You'd say Child.Right should stay "X" pixels from Parent.Right (or another control's Left).

  6. 5 months ago

    Dave S

    Oct 4 San Diego, California USA

    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

  7. Greg O

    Oct 5 Xojo Inc
    Edited 5 months ago

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

  8. Dave S

    Oct 5 San Diego, California USA

    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 :)

  9. Greg O

    Oct 5 Xojo Inc
    Edited 5 months ago

    Cassowary IS Autolayout.

  10. Paul R

    Oct 5 Pre-Release Testers, Xojo Pro Kirkland, WA

    @Greg OLone Cassowary IS Autolayout.

    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.

or Sign Up to reply!