Hi Corona Community,
It appears I have stumbled upon bug in widget.newSlider.
In short, the slider “shifts” to the right when its value is set to a number close to 0, which is visually very displeasing (oddly enough, this bug is not symmetric, and the same thing doesn’t happen when the value is near 100).
To help illustrate what I am saying, I have attached screenshots of this bug in action. Please find the files below.
Here’s how to recreate the bug:
-
Set the value of the slider to 0 (slide it to the left)
-
Navigate away from the current scene (in this case, by pressing the red circle button)
-
Reenter the scene which contained the slider. As you can see, the slider has mysteriously (and annoyingly) shifted to the right. As a side note, if you adjust the value to something sufficiently large (like > 20), navigate away and reenter the scene, the slider moves back to its original, correct location.
Here is what I ask you: what is causing this? And, more importantly, how to I fix/prevent this?
Thanks in advance!
________________________________________________________________________________________________
main.lua
local composer = require("composer") composer.gotoScene("home")
home.lua
local composer = require("composer") local scene = composer.newScene() local \_view function scene:create(event) \_view = self.view local button = display.newCircle(340,650,60) button:setFillColor(0,0,1) button:addEventListener("tap", function () composer.gotoScene("slider") end) \_view:insert(button) end scene:addEventListener("create", scene) return scene
slider.lua
local widget = require("widget") local composer = require("composer") local scene = composer.newScene() local \_view local slider1, slider2 local slider1Value, slider2Value function scene:create(event) \_view = self.view local button = display.newCircle(340,650,60) button:setFillColor(1,0,0) button:addEventListener("tap", function () composer.gotoScene("home") end) \_view:insert(button) end function scene:show(event) initSliders() end function initSliders() if (slider1) then slider1:removeSelf() slider1 = nil end slider1 = widget.newSlider { left = 240, top = 475, width = 200, orientation = "horizontal", value = slider1Value or 50, listener = adjustSlider1Value } if (slider2) then slider2:removeSelf() slider2 = nil end slider2 = widget.newSlider { left = 240, top = 525, width = 200, orientation = "horizontal", value = slider2Value or 50, listener = adjustSlider2Value } \_view:insert(slider1) \_view:insert(slider2) end function adjustSlider1Value(event) slider1Value = event.value end function adjustSlider2Value(event) slider2Value = event.value end scene:addEventListener("create", scene) scene:addEventListener("show", scene) return scene