Mixing the "top, left" properties with the "x.y" ones in a tableView

Hi all,

I was working with a tableView and my simulator was set to iphoneX. The table needed to be in the middle of the view horizontally but vertically there was the page title above it, so it was shifted down a bit.

Originally I used the “top, left” properties to set the table and everything was working fine until I switch the simulator to iPad. The table was no longer in the middle. I thought, that was wasy to fix by setting the x property to display.contentCenterX instead of using “left”, but I kept the “top” property, as vertical positionning was OK.

This didn’t solve the problem. Printing the value of x, I noticed that it was not being set to display.contentCenterX.

After debugging for a bit I noticed that things work if I replace “top” with “y” and calculate the y value manually.

Does this mean we can’t mix “x” or “y” with "left or “top”? I assumed that all “left”, “top” do is to (internally) calculate “x,y”, since “left, top” are not readable properties at runtime.

If that is the case then maybe it should be added to the “Gotchas” section.

It is best to always centre objects and then adjust the height and width to fit the device you are running on.

Here is some code (put it in main.lua) to always know the centre of the screen.

--screen constants \_originX, \_originY = display.screenOriginX, display.screenOriginY \_W, \_H = display.actualContentWidth, display.actualContentHeight \_centreX, \_centreY = \_originX + \_W/2, \_originY + \_H/2

Then to fill a tableView to the entire screen you can use…

 local tableView = widget.newTableView { left = \_originX, top = \_originY, height = \_H, width = \_W, }

Thanks @SGS. Useful tips.

My question though was about using “top” with “x” property. Typically you would use “top” and “left” to position objects, but sometimes it might be clearer to use “top” and “x”. This doesn’t seem to be supported by Corona. Not a big deal, since I can calculate the “left” value from x.