what's wrong with this basic orientation change handling code, to change object widths/position?

Anyone able to spot the issues here?  When I run this and toggle between portrait and landscape it does not work as expected (re width of rectangles following changing size of the effective width)

Try to get what the basic (simple) concept/approach is to handle autosizing UI elements to support Portrait and Landscape…

display.setStatusBar( display.HiddenStatusBar ) local WIDTH\_PERCENT = 0.8 local myGroup = display.newGroup() local myRoundedRect = display.newRoundedRect(myGroup, 0,0, display.contentWidth \* WIDTH\_PERCENT, 50, 25) myRoundedRect.strokeWidth = 3 myRoundedRect:setFillColor(0,1,0) myRoundedRect:setStrokeColor(1,0,0) myRoundedRect.y = 25 local myRoundedRect2 = display.newRoundedRect(myGroup, 0,0, display.contentWidth \* WIDTH\_PERCENT, 50, 25) myRoundedRect2.strokeWidth = 3 myRoundedRect2:setFillColor(0,0,1) myRoundedRect2:setStrokeColor(1,0,0) myRoundedRect2.y = 75 local function positionItems()     myRoundedRect.width = display.contentWidth \* WIDTH\_PERCENT     myRoundedRect2.width = display.contentWidth \* WIDTH\_PERCENT          myRoundedRect.x = display.contentWidth/2     myRoundedRect2.x = display.contentWidth/2 end positionItems() local function onOrientationChange( event )     positionItems() end Runtime:addEventListener( "orientation", onOrientationChange )  

See my feedback at this forum link

http://forums.coronalabs.com/topic/41884-auto-rotation-question/

Rob/Brent - this seems to be a bug, you view?  

Alex - this is all on Graphics 2.0 (I’m on version Version 2014.2122 (2014.1.4))

It seems to be an issue with setting the width programatically of a Rectangle after it is already in place.  I’m assume this is the basic operation that corona supports.  So what I’m seeing with the below code is:

  • If initially set to say a width of 1000 for the square as you toggle orientation it decreases in size each time until you can’t see it

  • If you set initially to say 10 you get a really weird pattern indeed

  • After you reset the size of the rectangle and then read it back it doesn’t have seemed to changed in value, but then that still doesn’t explain the above two points

Code:

display.setStatusBar( display.HiddenStatusBar ) local WIDTH\_PERCENT = 0.5 local INITIAL\_BOX\_WIDTH = 1000    -- pre immediate width/height setting by the "positionItems" functions local myGroup = display.newGroup() local myRoundedRect = display.newRoundedRect(myGroup, 0,0, INITIAL\_BOX\_WIDTH,INITIAL\_BOX\_WIDTH, 25) myRoundedRect.strokeWidth = 1 myRoundedRect:setFillColor(0,1,0) myRoundedRect:setStrokeColor(1,0,0) local function positionItems()     local displayW, displayH = display.contentWidth, display.contentHeight          myRoundedRect.width = displayW \* WIDTH\_PERCENT     myRoundedRect.height = displayH \* WIDTH\_PERCENT     myRoundedRect.x =displayW/2     myRoundedRect.y =displayH/2          print("Set width to " ..  displayW \* WIDTH\_PERCENT .. " . Read value back from Rec = " .. myRoundedRect.width) end positionItems() local function onOrientationChange( event )     positionItems() end Runtime:addEventListener( "orientation", onOrientationChange )  

Config (below - or just nothing gives same issue)

local aspectRatio =display.pixelHeight/display.pixelWidth application = { &nbsp; &nbsp; content = &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; width = aspectRatio \> 1.5 and 320 or math.ceil(480 /aspectRatio), &nbsp; &nbsp; &nbsp; &nbsp; height = aspectRatio\<1.5 and 480 or math.ceil (320\*aspectRatio), &nbsp; &nbsp; &nbsp; &nbsp; scale = "letterbox", &nbsp; &nbsp; } } &nbsp;

build

settings = { &nbsp; &nbsp; orientation = &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default = "portrait", &nbsp; &nbsp; &nbsp; &nbsp;supported = { "portrait","landscapeLeft", "landscapeRight","portraitUpsideDown" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, &nbsp; &nbsp; }, } &nbsp;

 

Update:

* Noted the issue of the ever disappearing rect (as you toggle orientation) only occurs for newRoundedRect, not newRect.  So question still stands

* Noted the weird pattern is just the large value of radius I used - you can reduce this down and still see the disappearing issue

See my feedback at this forum link

http://forums.coronalabs.com/topic/41884-auto-rotation-question/

Rob/Brent - this seems to be a bug, you view?  

Alex - this is all on Graphics 2.0 (I’m on version Version 2014.2122 (2014.1.4))

It seems to be an issue with setting the width programatically of a Rectangle after it is already in place.  I’m assume this is the basic operation that corona supports.  So what I’m seeing with the below code is:

  • If initially set to say a width of 1000 for the square as you toggle orientation it decreases in size each time until you can’t see it

  • If you set initially to say 10 you get a really weird pattern indeed

  • After you reset the size of the rectangle and then read it back it doesn’t have seemed to changed in value, but then that still doesn’t explain the above two points

Code:

display.setStatusBar( display.HiddenStatusBar ) local WIDTH\_PERCENT = 0.5 local INITIAL\_BOX\_WIDTH = 1000&nbsp;&nbsp;&nbsp;&nbsp;-- pre immediate width/height setting by the "positionItems" functions local myGroup = display.newGroup() local myRoundedRect = display.newRoundedRect(myGroup, 0,0, INITIAL\_BOX\_WIDTH,INITIAL\_BOX\_WIDTH, 25) myRoundedRect.strokeWidth = 1 myRoundedRect:setFillColor(0,1,0) myRoundedRect:setStrokeColor(1,0,0) local function positionItems() &nbsp;&nbsp;&nbsp;&nbsp;local displayW, displayH = display.contentWidth, display.contentHeight &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;myRoundedRect.width = displayW \* WIDTH\_PERCENT &nbsp;&nbsp;&nbsp;&nbsp;myRoundedRect.height = displayH \* WIDTH\_PERCENT &nbsp;&nbsp;&nbsp;&nbsp;myRoundedRect.x =displayW/2 &nbsp;&nbsp;&nbsp;&nbsp;myRoundedRect.y =displayH/2 &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;print("Set width to " .. &nbsp;displayW \* WIDTH\_PERCENT .. " . Read value back from Rec = " .. myRoundedRect.width) end positionItems() local function onOrientationChange( event ) &nbsp;&nbsp;&nbsp;&nbsp;positionItems() end Runtime:addEventListener( "orientation", onOrientationChange ) &nbsp;

Config (below - or just nothing gives same issue)

local aspectRatio =display.pixelHeight/display.pixelWidth application = { &nbsp; &nbsp; content = &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; width = aspectRatio \> 1.5 and 320 or math.ceil(480 /aspectRatio), &nbsp; &nbsp; &nbsp; &nbsp; height = aspectRatio\<1.5 and 480 or math.ceil (320\*aspectRatio), &nbsp; &nbsp; &nbsp; &nbsp; scale = "letterbox", &nbsp; &nbsp; } } &nbsp;

build

settings = { &nbsp; &nbsp; orientation = &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default = "portrait", &nbsp; &nbsp; &nbsp; &nbsp;supported = { "portrait","landscapeLeft", "landscapeRight","portraitUpsideDown" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, &nbsp; &nbsp; }, } &nbsp;

 

Update:

* Noted the issue of the ever disappearing rect (as you toggle orientation) only occurs for newRoundedRect, not newRect.  So question still stands

* Noted the weird pattern is just the large value of radius I used - you can reduce this down and still see the disappearing issue