I wanted to get raw values out of my slider instead of the integers from 0 to 100 it normally gives, so I went in to widget_slider.lua and took out the math.round calls on self._currentPercent.
Now I get floating point values from 0 to 100, then I scale them however I want. But it seems like it would be better if scaling were an option, and you could get either straight floating point values or scaled integer values. My application requires integers from 0 to 300, for example, so I still use math.round on the floating values I receive, but now I have 3 times as much resolution in the slider.
I tried doing it the right way, adding options to pass the scale and the rounding switch, but for some reason none of the values actually got passed in my options. Here’s my code:
function newMySlider( options ) local theme = \_getTheme( "slider", options ) local \_slider = require( "controls.widget\_slider" ) -- my modded lua file return \_slider.new( options, theme ) end
playbackSlider = newMySlider{ top = display.contentHeight - 60\*screenscale, left = buttonWidth+70, width = display.contentWidth - 2\*(buttonWidth + 70), frameHeight = 15\*screenscale, framewidth = 15\*screenscale, handleHeight = 50\*screenscale, handleWidth = 50\*screenscale, value = 0, listener = playbackListener, sheet = sliderSheet, leftFrame = 2, middleFrame = 4, rightFrame = 3, fillFrame = 5, handleFrame = 1, scale = trackingBuffer.max }
As you can see, I added scale to the options list. Now here are my mods in widget_slider.lua:
opt.rounding = customOptions.rounding or true opt.scale = customOptions.scale or 100 local value = self.\_currentPercent\*opt.scale/100 if opt.rounding then value = mRound(value) end local newEvent = { name = event.name, phase = event.phase, value = value, target = self, }
I’m pretty sure this would work! Except my added options are not being passed in with customOptions, so it just does the default behavior.
Currently I can make it work the way I want just by removing mRound altogether, but doing it the other way might be a worthwhile change to make in the standard code. It defaults to the standard model if people don’t pass rounding or scale.