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: 97
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: 4988
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: 97
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: 4988
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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”