Keep object inside card borders when moving
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Keep object inside card borders when moving
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
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0
-
- 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
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:
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
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
What would you do if you wanted to use the "grab" command?
Craig Newman
-
- 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
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
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
Re: Keep object inside card borders when moving
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
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0