Using the rectanglealign( function

I have a procedure which creates a number of rectangle objects and text label objects and which should centre each text label object within its relevant rectangle object. So, each pair should look like this:

Screen Shot 2021-10-27 at 4.29.25 pm

Sometimes that happens and sometimes the centering process doesn’t work and I get this:

Screen Shot 2021-10-27 at 4.30.53 pm

Here’s the code - can anybody find a fault in it?

;        MakeObjects        27 October 2021


local lvNamesArray, Centered, lvLocationX, lvLocationY, lvSizeHeight, lvSizeWidth, lvColor, lvProcedure

lvNamesArray = "Tickers,Services,Managed,Holdings,Accounts,Trades,Downloads"
lvColor = "FFD600"
lvProcedure = "call .Buttons"
lvLocationX = "40"
lvLocationY = "220"
lvSizeWidth = "150"
lvSizeHeight = "30"

looparray lvNamesArray,",",ButtonName,LoopCount
    newformobject "rectangle", "name",ButtonName, "color",lvColor, "$LocationX",lvLocationX, "procedure",lvProcedure, "$LocationY",lvLocationY, "$SizeWidth",lvSizeWidth, "$SizeHeight",lvSizeHeight
    newformobject "text label", "name",ButtonName+"Label", "$TextLabelContent",ButtonName, "$LocationX",lvLocationX, "$LocationY",lvLocationY
    Centered = rectanglealign(objectinfo("rectangle",ButtonName),objectinfo("rectangle",ButtonName+"Label"),"center")
    changeobject ButtonName+"Label","rectangle",Centered
    if LoopCount < arraysize(lvNamesArray,",")
        newformobject "line", "$StrokeWidth","2", "$LocationX",str(val(lvLocationX) + 151), "$LocationY",lvLocationY, "$SizeWidth","0",  "$SizeHeight",lvSizeHeight
    lvLocationX = str(val(lvLocationX) + 151)

I think I’ve worked out why this happens. A couple of times, I created one bar, grouped its contents and tucked it away at the bottom of the form. When I ran the procedure again, the centering statement didn’t work - probably because there were now two copies of each object on the form. Does that sound reasonable?

It would be so much simpler to do this with a Text Display object, and with Panorama X 10.2 Denali, only one object is required – you could dispense with the rectangle object. You can get the yellow color by specifying the background color, and set the alignment options to center both horizontally and vertically.

I would suggest that you create an object manually, then create a blueprint from that that you can use as the basis for your code.

Thanks Jim - that will simplify the process considerably.