Keep object inside card borders when moving

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

Keep object inside card borders when moving

Postby raugert » Wed Sep 13, 2017 1:48 am

How do I keep an object from going beyond the stack borders when moving it. I'm sure it's simple and I'm probably missing something. . I just don't want to write a complicated script if there already is an easier way...
raugert
 
Posts: 8
Joined: Thu May 26, 2016 9:30 pm

Re: Keep object inside card borders when moving

Postby dunbarx » Wed Sep 13, 2017 5:27 am

Hi.

Much of what the best solution might be depends on how you "move" stuff. But all will contrive to restrict the edges of a control to the limits of the card window. For example, if you have two buttons on a card, and this in the card script:
Code: Select all
on mouseMove x,y
   repeat with y = 1 to the number of buttons
      if the mouseLoc is within the rect of btn y then set the loc of btn y to item 1 of the mouseLoc & "," &  item 2 of the mouseLoc
   end repeat
end mouseMove


Then whenever you move the cursor into the rect of a button, it will track it. But since the "mouseMove" message is not sent when the cursor goes off the card, half of the button stays within the window. This can be expanded to manage the four edges, of course, leaving the entirety of the button in the card window. This is clunky, since you have to jerk the cursor out of the rect of the currently moving button in order to get to the other one. Or you might release the button with, say, a press of the optionKey. Whatever.

What would you do if you wanted to use the "grab" command?

Craig Newman
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 4793
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Keep object inside card borders when moving

Postby jmburnod » Wed Sep 13, 2017 8:51 am

Hi raugert,
Here is a thread about this
viewtopic.php?f=7&t=29242&hilit=intersect&start=15
and a stack "stMoveControlInsideRect001" here:
download/file.php?id=7938
Best regards
Jean-Marc
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1930
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève

Re: Keep object inside card borders when moving

Postby raugert » Thu Sep 14, 2017 3:33 am

Thank you both for the suggestions. As I am actually moving a group with several buttons and a datagrid within it, Jean-Marc's solution worked best... with some slight adjustments. Much appreciated. Merci .
raugert
 
Posts: 8
Joined: Thu May 26, 2016 9:30 pm


Return to Getting Started with LiveCode - Complete Beginners

Who is online

Users browsing this forum: No registered users and 5 guests