Changing Component Z-order

I see there are limited methods for modifying Components Z-order (ie: toFront, toBehind (other Component), toBack). Would it be possible to add some more methods that change the Z by customizable amounts? Something like:

Component::sendForwardsBy (int units)
Component::sendBackwardsBy (int units)

Or even in 1 unit increments, like:

Component::stepForwards() //Component moves 1 unit forward in Z
Component::stepBackwards() //Component moves 1 unit backwards in Z

No… I don’t really like that idea. It’d be easy to do, but feels like the wrong approach. It seems to me that the only reason you’d want to move a component backwards or forwards would be because you want to change its position with respect to another component, so you should specify the operation in terms of that other component, not in terms of the z-order index, right?

I disagree. The relation between the Components in my situation relies purely on the Z-order value. There’s no method for getting the Z-order value of a Component, therefore doing what I suggested would be way more straightforward than trying to figure out which Component needs to be relative to the one that needs to be shifted in Z.

Well I figured out what I needed a different way using an OwnedArray containing Component subclass’, and using its order as the reference point for Z-order. Every time I changed the object order (ie: Z-order), I just call toFront() sequentially on the array’s objects.

I’ve also had a few situations where I’ve gone through the same thought-process as you. First I think “ah, I need a method that I can use to set the z-order directly”… but then realised that I’m actually looking at the problem all wrong, and in fact using toFront/toBehind actually makes more sense. That’s why I was sceptical about your original suggestion.

I think that in most cases like this, you’re probably really just trying to sort a list of components into order, and the best way I’ve found is to iterate the list calling toBehind on them. (But don’t use toFront()! That would jiggle them all around and cause unnecessary repaints if they’re already in the correct order!)