How do I resize a group when using 'grab'?

Hugh Senior h at FlexibleLearning.com
Wed Feb 3 14:35:11 EST 2010


Q: How do I update the dimensions of a group when I 'grab' a control?

'Grab' is a really simple way of moving an object in 'browse' mode: Just
'grab me' in a mouseDown, and the object tracks the mouse until mouseUp (see
the docs).

There is, however, a problem when you 'grab' a control in a group. The
dimensions of a group do not automatically change to fit the repositioned
control, nor is the group's formattedRect updated. This means you can easily
drag an object out of sight to an inaccessible position. This is a 'bad
thing'.

It took me a while, but the trick here is to understand that the
formattedRect of the containing group is only updated when a geometric
property of a control (top, bottom, left, right, width, height etc) is
changed. The following is a simplified group script:


This fails to update the rect of the group...
  on mouseDown
    --| User clicks and drags a control in the group
    grab the target
  end mouseDown

  on mouseMove
    --| Resize the group...
    set the rect of this group to the formattedRect of this group
  end mouseMove


This works...
  on mouseDown
    grab the target
  end mouseDown

  on mouseMove
    --| Force the formattedRect to update...
    set the top of the target to (the top of the target)+1
    set the top of the target to (the top of the target)-1
    --| Now the group can be resized...
    set the rect of this group to the formattedRect of this group
  end mouseMove



Maybe this will help someone searching the archives.

/H




More information about the use-livecode mailing list