Skip to content

Instantly share code, notes, and snippets.

@jasonbradley
Created March 1, 2013 02:53
Show Gist options
  • Save jasonbradley/5062143 to your computer and use it in GitHub Desktop.
Save jasonbradley/5062143 to your computer and use it in GitHub Desktop.
local widget = require "widget"
local scroller = widget.newScrollView{
width = 320,
height = 480,
scrollWidth = 700,
scrollHeight = 1000
}
-- event listener for button widget
local function onButtonEvent( event )
if event.phase == "moved" then
local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )
-- if finger drags button more than 5 pixels, pass focus to scrollView
if dx > 5 or dy > 5 then
scroller:takeFocus( event )
end
elseif event.phase == "release" then
print( "Button pushed." )
end
return true
end
local button = widget.newButton{
label = "My Button"
top = 300,
left = 300,
onEvent = onButtonEvent
}
scroller:insert( button )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment