Do you any materials to better understand how to r...
# compose
o
Do you any materials to better understand how to reach "low level" related to """""view bounds"""""" in the Compose world? I need 2 distinct things • where is the "view" on the Window (I'd like to anchor a dialog to a view) • what is the size of my "view" (≃`View.getMeasuredWidth()` or the value we get from
View.onSizeChanged()
), what is the DPI of the screen where my "view" is (≃`Context.resources.displayMetrics`) → I'm aware there is no such "view" in the 100% Compose world, what I'd like is the have such thing within the layout for the result of a given composable
h
onGloballyPositioned
would help you with "position in window". To get the size, there are
BoxConstraints
and
onSizeChanged
👍 1
o
Thanks I'll start to look at this
a
You can also look at
Popup
which already can anchor to a specific location in a parent layout
o
I tried
DropdownMenu
(which I needed to something else, but also requiring to be anchored to a toolbar button). I now better understand such concepts and I'll be able to go further 👍
Do you know how one can get the screen DPI? I found
LocalDensity
for font scale and density but nothing for DPI
a
density is a function of dpi.
density = screenDpi / 160.0
o
I might miss something then…
Copy code
LocalDensity.current.density == 1
So, the DPI is 160 with your suggestion. My computation based on my screen returns 102f and
Copy code
AwtToolkit.getDefaultToolkit().screenResolution == 102
So, I'm confused 🤔
a
Are you running on desktop? Sounds like there may be a bug in not propagating density from the host system.
The density system compose uses is inherited from Android where it's a function of screen dpi but rounded into buckets. It's not exact by design, but I would have expected 102 to be rounded into a 120dpi bucket or similar.
o
I'm running on Jetbrains Compose on macOS yes, sorry I thought I told it 😬
a
No worries, I missed it in the thread scrollback
Please file a bug, we should get a standard of compatible buckets worked out for desktop sooner rather than later. A lot of people are probably going to be surprised by the change in existing code behavior for any fix we do
o
I'll dot 👍
a
either there or the google issue tracker
o