2 datagrid problems

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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

2 datagrid problems

Post by cusingerBUSCw5N » Wed Nov 14, 2012 5:23 am

I have a datagrid that brings in a series of topics, short descriptions (id_desc) and images.

Problem 1) I can't seem to get lock screen to work for a datagrid when it loads. I am bringing in images and resizing them to fit the device and it is very distracting to see the process happen. I found one possible solution (http://www.forums.runrev.com/phpBB2/vie ... =9&t=13349) for delaying or caching images - but before doing that I thought I'd check on lock screen. It seems a lot easier.

Problem 2) My datagrid has different heights depending on the height of id_desc. On wider stacks, it works just fine. But on narrow stacks, it's doing weird things - on some it's putting the entire id_desc. On others, it cuts it off after one or two words. The image size that corresponds to it doesn't seem to make any difference. Here is a screenshot

[img]http//www.toolsforbusiness.info/disaster/datagrid_problem.jpg[/img]

Here is my code (forgive me for blatant errors - but I really don't understand rects so I probably have too many.... For some reason it actually works on wider stacks!)

Code: Select all

on LayoutControl pControlRect

 local theFieldRect

    set the right of image "image_resource" of me to item 3 of pControlRect - 5
    set the top of image "image_resource" of me to item 2 of pControlRect + 35
    put the left of image "image_resource" of me into theLeft
    put the rect of image "image_resource" of me into theRectImage
    set the rect of image "image_resource" of me to theRectImage

    set the left of field "label" of me to item 1 of pControlRect + 5
    set the top of field "label" of me to item 2 of pControlRect + 5
    put the rect of field "label" of me into theRect0

    set the rect of field "label" of me to theRect0
         
    set the left of field "id_desc" of me to item 1 of pControlRect + 5
 
set the top  of field "id_desc" of me to the top of field "label" of me + the formattedheight of field "label" of me + 5
put the rect of field "id_desc" of me into theRect1

put theLeft - 5 into item 3 of theRect1
   
put item 2 of theRect1 + the formattedheight of field "id_desc" of me - the bottommargin of field "id_desc" of me into item 4 of theRect1
set the rect of field "id_desc" of me to theRect1 
                                                                                                                                                                                                        
set the top of button "link_address" of me to the top of field "id_desc" of me + the formattedheight of field "id_desc" of me + 5
put the rect of button "link_address" of me into theRect2
set the left of button "link_address" of me to item 1 of pControlRect + 5

   set the bottom of button "email_link" of me to the bottom of button "link_address" of me

put item 4 of theRectImage + 20 into tone
put item 4 of pControlRect into ttwo
put max(tone,ttwo) into tuse

put tuse into item 4 of pControlRect                                                                                                                                                                                                                                                                    
set the rect of graphic "Background" of me to pControlRect

end LayoutControl
What could be causing this inconsistency in handling the field id_desc? Thanks

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: 2 datagrid problems

Post by dave_probertGA6e24 » Wed Nov 14, 2012 7:07 am

Hi,

Couple of things. You forgot the colon after http in the image url :)

Regarding the Lock Screen option - I found it easier to send a large chunk of data in an array to the Datagrid so that it updates in one shot - rather than updating individual lines. If the images are coming from a server or something then they will have to load before they can display unless you delay them (like the other thread does - that works wonderfully BTW) - without the delayed load, each line will show and then wait for the image. That can be very slow especially if there are a lot of lines.

Do the Descriptions contain 'return'/'newline's at the point where they cut off? Are there any other significant characters at those points? It's unlikely that it will randomly split the text. There is usually something that will identify the split point.

Rects are simple a set of 4 coordinates representing the top-left and bottom-right of a rectangle. In you code you should not need to get the rect and then set it again. That is not really achieving anything. The purpose of the layout is to set the changeable parts of the template to suit the size that is given in pControlRect. Usually that is only with a few bits of "set the right of..." type calls. Wherever you are doing a "put the rect of..." followed by a "set the rect of..." without changing the rect values, you can remove to save a bit of clarity and processing power.

Possibly the below might be cleaner - it's only changes in the rect usage. Commented out the unneeded lines (as far as I can tell)

Code: Select all

local theFieldRect
    set the right of image "image_resource" of me to item 3 of pControlRect - 5
    set the top of image "image_resource" of me to item 2 of pControlRect + 35

    put the left of image "image_resource" of me into theLeft
    //put the rect of image "image_resource" of me into theRectImage
    //set the rect of image "image_resource" of me to theRectImage

    set the left of field "label" of me to item 1 of pControlRect + 5
    set the top of field "label" of me to item 2 of pControlRect + 5
    //put the rect of field "label" of me into theRect0
    //set the rect of field "label" of me to theRect0
         
    set the left of field "id_desc" of me to item 1 of pControlRect + 5
    set the top  of field "id_desc" of me to the top of field "label" of me + the formattedheight of field "label" of me + 5

    put the rect of field "id_desc" of me into theRect1
    put theLeft - 5 into item 3 of theRect1
    put item 2 of theRect1 + the formattedheight of field "id_desc" of me - the bottommargin of field "id_desc" of me into item 4 of theRect1
    set the rect of field "id_desc" of me to theRect1 
                                                                                                                                                                                                        
    set the top of button "link_address" of me to the top of field "id_desc" of me + the formattedheight of field "id_desc" of me + 5
    //put the rect of button "link_address" of me into theRect2
    set the left of button "link_address" of me to item 1 of pControlRect + 5
    set the bottom of button "email_link" of me to the bottom of button "link_address" of me

    put the bottom of image "image_resource" + 20 into tone
    put item 4 of pControlRect into ttwo
    put max(tone,ttwo) into tuse

    put tuse into item 4 of pControlRect                                                                                                                                                                                                                                                                    
    set the rect of graphic "Background" of me to pControlRect
end LayoutControl

To help a bit with the templates for datagrids I found that grouping parts that should be together or kept relatively positioned helped. Then you only need to set the positions of the group - not the individual components of the group (e.g. the Let's Go (link_address) and Link (email_link) buttons)

Some of the above may help,

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Post Reply