It’s not really a bug, per se, but it kind of is… I was unsure where to place this.
In the event handling functionality for ui.lua’s “newButton”, there are three ways to currently get event feedback. Asking for onPress, onRelease, or wanting to get all (or most) of the events with onEvent.
The catch is… onEvent only gives you “press” and “release”. What we really need here is to fill this out a little bit so those using onEvent will get all the info they need. What I did was added a few lines of code to ui.lua as documented below. This gives the additional events “moved_in”, “moved_out”, and “cancelled” (I’d also point out that “cancelled” is misspelled in your code and should be corrected ASAP to break as few apps as possible, I’ll open a bug for this).
In ui.lua : newButtonHandler : in the block for ‘if “moved” == phase then’ :
[code]
if “moved” == phase then
if over then
-- The rollover image should only be visible while the finger is within button's stageBounds
default.isVisible = not isWithinBounds
over.isVisible = isWithinBounds
end
-- SWP: Added so if we want to do special things on press/move/end, then we can
if onEvent then
if (isWithinBounds) then
buttonEvent.phase = "moved\_in";
else
buttonEvent.phase = "moved\_out";
end
result = onEvent( buttonEvent )
end
the above will send “moved_in” or “moved_out” events which let us do special things for when the user has pressed down, but moved out or into the button bounding area.
In ui.lua : newButtonHandler : in the block for ‘elseif “ended” == phase or “cancelled” == phase then’ :
[code]
elseif “ended” == phase or “cancelled” == phase then
if over then
default.isVisible = true
over.isVisible = false
end
-- Only consider this a "click" if the user lifts their finger inside button's stageBounds
if isWithinBounds then
if onEvent then
buttonEvent.phase = "release"
result = onEvent( buttonEvent )
elseif onRelease then
result = onRelease( event )
end
-- SWP: Added so if we want to do special things on press/move/end, then we can
else
if onEvent then
buttonEvent.phase = "cancelled"
result = onEvent( buttonEvent )
end
end
the above will send a “cancelled” (this is a type-o, but I felt consistency wins out) event allowing us to clean up any messes if the user does not actually release the button.
Basically, I needed the ability to change my button’s label’s text color when the button is in a pressed state. This particular capability should be handled automatically within the button object, but giving us the ability to extend functionality is always a good thing. If your concern was event flooding by the moves, then offer a flag to turn the move events “on” for our event handler.
Thanks,
Scott
P.S. Something really screwy with your code tag in your forums. Looks like the first lua comment “–” will kick it out of code mode. [import]uid: 5659 topic_id: 708 reply_id: 300708[/import]
