Button:setlabel Messes Up The Offset When Attached To A Button Event

Hi,

I’ve faced this problem while migrating from widget v1.0 to widget v2.0. It was working great with widget v1.0 but now, I have this problem:

When I try to change the button label with an event, setLabel method just messes up with the labelYOffset. 

Actually button:setLabel is the problem. It doesn’t matter if it’s attached to an event or not.

These are screenshots to what happens:

…and this is my code.

 local function onButtonRelease(event) if ( event.phase == "ended" ) then if ( event.target.id == "setSound" ) then if ( setSound:getLabel() == rosetta:getString("soundOn") ) then setSound:setLabel( rosetta:getString("soundOff") ) \_G.isSoundOn = false elseif ( setSound:getLabel() == rosetta:getString("soundOff") ) then setSound:setLabel( rosetta:getString("soundOn") ) \_G.isSoundOn = true end elseif ( event.target.id == "changeLanguage" ) then if ( counter == 6 ) then counter = 1 else counter = counter + 1 end rosetta:setCurrentLanguage("translations/" .. languages[counter]) if ( \_G.isSoundOn ) then setSound:setLabel( rosetta:getString("soundOn") ) else setSound:setLabel( rosetta:getString("soundOff") ) end local currentLang if (languages[counter] == "english") then currentLang = "English" languageID = "en" elseif (languages[counter] == "french") then currentLang = "François" languageID = "fr" elseif (languages[counter] == "german") then currentLang = "Deutsch" languageID = "de" elseif (languages[counter] == "turkish") then currentLang = "Türkçe" languageID = "tr" elseif (languages[counter] == "arabic") then currentLang = "Arabic" languageID = "ar" elseif (languages[counter] == "korean") then currentLang = "Korean" languageID = "ko" end changeLanguage:setLabel( rosetta:getString("changeLanguage") .. currentLang) mainMenu:setLabel( rosetta:getString("mainMenu") ) elseif ( event.target.id == "mainMenu" ) then director:changeScene("screens.mainMenu", "crossfade") end end end

Any help would be appreciated.

Thank you.

Hi,

I’ve faced this problem while migrating from widget v1.0 to widget v2.0. It was working great with widget v1.0 but now, I have this problem:

When I try to change the button label with an event, setLabel method just messes up with the labelYOffset. 

Actually button:setLabel is the problem. It doesn’t matter if it’s attached to an event or not.

These are screenshots to what happens:

attachicon.gifinitialState.png

attachicon.gifmessedUp.png

…and this is my code.

local function onButtonRelease(event) if ( event.phase == “ended” ) then if ( event.target.id == “setSound” ) then if ( setSound:getLabel() == rosetta:getString(“soundOn”) ) then setSound:setLabel( rosetta:getString(“soundOff”) ) _G.isSoundOn = false elseif ( setSound:getLabel() == rosetta:getString(“soundOff”) ) then setSound:setLabel( rosetta:getString(“soundOn”) ) _G.isSoundOn = true end elseif ( event.target.id == “changeLanguage” ) then if ( counter == 6 ) then counter = 1 else counter = counter + 1 end rosetta:setCurrentLanguage(“translations/” … languages[counter]) if ( _G.isSoundOn ) then setSound:setLabel( rosetta:getString(“soundOn”) ) else setSound:setLabel( rosetta:getString(“soundOff”) ) end local currentLang if (languages[counter] == “english”) then currentLang = “English” languageID = “en” elseif (languages[counter] == “french”) then currentLang = “François” languageID = “fr” elseif (languages[counter] == “german”) then currentLang = “Deutsch” languageID = “de” elseif (languages[counter] == “turkish”) then currentLang = “Türkçe” languageID = “tr” elseif (languages[counter] == “arabic”) then currentLang = “Arabic” languageID = “ar” elseif (languages[counter] == “korean”) then currentLang = “Korean” languageID = “ko” end changeLanguage:setLabel( rosetta:getString(“changeLanguage”) … currentLang) mainMenu:setLabel( rosetta:getString(“mainMenu”) ) elseif ( event.target.id == “mainMenu” ) then director:changeScene(“screens.mainMenu”, “crossfade”) end end end

Any help would be appreciated.

Thank you.

Questions:

  1. What version of Corona are you currently using?

  2. Can i see your button constructor please?

I’m using the latest public release now 2013.1076.

Sorry about skipping that information, here it is:

local distanceBetweenY = 35 setSound = widget.newButton{ id = "setSound", defaultFile = "images/menus/buttonInactive.png", -- overFile = "images/menus/buttonOnclick.png", label = rosetta:getString("soundOn"), width = 250, height = 50, labelYOffset = 4, labelColor = { default = { 0, 0, 0 }, over = { 255, 0, 0 } }, font = fontSketch, onEvent = onButtonRelease } if ( \_G.isSoundOn == true ) then setSound:setLabel(rosetta:getString("soundOn")) else setSound:setLabel(rosetta:getString("soundOff")) end setSound.x = display.contentCenterX setSound.y = 110 localGroup:insert(setSound) changeLanguage = widget.newButton{ id = "changeLanguage", defaultFile = "images/menus/buttonInactive.png", -- overFile = "images/menus/buttonOnclick.png", width = 250, height = 50, labelYOffset = 4, label = "", labelColor = { default = { 0, 0, 0 }, over = { 255, 0, 0 } }, font = fontSketch, onEvent = onButtonRelease } local currentLang = rosetta:getCurrentLanguageName() if (currentLang == "translations/english") then currentLang = "English" elseif (currentLang == "translations/french") then currentLang = "François" elseif (currentLang == "translations/german") then currentLang = "Deutsch" elseif (currentLang == "translations/turkish") then currentLang = "Türkçe" elseif (currentLang == "translations/arabic") then currentLang = "Arabic" elseif (currentLang == "translations/korean") then currentLang = "Korean" end changeLanguage:setLabel(rosetta:getString("changeLanguage") .. currentLang) changeLanguage.x = display.contentCenterX changeLanguage.y = setSound.y + setSound.height / 2 + distanceBetweenY localGroup:insert(changeLanguage)

Thank you,

Serkan

Hey Serkan,

Would you be so kind as to whip up a simple test case that exhibits just this issue and [buglink]. Take a peek at this: http://www.coronalabs.com/blog/2013/03/27/wednesday-faq-corona-bug-reports/

to see how test cases should be constructed.

Submitting a bug results in this getting assigned to me to investigate / fix, and having a reproducible example at hand speeds up the process of fixing the issue tenfold.

Cheers.

Hi Danny,

I submitted the bug and provided you with a working example. Hope it’s a good test case and useful for you.

Thanks.

Hi,

Is there a workaround to this problem or should I switch back to Widget v1 until further notice?

No need, I have fixed the issue and the fix will be in your hands shortly

Thank you Danny. Is your fix available on daily build 1079 or will it be available on a newer daily build? I haven’t seen it in the 1079 release notes but maybe I’m missing something.

Either 1080 or 1081 i believe. Thanks

Thank you for the quick fix Danny. This fix really helped me out. Thanks.

Hi (again),

I’m looking for the daily builds and I haven’t seen the fix yet. ( Case: 22445 ) Is there a problem or is the fix included but not noted on the daily builds page?

Thank you,

Serkan

This issue is also affecting me. The text moves away as soon as I do a setLabel()

Okay so I did some testing and I have a workaround. Use this function on your button widget to change the label and it’ll preserve the yOffset.

local function setLabel(obj, text)

    if obj.origLabelY == nil then

        obj.origLabelY = obj._view._label.y

    end

    obj:setLabel(text)

    obj._view._label.y = obj.origLabelY

end

Hi bfintal,

Thanks for the workaround. It is working as intended. Thank you so much.

Hi,

I’ve faced this problem while migrating from widget v1.0 to widget v2.0. It was working great with widget v1.0 but now, I have this problem:

When I try to change the button label with an event, setLabel method just messes up with the labelYOffset. 

Actually button:setLabel is the problem. It doesn’t matter if it’s attached to an event or not.

These are screenshots to what happens:

attachicon.gifinitialState.png

attachicon.gifmessedUp.png

…and this is my code.

local function onButtonRelease(event) if ( event.phase == “ended” ) then if ( event.target.id == “setSound” ) then if ( setSound:getLabel() == rosetta:getString(“soundOn”) ) then setSound:setLabel( rosetta:getString(“soundOff”) ) _G.isSoundOn = false elseif ( setSound:getLabel() == rosetta:getString(“soundOff”) ) then setSound:setLabel( rosetta:getString(“soundOn”) ) _G.isSoundOn = true end elseif ( event.target.id == “changeLanguage” ) then if ( counter == 6 ) then counter = 1 else counter = counter + 1 end rosetta:setCurrentLanguage(“translations/” … languages[counter]) if ( _G.isSoundOn ) then setSound:setLabel( rosetta:getString(“soundOn”) ) else setSound:setLabel( rosetta:getString(“soundOff”) ) end local currentLang if (languages[counter] == “english”) then currentLang = “English” languageID = “en” elseif (languages[counter] == “french”) then currentLang = “François” languageID = “fr” elseif (languages[counter] == “german”) then currentLang = “Deutsch” languageID = “de” elseif (languages[counter] == “turkish”) then currentLang = “Türkçe” languageID = “tr” elseif (languages[counter] == “arabic”) then currentLang = “Arabic” languageID = “ar” elseif (languages[counter] == “korean”) then currentLang = “Korean” languageID = “ko” end changeLanguage:setLabel( rosetta:getString(“changeLanguage”) … currentLang) mainMenu:setLabel( rosetta:getString(“mainMenu”) ) elseif ( event.target.id == “mainMenu” ) then director:changeScene(“screens.mainMenu”, “crossfade”) end end end

Any help would be appreciated.

Thank you.

Questions:

  1. What version of Corona are you currently using?

  2. Can i see your button constructor please?

I’m using the latest public release now 2013.1076.

Sorry about skipping that information, here it is:

local distanceBetweenY = 35 setSound = widget.newButton{ id = "setSound", defaultFile = "images/menus/buttonInactive.png", -- overFile = "images/menus/buttonOnclick.png", label = rosetta:getString("soundOn"), width = 250, height = 50, labelYOffset = 4, labelColor = { default = { 0, 0, 0 }, over = { 255, 0, 0 } }, font = fontSketch, onEvent = onButtonRelease } if ( \_G.isSoundOn == true ) then setSound:setLabel(rosetta:getString("soundOn")) else setSound:setLabel(rosetta:getString("soundOff")) end setSound.x = display.contentCenterX setSound.y = 110 localGroup:insert(setSound) changeLanguage = widget.newButton{ id = "changeLanguage", defaultFile = "images/menus/buttonInactive.png", -- overFile = "images/menus/buttonOnclick.png", width = 250, height = 50, labelYOffset = 4, label = "", labelColor = { default = { 0, 0, 0 }, over = { 255, 0, 0 } }, font = fontSketch, onEvent = onButtonRelease } local currentLang = rosetta:getCurrentLanguageName() if (currentLang == "translations/english") then currentLang = "English" elseif (currentLang == "translations/french") then currentLang = "François" elseif (currentLang == "translations/german") then currentLang = "Deutsch" elseif (currentLang == "translations/turkish") then currentLang = "Türkçe" elseif (currentLang == "translations/arabic") then currentLang = "Arabic" elseif (currentLang == "translations/korean") then currentLang = "Korean" end changeLanguage:setLabel(rosetta:getString("changeLanguage") .. currentLang) changeLanguage.x = display.contentCenterX changeLanguage.y = setSound.y + setSound.height / 2 + distanceBetweenY localGroup:insert(changeLanguage)

Thank you,

Serkan

Hey Serkan,

Would you be so kind as to whip up a simple test case that exhibits just this issue and [buglink]. Take a peek at this: http://www.coronalabs.com/blog/2013/03/27/wednesday-faq-corona-bug-reports/

to see how test cases should be constructed.

Submitting a bug results in this getting assigned to me to investigate / fix, and having a reproducible example at hand speeds up the process of fixing the issue tenfold.

Cheers.

Hi Danny,

I submitted the bug and provided you with a working example. Hope it’s a good test case and useful for you.

Thanks.

Hi,

Is there a workaround to this problem or should I switch back to Widget v1 until further notice?

No need, I have fixed the issue and the fix will be in your hands shortly