In parallel with a GraphicNode’s parent field, it would be wildly useful to have an indexInParent field, so you could quickly clamber around tree structures without scanning a parent for the index of the node in question.
The indexInParent field would of course just be the node’s index in the parent node’s children.
With this, you would have the effect of sibling pointers like you have in an HTML DOM.
I could use this too. Are you just iterating through nodes and getting the index manually?
These seem to work. The second one makes more sense looking at the layers panel (it is index from top to bottom).
function getItemIndex(item) {
var items = item.parent.children;
var numberOfItems = items.length;
for(var i=0;i<numberOfItems;i++) {
if (items.at(i)==item) {
return i;
}
}
}
function getItemIndexReverse(item) {
var items = item.parent.children;
var numberOfItems = items.length;
for(var i=0;i<numberOfItems;i++) {
if (items.at(i)==item) {
var n = parseInt(numberOfItems) - i;
return n;
}
}
}
I think it was confusing at first because the layers panel has the highest items at the top but the index at the top is 0 while the lowest item location + previous items.
<group>
<layer>I am layered above all other layers but my index is 0</layer>
<layer>My index is 1 but I am shown beneath top layer</layer>
<layer>My index is 2 but I am beneath 1 and 0</layer>
</group>
They layers panel is interesting because you have different metaphors for layers. Are things ordered like a stack of papers?
<stack>
<paper>I am at the top of the layers</paper>
<paper>Item 2</paper>
<paper>Item 3</paper>
</stack>
Where the item at the top of the screen is the top of the pile? Or do you handle it like reading a book from top to bottom where you are adding one layer and the next layer is added after that like elements in a web page?
<container>
<div>I am the first added item to the page.</div>
<div>I am the second added and above first item.</div>
<div>I am the third item added and above previous items.</div>
</container>
For those new to the forums: @Velara and I have had plenty of discussions in the forums about whether API features which are not really necessary, but may add some level of simplification should get added to the APIs. While I am a bit more conservative (“only add to the APIs what’s necessary for developers to achieve what they want to achieve”), @Velara is a lot more open to such simplifying, but not really necessary API features. We’ve had the discussion so many times by now, that it’s basically become a running gag .
On an a bit more serious note:
Personally, I think that this isn’t really necessary, as determining this value is easy to do with the APIs as they are now and there are a lot more pressing matters when it comes to aligning the APIs to what’s possible for a user to do manually. There also aren’t any big performance concerns and if one wants this to be simplified, it’s perfectly reasonable to do this as a library without any need for time of the Adobe team, whose efforts I (personally) appreciate much more when they get devoted to adding more general functionality to the APIs (or perhaps answering to issues on GitHub) .