I'm trying to make a Composable `Box(Modifier.zInd...
# compose-desktop
k
I'm trying to make a Composable
Box(Modifier.zIndex()...
relate to the centre coordinates of that Box. How do I reference the item's own properties in its own Modifiers?? Thanks! 😵
d
relate to the centre coordinates? Could you elaborate?
k
Yes, I want the zIndex to be the Box's own
Canvas.center.x
d
Ah those are two separate dimensions so it made no sense to me at first.
k
Sorry! 😀
d
There are a couple ways to achieve this but it depends on what you're trying to do.
k
I want the display order of objects to be dependent on its lateral placement.
d
You can use
Modifier.onGloballyPositioned {}
to get the coordinates after composition has happened.
k
Oh! OK, that's a new thing for me. I will try that.
So how would I use that value in another Modifier, like the .zIndex?
d
Oh, in that case instead of trying to observe the properties of the item it may be more appropriate to set them yourself. Since you might not want a frame of lag between the zIndex value and the x value.
👌🏻 1
So how would I use that value in another Modifier, like the .zIndex?
Save the value and read it later?
k
Assign it to a variable in the {} ?
d
Sure
k
Hmm. Ok, I'll try that.
Well, I've just discovered
LayoutCoordinates
so I think that might be what I was looking for too? I can reference that directly in the .zIndex.
Hmm. I need more instruction, and I need to sleep! Thanks for the pointers! I'll try some more another day. Cheers!
👍🏼 1
I'm understanding a little more of what you've told me here now that I've had more of a play with Compose! 🤓