diff --git a/components/Kapp/demo/build.gradle.kts b/components/Kapp/demo/build.gradle.kts index 2c08b67f80..4bcfdab24d 100644 --- a/components/Kapp/demo/build.gradle.kts +++ b/components/Kapp/demo/build.gradle.kts @@ -12,6 +12,11 @@ kotlin { named("desktopMain") { dependencies { implementation(compose.desktop.currentOs) + + } + } + named("commonMain") { + dependencies { implementation(project(":Kapp:library")) } } diff --git a/components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainMultiFrame.kt b/components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainMultiFrame.kt new file mode 100644 index 0000000000..140cb567da --- /dev/null +++ b/components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainMultiFrame.kt @@ -0,0 +1,33 @@ +package org.jetbrains.compose.kapp.demo + +import androidx.compose.foundation.layout.Column +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.runtime.* + +import org.jetbrains.compose.kapp.* + +fun multiFrameApp() = kapp(title = "Kapp demo") { + var visible = remember { mutableStateOf(5) } + + for (index in 0 .. visible.value) { + Frame { + FrameContent(index, visible) + } + } +} + +@Composable +fun FrameContent(index: Int, visible: MutableState) { + Column { + Text("I am frame $index") + if (index == 0) { + Button(onClick = { visible.value++ }) { + Text("Add") + } + Button(onClick = { if (visible.value > 1) visible.value-- }) { + Text("Remove") + } + } + } +} diff --git a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt b/components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt similarity index 79% rename from components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt rename to components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt index adbc02d403..000e9aef1f 100644 --- a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt +++ b/components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt @@ -1,6 +1,5 @@ -package org.jetbrains.compose.app.demo +package org.jetbrains.compose.kapp.demo -import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.foundation.layout.* import androidx.compose.material.Button import androidx.compose.material.Text @@ -9,13 +8,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import org.jetbrains.compose.kapp.simpleKapp -fun main() = simpleKapp(name = "Kapp demo") { - Content() +fun simpleDemoApp() = simpleKapp(name = "Kapp demo") { + SimpleAppContent() } -@Preview @Composable -fun Content() { +fun SimpleAppContent() { var counter by remember { mutableStateOf(0) } Column { Text("I an app: $counter") diff --git a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/Main.kt b/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/Main.kt deleted file mode 100644 index 8d3f694b7c..0000000000 --- a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/Main.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.jetbrains.compose.kapp.demo - -import androidx.compose.foundation.layout.Column -import androidx.compose.material.Button -import androidx.compose.material.Text -import androidx.compose.runtime.* - -import org.jetbrains.compose.kapp.* - -fun main() = kapp( - title = "App demo" -) { - var visible by remember { mutableStateOf(5) } - - for (index in 0 .. visible) { - Frame { - Column { - Text("I am frame $index") - if (index == 0) { - Button(onClick = { visible++ }) { - Text("Add") - } - Button(onClick = { if (visible > 1) visible-- }) { - Text("Remove") - } - } - } - } - } -} diff --git a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewComplex.desktop.kt b/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewComplex.desktop.kt new file mode 100644 index 0000000000..9a275211ce --- /dev/null +++ b/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewComplex.desktop.kt @@ -0,0 +1,19 @@ +package org.jetbrains.compose.kapp.demo + +import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf + +@Preview +@Composable +fun PreviewFrame0() { + FrameContent(0, mutableStateOf(1)) +} + +@Preview +@Composable +fun PreviewFrame1() { + FrameContent(1, mutableStateOf(2)) +} + +fun main() = multiFrameApp() diff --git a/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewSimple.desktop.kt b/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewSimple.desktop.kt new file mode 100644 index 0000000000..6992606f2a --- /dev/null +++ b/components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewSimple.desktop.kt @@ -0,0 +1,12 @@ +package org.jetbrains.compose.kapp.demo + +import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.runtime.Composable + +@Preview +@Composable +fun PreviewSimple() { + SimpleAppContent() +} + +fun main() = simpleDemoApp() diff --git a/components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/KApp.kt b/components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/Kapp.kt similarity index 100% rename from components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/KApp.kt rename to components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/Kapp.kt diff --git a/components/Kapp/library/src/desktopMain/kotlin/org/jetbrains/compose/kapp/App.desktop.kt b/components/Kapp/library/src/desktopMain/kotlin/org/jetbrains/compose/kapp/App.desktop.kt index c7ac3ad0fc..05938655cb 100644 --- a/components/Kapp/library/src/desktopMain/kotlin/org/jetbrains/compose/kapp/App.desktop.kt +++ b/components/Kapp/library/src/desktopMain/kotlin/org/jetbrains/compose/kapp/App.desktop.kt @@ -11,7 +11,9 @@ import kotlin.system.exitProcess class AppWindowScope : FrameWindowScope { val state = WindowState() override val window: ComposeWindow = ComposeWindow() - fun onClose() {} + fun onClose() { + + } } @Composable @@ -23,7 +25,7 @@ actual fun KAppScope.Frame(content: @Composable () -> Unit) { } } -class AppAppScope : KAppScope, androidx.compose.ui.window.ApplicationScope { +class AppAppScope : KAppScope, ApplicationScope { override fun exitApplication() { println("Exit application") SwingUtilities.invokeLater {