Positioning object in a loclocked group (Klaus major-k)
thompsonmichael at shaw.ca
thompsonmichael at shaw.ca
Thu Apr 15 17:06:41 EDT 2021
Klaus:
I am working with LC 9.6.1 Indy on a Dell PC running Windows 10. I first
find a point in the group (in this case the topleft of btn "Button 1"
Adjust it a little and then set the topright of the newly created button
"New Button". This would be the equivalent of your "where whateverX and Y
are definitively inside of that group"
The script below works on my setup:
There is a loclocked group named "Display Group" with an image and a button
"Button 1"
A button labeled "Create and Place a New Button in Group 'Display Group' out
side the group has the following script:
on mouseUp
Lock Screen
Put "Display Group" into tGroupName
Put the width of btn "Button 1" of group tGroupName into tWidth
Put the height of btn "Button 1" of group tGroupName into tHeight
Create button "New Button" in group tGroupName
## Optional resizing of the new button
Set the width btn "New Button" of group tGroupName to tWidth
Set the height of btn "New Button" of group tGroupName to tHeight
## Get a point to locate the new button.
Put the topLeft of btn "Button 1" of group tGroupName into tLocalTL
Subtract 4 from item 1 of tLocalTL
## This tLocalTL is equivalent to your "whateverX,Y"
Set the topRight of btn "New Button" of group tGroupName to tLocalTL
end mouseUp
This also works:
On MouseUp
Put "Display Group" into tGroupName
Put the rect of group tGroupName into tGroupRect
Put the loc of group tGroupName into tGroupLoc
Put 99,232 into tNewBtnLoc
--Put 400,400 into tNewBtnloc ## Try a point outside the rect of the
loclocked group
if tNewBtnLoc is within tGroupRect then
Create button "New Button" in group tGroupName
Set the loc of btn "New Button" to tNewBtnLoc
else Answer "The position of the New button would be outside the bounds of
the locked Group and therefore not visible on screen. Either unlock the
group or choose a new location within the rect of the group ("& tGroupRect
&")"
--Answer "tGroupLoc = "& tGroupLoc &return&"tGroupRect = "&tGroupRect
&return& "tNewBtnLoc = "&tNewBtnLoc
end MouseUp
Michael R Thompson
More information about the use-livecode
mailing list