Hi all, I'm new to LiveCode and was hoping you may be able to point me in the right direction.
I'm trying to make a simple desktop app where the user can drag items from a palate onto a window but the dragged item would need to be a child (contained within) an existing object in the window. For example, the user may drag an image or button on to a rectangle on a calendar (representing a day of the week) but the dropped object should be constrained within the rectangle.
I have been able to get the drag and drop portion working but am unsure how to get the dropped object to stay in the rectangle.
Another issue I'm having is that I will need to iterate through the child objects for any given date but I don't know how I would reference the relationship.
I have looked for examples but have not found anything that would establish a parent/child relationship between the objects.
Any help or example stacks I may have missed would be appreciated.
Constraining a dropped object
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Constraining a dropped object
Hi,
Try this to see if it can be of use: On a new card make two fields and THEN a button. Make each field a little larger than the default size.Separate all the controls. In the card script:
Not sure how you are currently dragging stuff from your palette, but for this experiment, click and hold on the button and drag it to the interior of a field. Release the mouse.
This surely needs a bit of refinement, perhaps lo limit the action to the last control created, or whatever, or to lock out such mobility to certain other controls. But that is the fun part.
Craig Newman
Try this to see if it can be of use: On a new card make two fields and THEN a button. Make each field a little larger than the default size.Separate all the controls. In the card script:
Code: Select all
local tControlMoved
on mouseMove
put the target into tControlMoved
if the mouse is down then set the loc of tControlMoved to the mouseLoc
end mouseMove
on mouseUp
repeat with y = 1 to the number of controls
if the loc of tControlMoved is within the rect of control y then
set the loc of tControlMoved to the loc of control y
end if
end repeat
end mouseUp
This surely needs a bit of refinement, perhaps lo limit the action to the last control created, or whatever, or to lock out such mobility to certain other controls. But that is the fun part.
Craig Newman
-
- Posts: 2
- Joined: Sun Sep 11, 2016 12:51 pm
Re: Constraining a dropped object
Great, thanks Craig, I'll give that a shot.
I also just found the Sodoku game in the sample stacks witch has the basic functionality I'm looking through that code as well.
Thanks again for your help
I also just found the Sodoku game in the sample stacks witch has the basic functionality I'm looking through that code as well.
Thanks again for your help
Re: Constraining a dropped object
Something to play with.
What would happen if you made two buttons instead of one, and did not rename either?
Craig
What would happen if you made two buttons instead of one, and did not rename either?
Craig