newStepper onHold

Hi Guys

i have changed to onPress to onHold.

want to have the buton on pressed to increment & decrement but on hold want to use timerIncrementSpeed to hold down either - + to get to higher/lower numbers quicker… cant seem to get it to work, it works on the on Press adds 1 per touch please help, code below.

local currentNumber = 100

– Handle stepper events
local function onHold( event )
    local phase = event.phase
 
 --update currentNumber
 
    if “increment” == phase then
        currentNumber = currentNumber+ 1
    elseif “decrement” == phase then
        currentNumber = currentNumber- 1
    end
end

 

– Create a default stepper (using widget.setTheme)
local newStepper = widget.newStepper
{
   
 left = display.contentWidth-70,
    top = 280,
    initialValue = 100,
    minimumValue = 0,
    maximumValue = 200,
    timerIncrementSpeed = 1000,
    changeSpeedAtIncrement = 5,
    --onPress = onPress,

    onHold = onHold,

}

Hi @darryl_wainwright,

I investigated this and it appears that our documentation is incorrect. There is just one listening function for this widget (onPress), so please use that. I’ll be correcting the documentation very soon on this point, and apologies for the mistake.

Best regards,

Brent Sorrentino

Thx Brent

No worries, I’ll get to writing my own one with a couple of buttons.

I’ll post below when done if anyone needs.

Hi all

see above couldn’t get the Stepper to work as needed so wrote my own.

Someone must have a way to cut this code down, bat all in all works good enough for me.

Buttons

Buttons.png


–Button Stepper

 

–setup widget
local widget = require( “widget” )

 

local numValue = 0
local strText = display.newText(“fgfdgfdg”, display.contentWidth * 0.5 - 45, (display.contentHeight * 0.5) - 24 , native.systemFont, 24)
strText.text = numValue

 

local pluspressed = false
local minuspressed = false

 

local MaxValue = 50
local MinValue = 0

 

–on button1 press/release------------------------------
local function PlusOnPress(event)
 
  if event.phase == “began” then
   pluspressed = true
  elseif event.phase == “ended” then
   pluspressed = false
  end
  
end

 

button1 = widget.newButton
{
 id = “button1”,
 left = display.contentWidth * 0.5,
 top = display.contentHeight * 0.5,
 defaultFile = “PlusButton.png”,
 overFile = “PlusButtonOver.png”,
 onEvent = PlusOnPress,
}

 

–on button2 press/release------------------------------
local function MinusOnPress(event)
 
  if event.phase == “began” then
   minuspressed = true
  elseif event.phase == “ended” then
   minuspressed = false
  end
  
end

 

button2 = widget.newButton
{
 id = “button2”,
 left = display.contentWidth * 0.5 - 20,
 top = display.contentHeight * 0.5,
 defaultFile = “MinusButton.png”,
 overFile = “MinusButtonOver.png”,
 onEvent = MinusOnPress,
}

 

local function updatevalue()
 --update text
 if pluspressed == true then
  if numValue < MaxValue then
   numValue = numValue + 1
  else
   numValue = MaxValue
  end
 
 else
  numValue = numValue
 end
 
 if minuspressed == true then
  if numValue > MinValue then
   numValue = numValue - 1
  else
   numValue = MinValue
  end
 
 else
  numValue = numValue
 end
 
 strText.text = numValue
 print(numValue)
 
end

 

–on enter & ongoing update values
Runtime:addEventListener( “enterFrame”, updatevalue)

Hi @darryl_wainwright,

I investigated this and it appears that our documentation is incorrect. There is just one listening function for this widget (onPress), so please use that. I’ll be correcting the documentation very soon on this point, and apologies for the mistake.

Best regards,

Brent Sorrentino

Thx Brent

No worries, I’ll get to writing my own one with a couple of buttons.

I’ll post below when done if anyone needs.

Hi all

see above couldn’t get the Stepper to work as needed so wrote my own.

Someone must have a way to cut this code down, bat all in all works good enough for me.

Buttons

Buttons.png


–Button Stepper

 

–setup widget
local widget = require( “widget” )

 

local numValue = 0
local strText = display.newText(“fgfdgfdg”, display.contentWidth * 0.5 - 45, (display.contentHeight * 0.5) - 24 , native.systemFont, 24)
strText.text = numValue

 

local pluspressed = false
local minuspressed = false

 

local MaxValue = 50
local MinValue = 0

 

–on button1 press/release------------------------------
local function PlusOnPress(event)
 
  if event.phase == “began” then
   pluspressed = true
  elseif event.phase == “ended” then
   pluspressed = false
  end
  
end

 

button1 = widget.newButton
{
 id = “button1”,
 left = display.contentWidth * 0.5,
 top = display.contentHeight * 0.5,
 defaultFile = “PlusButton.png”,
 overFile = “PlusButtonOver.png”,
 onEvent = PlusOnPress,
}

 

–on button2 press/release------------------------------
local function MinusOnPress(event)
 
  if event.phase == “began” then
   minuspressed = true
  elseif event.phase == “ended” then
   minuspressed = false
  end
  
end

 

button2 = widget.newButton
{
 id = “button2”,
 left = display.contentWidth * 0.5 - 20,
 top = display.contentHeight * 0.5,
 defaultFile = “MinusButton.png”,
 overFile = “MinusButtonOver.png”,
 onEvent = MinusOnPress,
}

 

local function updatevalue()
 --update text
 if pluspressed == true then
  if numValue < MaxValue then
   numValue = numValue + 1
  else
   numValue = MaxValue
  end
 
 else
  numValue = numValue
 end
 
 if minuspressed == true then
  if numValue > MinValue then
   numValue = numValue - 1
  else
   numValue = MinValue
  end
 
 else
  numValue = numValue
 end
 
 strText.text = numValue
 print(numValue)
 
end

 

–on enter & ongoing update values
Runtime:addEventListener( “enterFrame”, updatevalue)