Datagrid scrollbar

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Datagrid scrollbar

Post by cusingerBUSCw5N » Thu Oct 04, 2012 9:28 pm

I got the datagrid to work - so excited... :D

but the scrollbar in the Android device either doesn't work or it is too small to have fingers work it. :(

I have looked at the various forums and info and find no help. I did find something that worked on an android - but it uses a scrolling field, not a datagrid. Unfortunately, it fails because I don't have a clickline, listbehavior, autoHilite, or scroll - so I don't know how to begin to adjust the code for a datagrid.

It seems that someone else in this world has used a datagrid on an Android and has wanted to scroll down. But I have no idea where to go.

The code that works on an Android - but uses a scrolling field goes like this

Code: Select all

/* version .9, Bernd Niggemann Nov 2010*/

local sTrack = false
local sStart
local sOldY
local sNewY = 0
local sCumulY = 0
local sClickLine
local sMomentum, sDecay, sIncScroll
local sOldScroll
local sFirstMove, sEasing = false

on mouseDown
   if sEasing then 
      put true into sTrack
      put false into sEasing
      put item 2 of the clickLoc into sOldY
      exit mouseDown
   end if
   lock screen
   set the textColor of char 1 to -1 of me to black
   put the clickLine into sClickLine
   set the listbehavior of me to false
   set the autoHilite of me to false
   put the scroll of me into sOldScroll
   unlock screen
   put 0 into sNewY
   put 0 into sCumulY
   put item 2 of the clickLoc into sOldY
  
   -- the time it takes to easeOut
   put 1700 into sDecay
   -- to scip the first mouseMove
   -- to avoid unwanted movement of field
   put true into sFirstMove
   put true into sTrack
end mouseDown

on mouseMove x, y
   if sTrack then
      
      -- this avoids a movement by 
      -- some pixel when selecting
      -- a line
      if sFirstMove then
         put false into sFirstMove
         exit mouseMove
      end if
      
      put y - sOldY into sNewY
      add abs(sNewY) to sCumulY
      put sOldScroll - sNewY into tNewScroll
      set the scroll of me to tNewScroll
      put y into sOldY
      put tNewScroll into sOldScroll

      put abs(sNewY) into sMomentum

      
   end if
end mouseMove

on easeOut
   
   -- sMomentum holds the absolute value of last Y difference
   -- low Y / momentum is probably searching -> exit
   if sMomentum < 4 then exit easeOut
   put true into sEasing
   put the milliseconds into sStart
   
   -- max of stepincrease = sIncScroll is currently 17 pixel, change here
   put  min (abs (sMomentum),17) into sIncScroll
   put sIncScroll into tIncrement
   if sNewY < 0 then put 0 - sIncScroll into sIncScroll
   put sIncScroll into tIncrement
   
   repeat until (the milliseconds - sStart > sDecay) or sTrack or (not sEasing)
      put sOldScroll into tMyScroll
      
      set the scroll of me to tMyScroll - tIncrement
      
      put tMyScroll - tIncrement into sOldScroll
      
      -- wait to let the engine breathe and 
      -- to track changes of sTrack
      wait 2 milliseconds with messages
      
      -- a variation of Scott Rossi's/Richard Herz's algorithm
      put 1 - (min (((the millisecs - sStart)/sDecay),1)^2) into phi
      put round(sIncScroll* phi) into tIncrement
      
   end repeat
   put false into sEasing
end easeOut

on mouseUp
   put false into sTrack
   
   -- sCumulY holds Sum of Ys of mouseMove
   -- a high value is indicative of longer scrolling
   -- low value = more likely a click/selection
   if sCumulY < 6 then 
      
      if sClickLine <> "" then
         put false into sTrack
         put line word 2 of sClickLine of me into tTargetLine
         -- traps for single letter on selected line, in that case exit
         -- if you single letter to be selectable block the following line
         if length (tTargetLine) < 2 then exit mouseUp
         lock screen
         set the listBehavior of me to true
         set the hilitedLine of me to word 2 of  sClickLine
         set the textColor of sClickLine to white
         unlock screen
         -- the message that is sent when selecting a line
         put  line word 2 of sClickLine of me into tSelectedText
         slf_SelectionMade sClickLine, tSelectedText
         
      end if
   else
      easeOut
   end if
   
end mouseUp

on mouseRelease
   mouseUp
end mouseRelease

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid scrollbar

Post by cusingerBUSCw5N » Thu Oct 04, 2012 9:31 pm

To clarify - I actually hoped that I could use a downswipe instead of the scrollbar. The code I have above is for a down swipe.

I couldn't modify it to work with a datagrid. If there is a way to make the scrollbar for the datagrid work (either it works now and is too small to activate - or it doesn't work) - then I'd be satisfied....

Or a down swipe for a datagrid.

Otherwise, my datagrid is rather useless.

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid scrollbar

Post by cusingerBUSCw5N » Thu Oct 04, 2012 11:55 pm

Apparently you can purchase Touch Grid and it will solve the problem. Unfortunately, it seems to create 5 new problems.

I looked at the documentation and unfortunately, the touch grid isn't set up like the datagrid. So there is no row template or row behavior...I don't think that you can have variable heights of the lines... and I don't know how to load multiple fields within the touch grid.

Nor do I see any forum questions or info about this feature......

I have this working on the laptop. How do I get things to scroll down on an android????

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid scrollbar

Post by cusingerBUSCw5N » Fri Oct 05, 2012 1:06 am

I was thinking that my scrolling problem might be because the scrollbar is too narrow. I just learned that you can increase the width of the scrollbar with this code:


set the width of scrollbar "dgScrollbar" of group "mygrid_resources" to 40


Unfortunately, the scrollbar doesn't work on an Android...


I don't want to use the touchgrid because it seems to only allow rows - not formmated areas like datagrids... But a datagrid is rather useless if you can't scroll.

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid scrollbar

Post by cusingerBUSCw5N » Fri Oct 05, 2012 1:42 am

Figured it out. You have to set the colors for the scrollbar to see anything on an Android. (Androids have similar issues with popup message boxes - the color has to be set on those as well).

To do this, Click on the datagrid and select edit group. Then click on the scrollbar and set the colors The thing you move is the background (I would call it the touchpad myself - but they call it a background). What I call the background, Livecode calls a bar. Anyway, they have to be different - otherwise someone doesn't know where to touch.

Likewise...you have to increase the width of the scrollbar (see prior post).

The scroll works - but with a datagrid it's awkward. I'd rather have a touch grid - but can't go that direction if it only has lines of data that can't be formatted.

Anyway, if there is a better solution, please let me know.

Post Reply

Return to “Android Deployment”