[WidgetCandy] changing toggleState for a RadioButton causes it position to change (bug?)

When I reset the toggle state of a RadioButton it changes the layout location of this specific radio button. Seems to be a bug?

Notes:

  1. Have tried both these approaches and get the same issue
    (a) _G.GUI.GetHandle(firstRadioButtonName):set(“toggleState”, true)
    and
    (b) myWidgetObject:set(“toggleState”, true)

  2. When I do the above, the setting of the toggle state does work - it’s just the position of the screen of this particular radio button in the set is changes

[import]uid: 140210 topic_id: 28064 reply_id: 328064[/import]

We could not reproduce this. Could you please send us a small, stripped-down sample code to demonstrare this behaviour? [import]uid: 10504 topic_id: 28064 reply_id: 113429[/import]

ok - this seems to demonstrate it well

[code]

– build.settings contain –
– ===================== –
– settings = {

– orientation = {
– default = “landscape”,
– supported =
– {
– “landscape”
– },
– },

– }
– Widget Candy
_G.GUI = require(“widget_candy”)
_G.GUI.LoadTheme(“theme_1”, “themes/theme_1/”)-- LOAD THEME 1

LINE1_NAMES = {“Line1”, “Line2”, “Line3”, “Line4”, “Line5”, “Line6”, “Line7”, “Line8”, “Line9”, “Line10”, “Line11”, “Line12”, “Line13”, “Line14”, “LineA”, “LineB”, “LineC”, “LineD”, “LineE”}
localVar = {}
local secondRadioButtonName
local w, h = display.contentWidth, display.contentHeight
local function resetLineSelection()
– ISSUE HERE: Seems to change the position of the radio button
– ERROR OCCURS HERE - i.e. moves the 2nd radio button to 0,0 on the screen it seems
_G.GUI.GetHandle(secondRadioButtonName):set(“toggleState”, true)
end

– LINE 1 Radio Buttons
local i = 1
local NUM_COLUMNS = 4
for k,v in pairs(LINE1_NAMES) do
local row = math.floor((i-1)/NUM_COLUMNS)
local column = (i - 1) % NUM_COLUMNS
local nameStr = “groupName”…i
if i == 2 then secondRadioButtonName = nameStr end
local currButton = _G.GUI.NewRadiobutton(
{
name = nameStr,
x = 0,
y = 0,
width = w / NUM_COLUMNS,
scale = 1, --_G.GUIScale,
theme = “theme_1”,
caption = v,
fontSize = 20,
textAlign = “right”,
toggleState = i == 1 and true or false,
toggleGroup = (“RadioButtonsGroup”),
group = groupName,
}
)

– scene.view:insert(currButton)
local xPos = 0 + column * w/NUM_COLUMNS
local yPos = 60 + row * 30
currButton.x, currButton.y = xPos, yPos
localVar[i] = currButton

i = i + 1
end

– ERROR OCCURS HERE - i.e. moves the 2nd radio button to 0,0 on the screen it seems
– TOGGLE THIS ON/OFF TO SEE EFFECT OF IT
resetLineSelection()
[/code] [import]uid: 140210 topic_id: 28064 reply_id: 113561[/import]

You try to set a widget’s position directly:

[lua]local xPos = 0 + column * w/NUM_COLUMNS
local yPos = 60 + row * 30
currButton.x, currButton.y = xPos, yPos[/lua]

You should use Widget Candy to position a widget instead:

[lua]local currButton = _G.GUI.NewRadiobutton(
{
name = nameStr,
x = 0 + column * w/NUM_COLUMNS,
y = 60 + row * 30,
width = w / NUM_COLUMNS,
theme = “theme_1”,
caption = v,
textAlign = “right”,
toggleState = i == 1 and true or false,
toggleGroup = (“RadioButtonsGroup”),
group = groupName,
} [/lua]

Widget Candy stores the position of a widget (as well as other properties). When you change any of a widget’s properties, Widget Candy redraws the widget, using the stored properties of that widget. If you change a widget’s position manually by altering it’s .x or .y properties directly, Widget Candy tries to reposition it to the position stored with Widget Candy. Therefore, you should position widgets using the :set method.
[import]uid: 10504 topic_id: 28064 reply_id: 113718[/import]

oh - ok, got it, thanks [import]uid: 140210 topic_id: 28064 reply_id: 113725[/import]