scrolling groups programatically?!

Trevor DeVore lists at mangomultimedia.com
Tue Oct 16 16:21:59 EDT 2007


On Oct 16, 2007, at 4:13 PM, Andre Garzia wrote:

> its me again, I am very verbose today. I have a big group whose  
> rect is set
> to a small area of the stack. I can use the scrollbars that rev
> automatically adds to it to scroll the group. Now, if I want to  
> code my way
> to scroll the group, how should I proceed? I have a find function  
> that finds
> the correct group element that should be displayed, I want to  
> scroll so this
> element becomes visible...

Andre,

Here are some general purpose handlers I use to scroll coordinates/ 
rects into view whether in fields or groups. The handler names should  
be self-explanatory.

Hope this helps.

-- 
Trevor DeVore
Blue Mango Learning Systems
www.bluemangolearning.com    -    www.screensteps.com




--> HScroll/Vscroll


command scrollRectVerticallyIntoViewIfOffScreen pControl, pRect, pBuffer
     put the rect of pControl into theMaskRect

     if pBuffer is not an integer then put 0 into pBuffer

     if item 4 of pRect > item 2 of theMaskRect and item 2 of pRect <  
item 2 of theMaskRect then
         ## top is clipped off
         scrollYCoordinateToTopOfControl pControl, item 2 of pRect +  
the vscroll of pControl - item 2 of theMaskRect + pBuffer
     else if item 2 of pRect < item 4 of theMaskRect and item 4 of  
pRect > item 4 of theMaskRect then
         ## bottom is clipped off
         scrollYCoordinateToBottomOfControl pControl, item 4 of pRect  
+ the vscroll of pControl - item 2 of theMaskRect - pBuffer
     else if item 2 of pRect >= item 4 of theMaskRect or item 4 of  
pRect <= item 2 of theMaskRect then
         ## entire rect is clipped off
         if item 2 of pRect >= item 4 of theMaskRect then
             scrollYCoordinateToBottomOfControl pControl, item 4 of  
pRect + the vscroll of pControl - item 2 of theMaskRect - pBuffer
         else
             scrollYCoordinateToTopOfControl pControl, item 2 of  
pRect + the vscroll of pControl - item 2 of theMaskRect + pBuffer
         end if
     end if
end scrollRectVerticallyIntoViewIfOffScreen


command scrollRectHorizontallyIntoViewIfOffScreen pControl, pRect,  
pBuffer
     put the rect of pControl into theMaskRect

     if pBuffer is not an integer then put 0 into pBuffer

     if item 3 of pRect > item 1 of theMaskRect and item 1 of pRect <  
item 1 of theMaskRect then
         ## left is clipped off
         scrollXCoordinateToLeftOfControl pControl, item 1 of pRect +  
the hscroll of pControl - item 1 of theMaskRect + pBuffer
     else if item 1 of pRect < item 3 of theMaskRect and item 3 of  
pRect > item 3 of theMaskRect then
         ## right is clipped off
         scrollXCoordinateToRightOfControl pControl, item 3 of pRect  
+ the hscroll of pControl - item 1 of theMaskRect - pBuffer
     else if item 1 of pRect >= item 3 of theMaskRect or item 3 of  
pRect <= item 1 of theMaskRect then
         ## entire rect is clipped off
         if item 1 of pRect >= item 3 of theMaskRect then
             scrollXCoordinateToRightOfControl pControl, item 3 of  
pRect + the hscroll of pControl - item 1 of theMaskRect - pBuffer
         else
             scrollXCoordinateToLeftOfControl pControl, item 1 of  
pRect + the hscroll of pControl - item 1 of theMaskRect + pBuffer
         end if
     end if
end scrollRectHorizontallyIntoViewIfOffScreen


command scrollCoordinateToCenterOfControl pControl, pCoordinate
     lock screen
     scrollXCoordinateToCenterOfControl pControl, item 1 of pCoordinate
     scrollYCoordinateToCenterOfControl pControl, item 2 of pCoordinate
     unlock screen
end scrollCoordinateToCenterOfControl


--> HSCroll

command scrollXCoordinateToCenterOfControl pControl, pXCordinate
     set the hscroll of pControl to hscrollToPutXCoordinateInCenter 
(pControl, pXCordinate)
end scrollXCoordinateToCenterOfControl


command scrollXCoordinateToLeftOfControl pControl, pXCordinate
     set the hscroll of pControl to hscrollToPutXCoordinateAtLeft 
(pControl, pXCordinate)
end scrollXCoordinateToLeftOfControl


command scrollXCoordinateToRightOfControl pControl, pXCordinate
     set the hscroll of pControl to hscrollToPutXCoordinateAtRight 
(pControl, pXCordinate)
end scrollXCoordinateToRightOfControl


function hscrollToPutXCoordinateInCenter pControl, pXCoordinate
     put the width of pControl into theMaskWidth
     put the formattedwidth of pControl into theMaxWidth
     return max(0, min(pXCoordinate + round(theMaskWidth / 2) -  
theMaskWidth, theMaxWidth))
end hscrollToPutXCoordinateInCenter


function hscrollToPutXCoordinateAtLeft pControl, pXCoordinate
     put the formattedwidth of pControl into theMaxWidth
     return max(0, min(pXCoordinate, theMaxWidth))
end hscrollToPutXCoordinateAtLeft


function hscrollToPutXCoordinateAtRight pControl, pXCoordinate
     put the width of pControl into theMaskWidth
     put the formattedwidth of pControl into theMaxWidth
     return max(0, min(pXCoordinate - theMaskWidth, theMaxWidth))
end hscrollToPutXCoordinateAtRight


--> VScroll

command scrollYCoordinateToCenterOfControl pControl, pYCoordinate
     set the vscroll of pControl to vscrollToPutYCoordinateInCenter 
(pControl, pYCoordinate)
end scrollYCoordinateToCenterOfControl


command scrollYCoordinateToTopOfControl pControl, pYCoordinate
     set the vscroll of pControl to vscrollToPutYCoordinateAtTop 
(pControl, pYCoordinate)
end scrollYCoordinateToTopOfControl


command scrollYCoordinateToBottomOfControl pControl, pYCoordinate
     set the vscroll of pControl to vscrollToPutYCoordinateAtBottom 
(pControl, pYCoordinate)
end scrollYCoordinateToBottomOfControl


function vscrollToPutYCoordinateInCenter pControl, pYCoordinate
     put the height of pControl into theMaskHeight
     put the formattedheight of pControl into theMaxHeight
     return max(0, min(pYCoordinate + round(theMaskHeight / 2) -  
theMaskHeight, theMaxHeight))
end vscrollToPutYCoordinateInCenter


function vscrollToPutYCoordinateAtTop pControl, pYCoordinate
     put the formattedheight of pControl into theMaxHeight
     return max(0, min(pYCoordinate, theMaxHeight))
end vscrollToPutYCoordinateAtTop


function vscrollToPutYCoordinateAtBottom pControl, pYCoordinate
     put the height of pControl into theMaskHeight
     put the formattedheight of pControl into theMaxHeight
     return max(0, min(pYCoordinate - theMaskHeight, theMaxHeight))
end vscrollToPutYCoordinateAtBottom



More information about the use-livecode mailing list