I have been trying to understand how Livecode uses layers especially with groups of groups. My app' has a group of seven objects used to describe an image. It uses one of these objects named "polaroid-n" for every image in a folder. There are five images in the folder so there are five polaroid group controls. These five group controls are themselves part of a single group on the card named PhotoViewer. I hope that this is all clear!
The user may drag the polaroids within photoviewer using the grab control and the group scrolls as required. When doing a grab and drag the selected polaroid is hidden by other polaroids with a higher layer number as expected. So I have been attempting to move the selected polaroid to the top layer to keep it in view but there have been problems.
The main problem is that while it is simple to change the layer number it is also very simple to remove the polaroid object from the group by setting a value higher than the groups upper limit. Worse changing the layer back to its original value does not always work as some components of the polaroid group get left behind, orphaned from their parents. ( Note this may have been through my lack of understanding)
I am new to changing layer values so I am probably messing things up but it seems that layers are a little more complex than they first seem. First layer values get changed by LC as controls are added and removed from the card, LC honours the layer order and thats all. Creating a group will change the layer values of controls outside the group as well as those inside the group. This makes sense as LC does not allow unused layer values and a group is based on the layer values of the controls inside it. Or to put it another way a group is just a named range of layer values.
While all of the above seems straight forward things are less clear when these controls are viewed in the IDE's object inspector. In fact it is all quite confusing.
In my application the object inspector shows that the layer of the large group PhotoViewer to be 3. If I select "edit group" and then I select the first polaroid it is shown as layer 2. In terms of the objects on the card this is wrong as the card already has an object with a layer of 2. The real, true, layer value of the polaroid group is 5 and may be found by looking at the plugin revApplicationOverview. Also it may be calculated by adding the two values together e.g. 3 + 2 = 5. Next if I choose to edit the child group polaroid1 then again the components are displayed with incorrect layer values of 1-7 . Again these are not "correct" with the true layer being determined by adding the layer steps i.e. 3+2+1=6 with six being the control numbered 1 in the object inspector. The bottom line is not to rely on the object inspector and use the plugin revApplicationOverview when viewing the layer values of objects
If you are still with me you may remember that at time the polaroid being dragged gets hidden by objects it is being dragged past. The user expects a dragged object to be in front while being dragged. When the layer number is set to a very high value Livecode sets the control to the next highest value in its list and the control will become the front control. However, at this point the control is no longer a member of the group and the group will have adjusted its self reallocating all the layer numbers. When the drag is complete it is necessary to add the control back into the group. This is where the fun begins.
In order to add a control to a group I tried to set its layer value to one that is inside the range of layers of the group. But to do this I had to also use the command RelayerGroupedControls to true. This is the catch as it is global and applies to ALL groups. Thus adding my polaroid group to a group of other groups adds my polaroid to a level. If previously that level was part of a child group then the object I am adding is added to the child and confusion is highly likely. If the main group is only child groups then the objects added this way will always be added to a child group. The only method I have discovered is to have a non group control such as a field in the main group and set my polaroid to the layer level of that field. Doing this ensures that the polaroid control is added to the main group and not a child. However, it is clumsy.
A better method is to use the copy command as it allows LC to do the layer number accounting. I tried this code, before it is executed Polaroid2 is outside the group PhotoViewer:
Code: Select all
on mouseUp pMouseButton
copy group "Polaroid2" of this card to group "PhotoViewer" of this card
set the name of it to "Polaroid2-1"
Delete group "Polaroid2" of this card
end mouseUp