Hi, I need some advice on how to migrate some code...
# compose-desktop
m
Hi, I need some advice on how to migrate some code made with the 0.4.x and below Window API to the new API. I have a custom clickable modifier that takes a click event, gets the x and the y of the click event inside the window, and compares it to the LocalAppWindow.current width and height so that it gives me a % value of where it was clicked. I cant find a good way to do this in the new Window Api, as LocalAppWindow was deprecated.
1
i
Replacement of
LocalAppWindow.current
is
window
which you can access inside
Window
function or inside any other function if you pass WindowScope there:
Copy code
Window {
   Box(...clickable { window.width }
   foo()
}

@Composable
fun WindowScope.foo() {
   Box(...clickable { window.width }
}
m
Is there some kind of way I can get that when I am deep in a function tree? Or should I make a CompositonLocal of it myself
i
Yes, you can make your own composition local, there is no built-in one in the new API
👍 1