Hello guys and gals, I’ve just merged a new Window...
# compose-desktop
a
Hello guys and gals, I’ve just merged a new Window/Dialog API with some improvements. It’s available in CMP 1.12.0-alpha01+dev4104 Here’s a short guide I wrote. Feedback is welcome.
K 6
👀 5
d
Looked quickly at the API. Being able to auto-size a window is great! Thanks. Do you think this will also fix https://youtrack.jetbrains.com/issue/CMP-8821 ?
a
Unfortunately no. I’d even say the new API makes this problem even harder to solve. The problem there is that the first composition happens before the window has been given a size. In the new API you can size the window according to the content, so the content has to be composed, measured and laid out before the window can be given a size.
It’s just a problem that wasn’t considered when the
LocalWindowInfo
API was written, because it was written for Android, where the window size is typically fixed.
d
It affects adaptive layouts, as
currentAdaptiveWindowSizeClass()
is based on
LocalWindowInfo
on desktop....
What advice would you give me to workaround this? Currently my workaround
if
is not pretty...
a
I understand. It’s fairly easy to check for zero size and handle this case differently, though. There really is no way to know the size of the window when the first composition happens though, so it’s an actual case that needs to be handled, not a bug.
d
So, the
if
I use to not do the first composition is the right way?
a
I don’t know what you do in that
if
. What I think you should be doing is using a “default” or “preferred” window size in the first composition. This will allow sizing the window to the content.
To clarify, it’s a chicken and egg problem. Adaptive layouts want the content to adapt to the size of the window. The window, initially, wants to set its size to the preferred size of the content.
So someone has to be “first”
d
In essence, I do
if (LocalWindowSize != 0,0) { App() }
Otherwise, there is an animation happening when the window appears.
a
In essence, I do
if (LocalWindowSize != 0,0) { App() }
That will make it impossible to size the window to the preferred content size.
d
Otherwise, there is an animation happening when the window appears. Because at first composition, we are COMPACT (because
LocalWindowSize
is 0,0) and at the second composition we are EXPANDED (for instance).
a
So don’t use COMPACT, use the window class you want to be at
and use the new Window sizing API to make that happen
d
I don't know the window size class I need inside the composable tree. That's what
currentAdaptiveWindowInfo
is supposed to do. Are you saying I should completely bypass
compose-adaptive
on desktop?
a
I don’t know the window size class I need inside the composable tree.
Someone should specify that.
1
Again, it’s a chicken and egg problem. Content: Hey, what’s the size class here? Window: What size do you want to be? I’ll size myself to that. Content: I don’t know yet, let me know the size class. Window: I can’t let you know until you tell me your preferred size. ….
d
I don't mind specifying a default size (say 800,600) and on later application start restore the last saved size. But then
LocalWindowSize
is always initialized to 0,0 at first composition anyway.