Example of DataGrid Form & Scroller

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
RickD
Posts: 31
Joined: Thu Feb 11, 2010 5:47 pm

Example of DataGrid Form & Scroller

Post by RickD » Tue Feb 08, 2011 9:01 pm

Hi All:

I just wanted to share a sample stack that combines a DataGrid Form with a scroller control. I wanted more granular control on how to emulate a native iOS list which the field object did not provide.

I spent several days trying to figure this out and it seems that some of you are going through the same issues. Several of you pointed out to use touch messages instead of mouse messages, which turned out to be true, but the actual implementation of the touch messages took me a while to figure out.

So, for the benefit of all, attached is a simple DataGrid stack that you can build upon and use on your own projects.

Cheers
Attachments
DataGrid Scroller-1.0.0.zip
(9.72 KiB) Downloaded 486 times

SteveHanlan
Posts: 80
Joined: Fri Jul 09, 2010 6:28 pm

Re: Example of DataGrid Form & Scroller

Post by SteveHanlan » Mon Feb 14, 2011 6:43 pm

Rick

Thanks for posting this. It's exactly what I need, however, I am seeing some strange effects ...

I have a DataGrid and and invisible field set up as a group in the middle of the ipad screen with some column headings above.

The scroll works, but it scrolls the original data out of the top of the data area without adding the lower data.
Also, very strangely, when I use the selected line to go to another card, and return to this one, the headings, (which are not in the group), are now down in the middle of the scrolled data area

I appreciate any ideas you may have

thanks

Steve

RickD
Posts: 31
Joined: Thu Feb 11, 2010 5:47 pm

Re: Example of DataGrid Form & Scroller

Post by RickD » Tue Feb 15, 2011 4:53 pm

Hi Steve:

I ran into similar issues while developing my scrollers. things to whatch out for:
1) Make sure your DataGrid and DatGridScroller groups have the "Lock size and position" property checked.
2) Make sure that the dimensions & locations of the DataGrid and the DataGridScroller groups are exactly the same.
3) Make sure that the statement - iphoneControlSet sScrollerId, "contentRect", (0, 0, tWidth, tHeight) has 0,0 at the begining of the rect coordinates.

These were the main issues I found that gave me grief in my scroller implementation.

If you still have issues, fell free to post your stack and I will gladly take a look at it.

Cheers

SteveHanlan
Posts: 80
Joined: Fri Jul 09, 2010 6:28 pm

Re: Example of DataGrid Form & Scroller

Post by SteveHanlan » Wed Feb 16, 2011 3:12 am

Brilliant

I was wrongly assuming that locking position was design only - Doh!

I just now need to get my movement or selection nailed, (if it's just one tap then I need to change the visibility of external controls on the card, otherwise scroll; and at the moment it's not seeing the tap - probably my bad interpretation of your code)

If I can't work it out, I'll give you a shout

Thanks for all the help, (and the great design)

Steve

PS Is there a document that lists the iPhoneControls, (like "scroller"), and their properties?
S.

RickD
Posts: 31
Joined: Thu Feb 11, 2010 5:47 pm

Re: Example of DataGrid Form & Scroller

Post by RickD » Wed Feb 16, 2011 4:36 pm

Hi Steve:

I'm glad you are making progress.

The iOS Release Notes pdf that gets installed with Livecode is where you will find iOS specific documentation.

With regards to differentiating between a "Tap" or a "Scroll", look at the touchEnd script behind the "DataGrid 1" group. The if statement looks at how much scrolling you have done and if it is < 10 pixels it assumes it is a touch and processes the DataGrid selection. You can insert your specific code after the gdmouseDown command.

Hope this helps.

Cheers

SteveHanlan
Posts: 80
Joined: Fri Jul 09, 2010 6:28 pm

Re: Example of DataGrid Form & Scroller

Post by SteveHanlan » Wed Feb 16, 2011 8:11 pm

Thanks Rick

I really should just read the entire release notes (I was just using it for reference).
Now I see all the useful things I should have been using.

Cheers

Steve

witeowl
Posts: 45
Joined: Mon Feb 21, 2011 3:02 am

Re: Example of DataGrid Form & Scroller

Post by witeowl » Sun Mar 20, 2011 7:45 pm

Thank you, thank you, thank you!

I had been poring over the example scroller and the rather lacking -- or scattered, perhaps -- documentation given by livecode and trying to apply it to nearly no avail. Having your example as a comparison helped immensely. My scroller is not quite perfect (is it ever?), but it's at least functional, and I still have some hair left on my head. ;)

I feel like I need an "I'm not worthy!" smiley.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Example of DataGrid Form & Scroller

Post by Jellicle » Mon Mar 21, 2011 1:40 am

Awesome example, Rick, thanks. However while your example stack compiles fine, when I paste your card into my stack and compile (having only changed line one of your opencard script - see below),I can't see any text in the scrolling field at all :)

on opencard
#Setup the Scroller ContectRect
put "600" into tHeight
-- I found I needed to put a value into tHeight otherwise the field didn't display at all.
-- It previously read "put (the dgFormattedHeight of group "DataGrid 1" of me) into tHeight"
put the width of group "DataGridScroll" into tWidth
iphoneControlSet sScrollerId, "contentRect", (0, 0, tWidth, tHeight)
set the height of group "DataGrid 1" to tHeight
set the top of group "DataGrid 1" to the top of grp "DataGridScroll"
end opencard
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Example of DataGrid Form & Scroller

Post by Jellicle » Tue Mar 22, 2011 1:36 pm

Rick, I solved my problem (above) by just moving all my cards to your stack - it all works fine now, and I've even figured out a bit about how it works :D

I have a question, however - how do I use this for a non-list scrolling field? What bits need to change? I just need a longish field (about 5 screenfuls of text in a small font size).

Cheers

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

RickD
Posts: 31
Joined: Thu Feb 11, 2010 5:47 pm

Re: Example of DataGrid Form & Scroller

Post by RickD » Thu Mar 31, 2011 3:46 pm

Hi Gerry:

For a non-list scrolling field you can use a regular text field instead of a datagrid. That should do it.

Cheers

Post Reply