Widgets don't react to trackpad gestures on Mac OS

Thanks for the tips!

But I don’t see a ‘mouse scroll’ event in the API list, just a general ‘mouse’ event and three (primary/secondary/middle)ButtonDown’s. No idea how to determine if it’s a scroll or just moving the cursor around.

If I have to do something that’s not already in the Corona API, I’d rather give up the idea of dealing with it on my own.

This is the code I’m using for mouse wheel scrolling. Works from an undocumented property called .scrollY.

It can be adapted slightly to work on tableViews as well.

[lua]

local middleMouseButtonScrollSpeed = 400 ;

 local mouseScroll = function (event)

      local sv = event.target

      local scrollInfo = {

        dist = event.scrollY, – not officially part of the Corona SDK

        time = event.time-sv.lastTime

    }

    sv.lastTime = event.time;

    – Add it to the scroll info table

    sv.scrollInfoTable[#sv.scrollInfoTable+ 1] = scrollInfo;

    – Take an average from the last 10 (or up to that if table smaller)

    local sampleSize = #sv.scrollInfoTable;

    if sampleSize > 10 then

        sampleSize = 10 ;

    end

    local averageDist = 0 ; local averageTime = 0 ;

    for i=#sv.scrollInfoTable, (#sv.scrollInfoTable+ 1 -sampleSize), - 1 do

        averageDist = averageDist + sv.scrollInfoTable[i] .d ist;

        averageTime = averageTime + sv.scrollInfoTable[i] .t ime;

    end

    averageDist = averageDist / sampleSize;

    averageTime = averageTime / sampleSize;

    local speed = math.round((averageDist/averageTime) * middleMouseButtonScrollSpeed);

    local py, px = sv:getContentPosition();

    local currentPosition = py;

    local newPosition = currentPosition - speed;

    – Don 't allow the scroll content to go off the bottom

    – Would be nice to add “bounce” effect at some point

    if newPosition > 0 then

        newPosition = 0;

    end

    – Or off the top

   local contentHeight = sv._collectorGroup.height;

    if contentHeight > sv.ht then

        if newPosition < (sv._collectorGroup.height-contentHeight) then

            newPosition = sv._collectorGroup.height-contentHeight;

        end

    else

        newPosition = 0;

    end

    – Do the actual scrolling (if scroll speed isn’t zero)

   if speed ~= 0 then

        sv:scrollToPosition {

            x = 0 ,

            y = newPosition,

            time = 0 ,

            onComplete = nil

        }

    end

    – Remove any extra records from the table so we don’t use up any unnecessary memory

    if #sv.scrollInfoTable > sampleSize then

        table.remove(sv.scrollInfoTable, 1);

    end

  end

  – assuming your scrollview is named ‘sv’

  sv:addEventListener( “mouse”, mouseScroll );

  sv.scrollInfoTable = {}

  sv.lastTime = system.getTimer()

[/lua]

Thanks a lot! It doesn’t seem applicable to PickerWheel but I should be able to use TableView instead.

I assume _collectorGroup is another undocumented property :slight_smile:

Just as an FYI…

Any widget property that starts with an _ is meant to be a private member and we may change it in the future with little or no warning. So yes, it’s undocumented on purpose.

Are we likely to change it? Probably not, but it’s still a “use at your own risk” property.

Rob

Look at the mouse event:

https://docs.coronalabs.com/api/event/mouse/index.html

You’re not looking for something literally called mouse scroll.

This code is the mouse listener from a project of mine.

_ WARNING! _  Uses SSK for post, listen, helper functions etc.  I am not going to convert it to basic Corona, but it should be clear enough what it does.  https://roaminggamer.github.io/RGDocs/pages/SSK2/globals/#runtime-improvements

local function onMouse( event ) -- Dispatch scroll events if( event.scrollY \< 0 ) then post( "onMouseScroll", { direction = (common.invertMouse) and "down" or "up", x = event.x, y = event.y } ) elseif( event.scrollY \> 0 ) then post( "onMouseScroll", { direction = (common.invertMouse) and "up" or "down", x = event.x, y = event.y } ) end end; listen( "mouse", onMouse )

Thank you for the example. Your SSK collection looks quite useful and I got carried away browsing it.

I also saw https://docs.coronalabs.com/api/event/axis/index.html, but I couldn’t even make the example code print anything at all. Tried both trackpad and a mouse.

I still hope the Corona team would make the widgets scrollable with mouse/trackpad - even if only in the simulator, as this would make testing much easier.

I wouldn’t hold my breath.  

  1. Unless you filed an official feature request and it gets voted on the idea stops here.  The staff (rightly so) rarely takes forums posts as suggestions for changes.

  2. This is a feature that would require a significant amount of work to implement in the many scroll-able widgets and it would risk breaking existing functionality.

  3. Implementing this yourself for the specific widgets you want and in the way you specifically want them to behave can be coded via Runtime listeners and calls to official widget functions/methods with about 40 lines of code or so.

@roaminggamer is right. We do not use the forums for tracking bugs or feature requests.  We have a tool for feature requests and there is one for this:

http://feedback.coronalabs.com/forums/188732-corona-feature-requests-feedback/suggestions/11517033-mouse-scroll-wheel-with-scrollview-widget

This only has 9 votes (at the time I’m posting this). I don’t know if that means 9 people want it a little bit or 3 people want it a lot. Still it’s not much in the way of saying as a community this is important. You will note it’s marked started because we thought it was a good idea too and shouldn’t be too difficult to implement. But we hit some bugs that we are not comfortable releasing and we put it on the back burner and have moved on to other priorities.

We will probably need to see more community interest in this to get it back on the road map. Please vote it up. That’s what we need from you.

Rob

I wouldn’t hold my breath.  

 

 

Yes, I saw there is such request with a few votes. The existing community seems to be almost exclusively focused on the mobile platforms (iOS and Android). And the new users like me probably don’t know (or are not that involved yet in Corona) about the feature requests.

Anyway, I got some good tips here and if I need more help with this, I’ll probably use your Hitman service.

Just voted, thanks!