I recently found I was trying to dynamically position a bunch of controls and was constantly adding the left+width or finding the centers, and in doing so was duplicating the same basic equations over and over. Then I recalled that Swift has methods attached to all the controls that return these values directly… so I created these simple extends for the RECTCONTROL. And since almost all controls inherit from RECTCONTROL… just adding this code to your project will add these functions to every control you are using.
Some are just an alias for existing properties, some have a tiny bit of math, all should be self explanitory
Public Function minX(Extends ctl as Rectcontrol) as integer
Return ctl.Left
End Function
Public Function maxX(Extends ctl as Rectcontrol) as integer
Return ctl.Left+ctl.width
End Function
Public Function maxY(Extends ctl as Rectcontrol) as integer
Return ctl.Top+ctl.Height
End Function
Public Function midX(Extends ctl as Rectcontrol) as integer
Return ctl.Left+(ctl.width/2)
End Function
Public Function midY(Extends ctl as Rectcontrol) as integer
Return ctl.Top+(ctl.height/2)
End Function
Public Function minY(Extends ctl as Rectcontrol) as integer
Return ctl.Top
End Function
Public Function Origin(Extends ctl as Rectcontrol) as REALbasic.Point
Return New REALbasic.Point(ctl.Left,ctl.top)
End Function
Public Function Size(Extends ctl as Rectcontrol) as REALbasic.Size
Return New REALbasic.Size(ctl.width,ctl.height)
End Function