JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.96k stars 1.16k forks source link

How to properly open a new window or switch between windows from code? #2888

Open paulorb opened 1 year ago

paulorb commented 1 year ago

I am creating a very simple (Desktop) application which consists in two Windows A and B.

A contains a button which when pressed should close the current window and open a new window B B only has a Text (label)

How can I properly manage the window creation/termination directly from the Compose/Window code.

What do you suggest? I saw some articles about Decompose, but I was looking for something more simple (since my application will have few windows)

pablichjenkov commented 1 year ago

I advice you to close this issue and post this type of question in stackoverflow or in the kotlin slack channel. Here, it will just create noise, since this is not an issue but a question on how to use a specific feature of the framework. Back to your question, you can have a list of WindowState in your Application and render the list all the time.

for (windowState in activeWindowsState) {
            key(windowState) {
                YourWindowCustomClass(windowState)
            }
        }

Then on the A button click you add WindowStateB to the list and remove WindowStateA from the windowstate list.

Check this windowState

Here is an example of similar functionality. Although it has some decoration on it: https://github.com/pablichjenkov/templato/blob/3ce5cd172f1bdc115addfefad60e139d61d021c9/component/desktopApp/src/jvmMain/kotlin/com/pablichj/incubator/uistate3/demo/DesktopAppNode.kt#L9

okushnikov commented 3 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.