I'd like to scale the local Density for a composab...
# compose
r
I'd like to scale the local Density for a composable so that it fills it's constraints without overflowing, with bounds. I can do this manually using
LocalDensity
and
onGloballyPositioned
, but this seems like it would be very sub-optimal. Is there a way to do this built in, or using a custom layout? I could not find a way to alter the density in a custom layout
a
Relatively speaking the most "correct" way to do this is probably going to involve SubcomposeLayout, but why are you looking to do this? It sounds like there's an X-Y problem here somewhere
r
Possibly, yeah. I'm working (on Desktop) with multiple screen sizes, and want to scale the text of the sidebar (and the spacers, which are all measured in
dp
) so that it's readable on all resolutions, but doesn't overflow to a scrollbar if I can avoid it. Smaller screens can support smaller density values while still being readable, so my approach was to set a min density, then scale up if the screen is big enough.
a
You might poke around a search in this channel for resizable text, using smaller text sizes to make it fit an area is a pretty common use case and I've seen some snippets posted here and there