Browse Source

Add tooling improvements

app-api
Nikolay Igotti 3 years ago
parent
commit
bba12da348
  1. 5
      components/Kapp/demo/build.gradle.kts
  2. 33
      components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainMultiFrame.kt
  3. 10
      components/Kapp/demo/src/commonMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt
  4. 30
      components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/Main.kt
  5. 19
      components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewComplex.desktop.kt
  6. 12
      components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/PreviewSimple.desktop.kt
  7. 0
      components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/Kapp.kt
  8. 6
      components/Kapp/library/src/desktopMain/kotlin/org/jetbrains/compose/kapp/App.desktop.kt

5
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"))
}
}

33
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<Int>) {
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")
}
}
}
}

10
components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/MainSimple.kt → 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")

30
components/Kapp/demo/src/desktopMain/kotlin/org/jetbrains/compose/kapp/demo/Main.kt

@ -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")
}
}
}
}
}
}

19
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()

12
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()

0
components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/KApp.kt → components/Kapp/library/src/commonMain/kotlin/org/jetbrains/compose/kapp/Kapp.kt

6
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 {

Loading…
Cancel
Save