Keyboard scroll ??

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Keyboard scroll ??

Post by Timothy » Tue Jul 04, 2006 2:27 am

Sorry, I don't know what to call this subject line.

I frequently deal with loonngg vertically scrolling fields. They are clickable index fields, which navigate to cards in a stack with more than 1000 cards. The fields are alphabetized.

So, I'm often scrolling through these fields, looking for a last name, then a first name, typically. When I do it, I think wistfully of Apple dialog boxes with scrolling fields. Like Open and Save as... dialog boxes. If I type the first letter or two of what I'm looking for, the field scrolls down to the first line that matches the letters I've typed.

I hope I made that clear. If I did...

Is there a reasonable easy way to make RR work this way, on designated cards with long scrolling fields?

Thanks,


Tim

Benedikt.Seidl
Posts: 9
Joined: Sat Apr 08, 2006 3:54 pm

Post by Benedikt.Seidl » Tue Jul 04, 2006 4:09 am

set the code of fld to this script:

Code: Select all

on keydown thekey
  lock screen
  put 0 into i
  repeat for each line tline in the text of me
    add 1 to i
    if char 1 of tline is thekey then
      exit repeat
    end if
  end repeat
  put i * the textheight of fld 1
  if the textheight of me is empty then set the textheight of me to 14
  set the scroll of me to ( i * the textheight of me )
  select line i of me
  unlock screen
end keydown
i tested it with exact 1000 lines and it worked very fast.

i hope it is usefull for you

SEIDL.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Tue Jul 04, 2006 4:26 am

Hi Tim,

You can write a keyUp handler in your card script, and react to what the user types. Here's something to get you started:

Code: Select all

--- script local variable declarations
local sFindString
local sResetMsgID

-- engine message handlers
on keyUp pKey
  put pKey after sFindString
  -- use 'send in time' costruct to improve performance
  if "ScrollToFindString" is not in the pendingMessages
  then send "ScrollToFindString" to me in 25 milliseconds
end keyUp

on backspaceKey
  delete char -1 of sFindString
  -- use 'send in time' costruct to improve performance
  if "ScrollToFindString" is not in the pendingMessages
  then send "ScrollToFindString" to me in 25 milliseconds
end backspaceKey

-- custom handlers
on ScrollToFindString
  put return & sFindString into tFindString
  put return & field "Scrolling List Field" into tFieldString
  put lineOffset(tFindString, tFieldString) into tLineOffset
  set the hilitedLine of field "Scrolling List Field" to tLineOffset
  -- give the user some time before resetting the find string
  if sResetMsgID is not empty then
    cancel sResetMsgID
  end if
  -- use 'send in time' construct and save the message ID to cancel
  send "ResetFindString" to me in 4 seconds
  put the result into sResetMsgID
end ScrollToFindString

on ResetFindString
  -- clean up local variables
  put empty into sFindString
  put empty into sResetMsgID
end ResetFindString
The above script worked for me in Rev 2.7.2, but I had to leave some time between the different letters.

Hope thgis helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Jul 04, 2006 9:34 am

Hi Tim,

Why don't you create a field that, on rawKeyUp, filters a list and puts the result into your list field? That is probably easier than scrolling very long list fields.

-- assume cList is a custom prop
-- containing all data
on rawKeyUp
put the cList of this stack into myList
filter myList with (me & "*")
put myList into fld "Your list field"
end rawKeyUp

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Post by Timothy » Wed Jul 05, 2006 4:45 am

Thanks everybody.

Wow! I didn't know about the "Filter" command.

Who knows how many other great features await my discovery.

In any case, this seems very do-able now. Thanks again. :D

Tim
It's better to be happy and rich than poor and sad -- W. C. Fields

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Post by Timothy » Wed Jul 19, 2006 6:55 pm

Suggestions were excellent. I ended up using Jan's script. It worked perfectly right out of the box. All I had to do was type in the field name.

Tim

Post Reply

Return to “Talking LiveCode”