Smooth group scrolling

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
JasonRB
Posts: 3
Joined: Fri Jan 22, 2021 4:12 pm

Smooth group scrolling

Post by JasonRB » Fri Jan 22, 2021 4:25 pm

Hi,
I have an app that includes a scrolling group. When the user scrolls he has to keep his finger on the screen and he can't release until he finish his scrolling.
I want to give the user the option to scroll a bit but fast and let the group keep scrolling after he released his finger.
Is it possible in livecode? If it is, how do I do that?
Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Smooth group scrolling

Post by dunbarx » Fri Jan 22, 2021 7:14 pm

Everything is possible in LC.

You have given me an excuse to stop working and check this out. Thank you

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Smooth group scrolling

Post by dunbarx » Fri Jan 22, 2021 7:43 pm

Well, I have to get back to work. But try this. On a new card make a long scrolling group. Shorten the group so a scrollBar appears. Perhaps the group might have controls that you can see scroll by as you drag. Now make a button as tall as the group. Overlay the button on top of the group scrollbar for now.

There is a problem with this whole idea, and it centers on the fact that a scrollbar does not send messages very well. So I made a kludge, in that you have to do your scrolling in the tall field, not the group. But we can make that look right later on. In the button script:

Code: Select all

global moveLog

on mouseDown
   put "" into moveLog
end mouseDown

on mouseUp
   keepScrolling yTravel,timeTravel
end mouseUp

on mouseMove x,y
   if the mouseLoc is within the rect of me then put y & "," & the ticks & return after moveLog
   if the mouse is down then
      if item 1 of line -2 of moveLog > item 1 of line -1 of moveLog  then set the scroll of grp 1 to the scroll of grp 1 - 1
      else set the scroll of grp 1 to the scroll of grp 1 + 1
   end if
end mouseMove

on keepScrolling ytravel,timeTravel
   put the ticks into startTime
   put item 1 of line -5 of moveLog - item 1 of line -1 of moveLog into yTravel
   put item 2 of line -5 of moveLog - item 2 of line -1 of moveLog into timeTravel
   
   repeat until the mouseClick
      if the ticks mod abs(timeTravel) > 0 then
         switch
            case yTravel < 0
               set the scroll of grp 1 to the scroll of grp 1 + 1
               break
            case yTravel > 0
               set the scroll of grp 1 to the scroll of grp 1 - 1
               break
         end switch
      end if
   end repeat
end keepScrolling
Enter the button, click and drag. Release the button. The scroll will continue until the end is reached, or you click the mouse.

Now this needs a little work. The speed of the scroll in the group should be done better, based on the differences in the variable "moveLog". It is likely that other things need tweaking as well. :wink:

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Smooth group scrolling

Post by FourthWorld » Fri Jan 22, 2021 7:54 pm

Jason, have you scripted a mobile overlay control over the object you want to scroll more smoothly?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Smooth group scrolling

Post by dunbarx » Fri Jan 22, 2021 9:54 pm

Is that what was meant? I read it as the scroll process keeps going after it has been "run" for a short time and the user lets go of the mouse or screen.

Craig
Last edited by dunbarx on Sat Jan 23, 2021 12:54 am, edited 1 time in total.

JasonRB
Posts: 3
Joined: Fri Jan 22, 2021 4:12 pm

Re: Smooth group scrolling

Post by JasonRB » Fri Jan 22, 2021 10:04 pm

Craig,
It works well on my computer :D I only found that rarely when i swipe up it swipes the group down but that's not a big problem.
But when I tried this on my android phone it didn't continue to scroll after i released my finger. I am currently trying to solve this, I will update you when it will work.
Anyways, thank you so much. I appreciate that.

FourthWorld wrote:
Fri Jan 22, 2021 7:54 pm
Jason, have you scripted a mobile overlay control over the object you want to scroll more smoothly?
Hi FourthWorld,
I use the verical scrollbar property of the group. what do you mean by "mobile overlay control"?
thanks

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Smooth group scrolling

Post by FourthWorld » Fri Jan 22, 2021 10:10 pm

A future version of the engine will automatically instantiate the interactive overlay needed for smooth mobile-native scrolling of scrollable objects like fields and groups.

For now, you'll need to script that scroller yourself - takes just a few lines, described here:
https://lessons.livecode.com/m/4069/l/1 ... ll-a-group
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

JasonRB
Posts: 3
Joined: Fri Jan 22, 2021 4:12 pm

Re: Smooth group scrolling

Post by JasonRB » Fri Jan 22, 2021 10:56 pm

Hi FourthWorld,
It works perfectly,
I heard about the custom scrollbar before and I followed the tutorial "custom-controls" (it doesn't let me send a link), but it didn't help me.
The tutorial you sent me was great and now it's working well.

Craig, FourthWorld,
thank you so much. You’re the best!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Smooth group scrolling

Post by FourthWorld » Fri Jan 22, 2021 11:50 pm

Happy to help, Jason. Keep us posted if you run into anything else you could use a hand with.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”