Bernd, that's nerdy awesome! That is exactly the type of behavior I want, however, I want the user to be able to resize using any of the 8 built-in drag handles. More in-depth detail and an update on my progress is below:
My overall goal is to create a searchable text-field control that can be dragged out from a palette and placed onto a stack to use. I want this control to as closely resemble a built-in livecode control so I feel it is necessary to use the built-in handles to control the size of the objects within the group.
The searchable text field is fully functional (and well encapsulated), so I can copy it and paste it to create another instance. However, to go the final step, I need to allow the developer to do the resizing stuff (without having to edit the group). This is where your help started!
I made some good progress on the resizing stuff today, and I think it will work. Here is my general approach:
1. Create a handler within the searchable text field group to handle the resizeControl message.
2. Within this handler, determine which handle (of which there are eight) the user is dragging to resize the control
3. Select the proper reference point given the handle that is being used. For example, to properly resize the text control when the user drags the right-edge drag handle, the reference needs to be either topLeft or bottomLeft corner of the text field. If the user drags the left-edge drag handle, the reference needs to be either the topRight or the bottomRight corner of the text field.
4. Resize and reposition each one of the controls
This is much easier to "say" I'm going to do then actually "do", because of the lack of visibility into how and when LiveCode decides to resize the group.
So, once this proved harder to do than anticipated, I have spent a lot of my time figuring out when LiveCode does choose to resize the group, and have written my code to make sure it doesn't interfere with LiveCode's built-in behavior. To address the "fighting" that was occurring on the top-edge handle, I have done the following:
Code: Select all
on resizeControl
put the bottomRight of field "theField" into theAnchor
--set the width of field "theField" to (pWidth - the leftMargin of me - the rightMargin of me)
set the lockScreen to true
put the bottomRight of field "theField" into theAnchor
--Calculate the new height of the field "theField"
put the height of me - the topMargin of me - the bottomMargin of me - 25 into theNewHeight
if theNewHeight > 75 then //Don't allow the textfield to get less than 75 in height
--Setting the position of the button first allows LiveCode to properly resize the group
--and then given the new size, I set the new height of my field "theField"
set the top of button "theButton" to the top of me + the topMargin of me
set the height of field "theField" to theNewHeight
set the bottomRight of field "theField" to theAnchor
else
--Need some help here
put the bottomRight of me into it
set the height of me to 120
set the bottomRight of me to it
set the top of button "theButton" to the top of me + the topMargin of me
--set the lockLocation of me to true
end if
set the lockScreen to false
pass resizeControl
end resizeControl
Please note, this is actually not in the resizeControl handler, but rather in the "DoSetSizes" handler. Additionally, this is the code to work for just the top edge handle.
There is still some funny behavior present once you reach the limit (see the "Need some help here" comment above), but otherwise, you get a smooth increase and decrease in the size of the field "theField" when you drag the top-edge handle What I really want to do is lock the position of the group if the user tries to make it a smaller size than allowed, however, this doesn't take effect until after the user stops trying to resize the group. Any ideas of how I can tastefully restrict the size of the group while using the built-in resizing handles?
Cheers,
Tom