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

Post Reply
raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Keep object inside card borders when moving

Post by 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...
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: Keep object inside card borders when moving

Post by 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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Keep object inside card borders when moving

Post by 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
https://alternatic.ch

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Keep object inside card borders when moving

Post by 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 .
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”