I have 3 elements that I switch between (with a `w...
# compose
m
I have 3 elements that I switch between (with a
when
), but I want the layout to keep the same size, so I need the outer container to be the size of the largest element. Is there some solution for this I am missing or would I need to measure all 3 with a
Layout
and then only place one?
z
You would need to compose them all, yes. And probably measure, although if you only need one dimension, querying intrinsics might be cheaper than fully measuring.
m
I did it with a
Layout
and it works correctly, but it recomposes all the elements instead of only the current one, because the layout goes through all of them before selecting one to
.place()
. So it's not as efficient. I only need to measure them once and never again.
z
Well nothing prevents any of the items from changing size while they’re not placed, so for your layout to be correct it would need to keep them composed and measured.
If you don’t care about that, it will make the layout more brittle but you could just use a flag to compose and measure them on the first frame and then remove them on the second frame. But in that case make sure to also implement the intrinsics methods yourself so if a parent queries an intrinsic size you don’t treat that as the main measure pass.
m
Well nothing prevents any of the items from changing size while they’re not placed
Even if they changed size, Compose Desktop does not resize windows when the window content changes, so it wouldn't work anyway. This is only important for the initial window content to be correct size, since that's when the window size is determined.
🤦🏻 1
use a flag to compose and measure them on the first frame and then remove them on the second frame.
Yeah, I could do that 👍