Browse Source

Components. Native dialogs

components_nativedialogs
Igor Demin 3 years ago
parent
commit
832ebb1ff0
  1. 73
      components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt
  2. 29
      components/nativedialogs/demo/build.gradle.kts
  3. 31
      components/nativedialogs/demo/src/jvmMain/kotlin/org/jetbrains/compose/nativedialogs/demo/Main.kt
  4. 43
      components/nativedialogs/library/build.gradle.kts
  5. 12
      components/nativedialogs/library/src/desktopMain/kotlin/org/jetbrains/compose/nativedialogs/NativeDialogs.kt
  6. 2
      components/settings.gradle.kts

73
components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt

@ -1,73 +0,0 @@
package org.jetbrains.compose.splitpane.demo
import androidx.compose.desktop.DesktopTheme
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
import org.jetbrains.compose.splitpane.ExperimentalSplitPaneApi
import org.jetbrains.compose.splitpane.HorizontalSplitPane
import org.jetbrains.compose.splitpane.VerticalSplitPane
import org.jetbrains.compose.splitpane.rememberSplitPaneState
import java.awt.Cursor
@OptIn(ExperimentalComposeUiApi::class)
private fun Modifier.cursorForHorizontalResize(): Modifier =
pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)))
@OptIn(ExperimentalSplitPaneApi::class)
fun main() = singleWindowApplication(
title = "SplitPane demo"
) {
MaterialTheme {
val splitterState = rememberSplitPaneState()
val hSplitterState = rememberSplitPaneState()
HorizontalSplitPane(
splitPaneState = splitterState
) {
first(20.dp) {
Box(Modifier.background(Color.Red).fillMaxSize())
}
second(50.dp) {
VerticalSplitPane(splitPaneState = hSplitterState) {
first(50.dp) {
Box(Modifier.background(Color.Blue).fillMaxSize())
}
second(20.dp) {
Box(Modifier.background(Color.Green).fillMaxSize())
}
}
}
splitter {
visiblePart {
Box(
Modifier
.width(1.dp)
.fillMaxHeight()
.background(MaterialTheme.colors.background)
)
}
handle {
Box(
Modifier
.markAsHandle()
.cursorForHorizontalResize()
.background(SolidColor(Color.Gray), alpha = 0.50f)
.width(9.dp)
.fillMaxHeight()
)
}
}
}
}
}

29
components/nativedialogs/demo/build.gradle.kts

@ -0,0 +1,29 @@
import org.jetbrains.compose.compose
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
kotlin {
jvm {}
sourceSets {
named("jvmMain") {
dependencies {
implementation(compose.desktop.currentOs)
implementation(project(":nativedialogs:library"))
}
}
}
}
compose.desktop {
application {
mainClass = "org.jetbrains.compose.nativedialogs.demo.MainKt"
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}

31
components/nativedialogs/demo/src/jvmMain/kotlin/org/jetbrains/compose/nativedialogs/demo/Main.kt

@ -0,0 +1,31 @@
package org.jetbrains.compose.nativedialogs.demo
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.window.singleWindowApplication
import org.jetbrains.compose.nativedialogs.pickFolder
fun main() {
singleWindowApplication(
title = "Native Dialogs demo"
) {
var openedFile by remember { mutableStateOf("") }
Column {
Text(openedFile)
Button(onClick = {
pickFolder(System.getProperty("user.home"))?.also {
openedFile = it
}
}) {
Text("File")
}
}
}
}

43
components/nativedialogs/library/build.gradle.kts

@ -0,0 +1,43 @@
import org.jetbrains.compose.compose
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("maven-publish")
}
val osName: String = System.getProperty("os.name")
val os = when {
osName == "Mac OS X" -> "macos"
osName == "Linux" -> "linux"
osName.startsWith("Win") -> "windows"
else -> throw Error("Unknown OS $osName")
}
kotlin {
jvm("desktop")
sourceSets {
named("desktopMain") {
dependencies {
implementation(compose.runtime)
implementation("org.lwjgl:lwjgl:3.2.3")
implementation("org.lwjgl:lwjgl-nfd:3.2.3")
implementation("org.lwjgl:lwjgl:3.2.3:natives-$os") // TODO make a separate publication
implementation("org.lwjgl:lwjgl-nfd:3.2.3:natives-$os") // TODO make a separate publication
}
}
}
}
// TODO it seems that argument isn't applied to the common sourceSet. Figure out why
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
configureMavenPublication(
groupId = "org.jetbrains.compose.components",
artifactId = "components-nativedialogs",
name = "Native Dialogs for Compose JB"
)

12
components/nativedialogs/library/src/desktopMain/kotlin/org/jetbrains/compose/nativedialogs/NativeDialogs.kt

@ -0,0 +1,12 @@
package org.jetbrains.compose.nativedialogs
import org.lwjgl.PointerBuffer
import org.lwjgl.system.MemoryUtil
import org.lwjgl.util.nfd.NativeFileDialog
fun pickFolder(path: String): String? {
val buf = PointerBuffer.allocateDirect(100)
NativeFileDialog.NFD_PickFolder(path, buf)
val mem = buf.get()
return if (mem != MemoryUtil.NULL) MemoryUtil.memUTF8(mem) else null
}

2
components/settings.gradle.kts

@ -1,2 +1,4 @@
include(":SplitPane:library")
include(":SplitPane:demo")
include(":nativedialogs:library")
include(":nativedialogs:demo")
Loading…
Cancel
Save