Thread
#compose
    o

    Olivier Patry

    1 year ago
    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
    Halil Ozercan

    Halil Ozercan

    1 year ago
    onGloballyPositioned
    would help you with "position in window". To get the size, there are
    BoxConstraints
    and
    onSizeChanged
    o

    Olivier Patry

    1 year ago
    Thanks I'll start to look at this
    Adam Powell

    Adam Powell

    1 year ago
    You can also look at
    Popup
    which already can anchor to a specific location in a parent layout
    o

    Olivier Patry

    1 year ago
    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
    Adam Powell

    Adam Powell

    1 year ago
    density is a function of dpi.
    density = screenDpi / 160.0
    o

    Olivier Patry

    1 year ago
    I might miss something then…
    LocalDensity.current.density == 1
    So, the DPI is 160 with your suggestion. My computation based on my screen returns 102f and
    AwtToolkit.getDefaultToolkit().screenResolution == 102
    So, I'm confused 🤔
    Adam Powell

    Adam Powell

    1 year ago
    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

    Olivier Patry

    1 year ago
    I'm running on Jetbrains Compose on macOS yes, sorry I thought I told it 😬
    Adam Powell

    Adam Powell

    1 year ago
    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

    Olivier Patry

    1 year ago
    I'll dot 👍
    Adam Powell

    Adam Powell

    1 year ago
    either there or the google issue tracker
    o

    Olivier Patry

    1 year ago