Anchor not updating after changing button label

Hi Brent,

So I added the line and the button code looks like this now:

 addScreen.categoryBtn = widget.newButton( { label = "Friend", labelColor = {default={129/255, 202/255, 195/255}, over={1,1,1}}, font = font.robotoM, fontSize = 15, onEvent = functions.openCategory, emboss = false, textOnly = true, x = centerCor.addMainRectX \* 1.375, y = centerCor.addMainRectY \* 1.15, } ) addScreen.categoryBtn.anchorX = 0 addScreen.categoryBtn.anchorChildren = true

But that didn’t work :confused:

Any other suggestions?

Kind regards

Bram

Hi Bram,

Try flipping those two commands: anchor the children first, then set the anchor point. That might do the trick (I haven’t tested it in awhile but I seem to recall so).

Brent

That didn’t work either. But the anchor jumps to the correct place after pressing another button, I’ve got a confirm and cancel button. After one of those is tapped the anchor jumps to the correct place for some reason.

Perhaps it’s important to note that the button itself is in another display group. And that other display group is inserted into to the scenegroup.

Hmmm… one more little test: try setting (or rather re-setting) the button’s x and y after you do the anchor commands.

No luck either. I tried to place the code before and after I reset the anchor but no luck.

Hi Bram,

I did some testing and came up with a workaround. Most of this is because you set the button to be “text only” so, internally, it only renders the text object (sorry I didn’t notice this initially).

To make different labels align left, you can use the following workaround instead of setting the anchorX to 0. Just add half the button’s width to an x “edge” position (whatever you need). You’ll need to do this both when the button is created and when the label changes.

[lua]

addScreen.categoryBtn = widget.newButton(

    {

        label = “Friend”,

        labelColor = {default={129/255, 202/255, 195/255}, over={1,1,1}},

        font = font.robotoM,

        fontSize = 15,

        onEvent = functions.openCategory,

        emboss = false,

        textOnly = true,

        x = 0,

        y = centerCor.addMainRectY * 1.15,

    }

)

addScreen.categoryBtn.x = addScreen.categoryBtn.width/2 + centerCor.addMainRectX * 1.375

function functions.categoryItemEvent(event)

    if event.phase == “ended” then

        categorySelector = event.target.id

        addScreen.categoryBtn:setLabel(categorySelector:gsub("^%l", string.upper))

        addScreen.categoryBtn.x = addScreen.categoryBtn.width/2 + centerCor.addMainRectX * 1.375

        print("categorySelector = " … categorySelector)

    end

end

[/lua]

Hope this helps!

Brent

Hi Brent,

This did the job. Thank you for your time!

Should I send a bugreport for this or can we just leave it like this?

Kind regards

Bram

Hi Bram,

Good to hear it worked! I wouldn’t necessarily qualify this as a “bug” since, if you use non-text-only buttons and the anchor children approach, buttons can be positioned with anchors. But, if you want to file a report anyway to get it on the radar, feel free.

Brent