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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Scrolling

Post by Quinton B. » Fri Jun 14, 2019 6:15 am

Good day,

I've reviewed this livecode lesson:
http://lessons.livecode.com/m/4071/l/44 ... chitecture

I'm currently using this, however if the user selects a pop-up menu it will keep scrolling to the mouseloc. How do I stop the scrolling if the user selects a pop-up menu?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling

Post by jacque » Fri Jun 14, 2019 4:55 pm

That lesson needs to be updated, it's 7 years out of date and much has changed since then. You no longer need to set the compositor, tilesize, etc. and it isn't necessary to track mouseMove to determine the scroll.

I'm not at my computer right now but maybe someone here can post an example of the newer method. Once you implement that, the problem may go away, or you can block it if you need to.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Scrolling

Post by Quinton B. » Thu Jun 20, 2019 3:47 am

Thanks for the info, does anyone have an updated version?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling

Post by jacque » Sat Jun 22, 2019 7:01 pm

Sorry for the delay, I meant to post sooner but I've been swamped with work and family. Below are the standard library handlers I use for creating and managing native scrollers on mobile. It does not require you to track mouse events, instead LC sends a "scrollerDidScroll" message to the script that created the scroller, with parameters that indicate the current scroll positions.

If the user taps on another control, you shouldn't get that message at all.

Code: Select all

command createScroller pName -- scrolling groups
  -- pName = any valid grp identifier, may work on fields too
  if not isMobile() then exit CreateScroller
  deleteMobileControl pName -- delete any existing
  put (the rect of control pName) into tRect
  put the hScrollBar of control pName into tHScroller
  put the vScrollBar of control pName into tVScroller
  put the hScroll of control pName into tHScroll
  put the vScroll of control pName into tVScroll
  set the hScrollBar of control pName to false -- remove fld scrollbars on mobile
  set the vScrollBar of control pName to false
  set the hScroll of control pName to 0 -- init before creating native scroller
  set the vScroll of control pName to 0
  mobileControlCreate "scroller", pName
  mobileControlSet pName, "rect", tRect
  put  ("0,0," & (the formattedwidth of control pName) & "," & the formattedheight of control pName) into tContentRect
  mobileControlSet pName, "contentRect", tContentRect
  mobileControlSet pName, "hScroll", 0
  mobileControlSet pName, "vScroll", 0
  mobileControlSet pName, "hIndicator", tHScroller
  mobileControlSet pName, "vIndicator", tVScroller
  set the hScroll of control pName to tHScroll -- restore orig scroll
  set the vScroll of control pName to tVScroll
  mobileControlSet pName, "hScroll", tHScroll
  mobileControlSet pName, "vScroll", tVScroll
  mobileControlSet pName, "visible", true
end createScroller

on scrollerDidScroll pHScroll, pVScroll -- sent by LC when user scrolls
  put mobileControlTarget() into tControlID -- short name
  set the defaultstack to the topstack
  try
    set the hscroll of control tControlID to pHScroll
    set the vscroll of control tControlID to pVScroll
  catch tErr
    ANSWER tErr &cr& the executionContexts -- for debugging
  end try
end scrollerDidScroll

command deleteAllMobileControls -- delete all  everywhere
  if not isMobile() then exit deleteAllMobileControls
  repeat for each line l in mobileControls()
    deleteMobileControl l
  end repeat
end deleteAllMobileControls

command deleteMobileControl pName -- deletes a single existing mobile control
  -- pName = any valid grp identifier
  -- native controls should be deleted when no longer needed
  if not isMobile() then exit deleteMobileControl -- do nothing on desktop
  repeat while pName is among the lines of mobileControls()
    mobileControlDelete pName
  end repeat
end deleteMobileControl

function isMobile
  return the environment = "mobile"
end isMobile
The createScroller handler sets the scroll of the group to 0 before setting up the native scroller. This is needed to align the scroller correctly. After setup, the scroll is returned to original value. There appears to be a problem with that in LC 9.x which I will be submitting a report about, but if you're okay with having the initial scroll at 0 (which is usually the case anyway) then it all works fine.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Scrolling

Post by Quinton B. » Thu Jul 04, 2019 8:42 am

Thank you for your help.

What I need to do is figure out how to stop scrolling upon using a control within the scrolling field, then resume upon completion/leave of that control.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling

Post by jacque » Thu Jul 04, 2019 6:28 pm

Controls can't be embedded in a field, so how is the layout arranged exactly? Do you have a control placed on top of the field? Does it move along with the field?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Scrolling

Post by Quinton B. » Fri Jul 05, 2019 8:47 am

The control is within the field and moves with it.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling

Post by jacque » Fri Jul 05, 2019 5:25 pm

I probably wasn't clear. I think you must mean that you have a field, and an option button that sits on top of the field. In that case you must have grouped the field and the button together and are scrolling the group.

The script in the LC lesson doesn't account for this setup. The fix is to not use that script and instead use the one I posted. Pass the name of the group as the parameter. So if the name of your group is "my Group" you'd use: createScroller "my Group". The scrollerDidScroll handler will scroll the group normally but will not do anything when the user is touching the menu button.

Call createScroller in a preOpenCard or openCard handler and when you don't need the scroller any more, remove it with deleteMobileControl "my Group".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Scrolling

Post by Quinton B. » Sun Sep 15, 2019 1:53 am

Lol, still having trouble.

Code: Select all

command createScroller RegisterGroup -- scrolling groups
   -- "RegisterGroup" = any valid grp identifier, may work on fields too
   if not isMobile() then exit CreateScroller
   deleteMobileControl "RegisterGroup" -- delete any existing
   put (the rect of control "RegisterGroup") into tRect
   put the hScrollBar of control "RegisterGroup" into tHScroller
   put the vScrollBar of control "RegisterGroup" into tVScroller
   put the hScroll of control "RegisterGroup" into tHScroll
   put the vScroll of control "RegisterGroup" into tVScroll
   set the hScrollBar of control "RegisterGroup" to false -- remove fld scrollbars on mobile
   set the vScrollBar of control "RegisterGroup" to false
   set the hScroll of control "RegisterGroup" to 0 -- init before creating native scroller
   set the vScroll of control "RegisterGroup" to 0
   mobileControlCreate "scroller", "RegisterGroup"
   mobileControlSet "RegisterGroup", "rect", tRect
   put  ("0,0," & (the formattedwidth of control "RegisterGroup") & "," & the formattedheight of control "RegisterGroup") into tContentRect
   mobileControlSet "RegisterGroup", "contentRect", tContentRect
   mobileControlSet "RegisterGroup", "hScroll", 0
   mobileControlSet "RegisterGroup", "vScroll", 0
   mobileControlSet "RegisterGroup", "hIndicator", tHScroller
   mobileControlSet "RegisterGroup", "vIndicator", tVScroller
   set the hScroll of control "RegisterGroup" to tHScroll -- restore orig scroll
   set the vScroll of control "RegisterGroup" to tVScroll
   mobileControlSet "RegisterGroup", "hScroll", tHScroll
   mobileControlSet "RegisterGroup", "vScroll", tVScroll
   mobileControlSet "RegisterGroup", "visible", true
end createScroller

on scrollerDidScroll pHScroll, pVScroll -- sent by LC when user scrolls
  put mobileControlTarget() into tControlID -- short name
  set the defaultstack to the topstack
  try
     set the hscroll of control tControlID to pHScroll
     set the vscroll of control tControlID to pVScroll
  catch tErr
     ANSWER tErr &cr& the executionContexts -- for debugging
  end try
end scrollerDidScroll

command deleteAllMobileControls -- delete all  everywhere
  if not isMobile() then exit deleteAllMobileControls
  repeat for each line l in mobileControls()
     deleteMobileControl l
  end repeat
end deleteAllMobileControls

command deleteMobileControl RegisterGroup -- deletes a single existing mobile control
  -- "RegisterGroup" = any valid grp identifier
  -- native controls should be deleted when no longer needed
  if not isMobile() then exit deleteMobileControl -- do nothing on desktop
  repeat while "RegisterGroup" is among the lines of mobileControls()
     mobileControlDelete RegisterGroup
  end repeat
end deleteMobileControl

function isMobile
  return the environment = "mobile"
end isMobile

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling

Post by jacque » Sun Sep 15, 2019 3:11 am

What doesn't work exactly? I did notice you've mixed up variables and literals a bit but that should only affect the deleteMobileControl handler in this case.

The handlers were meant to use variables everywhere but if you want to use quoted literals instead then they should be consistent.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Scrolling

Post by Quinton B. » Sun Sep 15, 2019 9:41 am

Lol, it doesn't scroll.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3302
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Scrolling

Post by bn » Sun Sep 15, 2019 11:01 am

Hi Quinton,

in your code

Code: Select all

command createScroller RegisterGroup -- scrolling groups
   -- "RegisterGroup" = any valid grp identifier, may work on fields too
   if not isMobile() then exit CreateScroller
   deleteMobileControl "RegisterGroup" -- delete any existing
   put (the rect of control "RegisterGroup") into tRect
   put the hScrollBar of control "RegisterGroup" into tHScroller
   put the vScrollBar of control "RegisterGroup" into tVScroller
   put the hScroll of control "RegisterGroup" into tHScroll
   put the vScroll of control "RegisterGroup" into tVScroll
you put the parameter RegisterGroup in quotes. That assumes you have a group named "RegisterGroup".
I think what you want is to create a scroller for the group passed as parameter to command createScroller. If you quote "RegisterGroup" this is not the parameter passed but the literal "RegisterGroup".
That is what Jacque is alluding to in her reply except she pointed to only to the deleteMobileControl handler. But you also do it in the createScroller handler.

to call command createScroller you could create the parameter like this

Code: Select all

   put "id" && the id of control "myControl" into tRegisterGroup
   createScroller tRegisterGroup -- invoke createScroller
Try to remove the quotes from RegisterGroup.

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”