You can’t do it by coordinates. The underlying system uses constraints and are so much more powerful than coordinates alone and because you never know how much space you’re going to get (especially on iPad) they’re also really important.
Constraints allow you to define relationships within and between controls and their views. So for instance, for these two canvases, you could have eight constraints if you wanted them to be square:
Let’s call them c1 and c2. Vertical first
- c1.top standard gap from view.top
- c2.top, standard gap from c1.bottom
- View.bottom, standard gap from c2.bottom
- c2.height, equal to c1.height
This in of itself is kinda magic. The two canvases are going to stay away from the top and bottom edges, away from each other and have the same heights, no matter what size screen they’re on.
Now horizontal:
5. c1.left, standard gap from view.left
6. c2.left, equal to c1.left
7. c1.width, equal to c1.height
8. c2.width, equal to c2.height
This group makes sure there’s a gap on the left and that the canvases have the same widths as their heights.
I find it easier if you draw out the layout you want and then draw lines representing the constraints within and between the controls and views. A good rule of thumb is “Two constraints per control in each direction when dealing with things being equal.”
Once in a while you’ll get into situations where you just can’t do what you want by purely using equals though. Like if these canvases have a minimum size. That’s when priorities and inequalities come into play. If, for instance, you needed the minimum size of these canvases to be 200, you can just say that:
- c1.width >= 200, Required
In that case, you’d need to give the system some indication of what to do if that wasn’t possible (like if the screen height < 400, in which case they both can’t be 200 tall, but we also told them that height = width.
It can get complicated, but I assure you that the results are worth learning this stuff.
FWIW, I did a Xojo webinar in 2023 about constraints and released a project which exposes their full power in Xojo projects. There’s even a method that converts Xojo layout constraints at runtime for use in this system.