From 0f9735140dac1b71352a1a7fde675b2ae346613b Mon Sep 17 00:00:00 2001 From: Noire Date: Tue, 10 Aug 2021 20:59:08 +0800 Subject: [PATCH] Fix component SplitPane (#1037) --- .../jetbrains/compose/splitpane/demo/Main.kt | 34 +++++------------- .../compose/splitpane/SplitPaneState.kt | 4 --- .../compose/splitpane/DesktopSplitter.kt | 36 ++++--------------- 3 files changed, 16 insertions(+), 58 deletions(-) diff --git a/components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt b/components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt index 3bfbc5d128..4054da5b87 100644 --- a/components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt +++ b/components/SplitPane/demo/src/jvmMain/kotlin/org/jetbrains/compose/splitpane/demo/Main.kt @@ -1,49 +1,33 @@ package org.jetbrains.compose.splitpane.demo import androidx.compose.desktop.DesktopTheme -import androidx.compose.desktop.LocalAppWindow -import androidx.compose.desktop.Window 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.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.composed import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.input.pointer.pointerMoveFilter +import androidx.compose.ui.input.pointer.PointerIcon +import androidx.compose.ui.input.pointer.pointerIcon 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 -private fun Modifier.cursorForHorizontalResize( -): Modifier = composed { - var isHover by remember { mutableStateOf(false) } - - if (isHover) { - LocalAppWindow.current.window.cursor = Cursor(Cursor.E_RESIZE_CURSOR) - } else { - LocalAppWindow.current.window.cursor = Cursor.getDefaultCursor() - } - - pointerMoveFilter( - onEnter = { isHover = true; true }, - onExit = { isHover = false; true } - ) -} +@OptIn(ExperimentalComposeUiApi::class) +private fun Modifier.cursorForHorizontalResize(): Modifier = + pointerIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR))) @OptIn(ExperimentalSplitPaneApi::class) -fun main() = Window( - "SplitPane demo" +fun main() = singleWindowApplication( + title = "SplitPane demo" ) { MaterialTheme { DesktopTheme { diff --git a/components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneState.kt b/components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneState.kt index 53101cca3c..d0ffc8f887 100644 --- a/components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneState.kt +++ b/components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneState.kt @@ -1,9 +1,5 @@ package org.jetbrains.compose.splitpane -import androidx.compose.foundation.interaction.Interaction -import androidx.compose.foundation.interaction.InteractionSource -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.interaction.collectIsDraggedAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue diff --git a/components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitter.kt b/components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitter.kt index 8e7ce35a3f..ff4927c1a0 100644 --- a/components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitter.kt +++ b/components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitter.kt @@ -1,45 +1,23 @@ package org.jetbrains.compose.splitpane -import androidx.compose.desktop.LocalAppWindow import androidx.compose.foundation.background import androidx.compose.foundation.gestures.detectDragGestures -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.* import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.composed import androidx.compose.ui.graphics.Color +import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.consumeAllChanges +import androidx.compose.ui.input.pointer.pointerIcon import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.unit.dp import java.awt.Cursor -private fun Modifier.cursorForHorizontalResize( - isHorizontal: Boolean -): Modifier = composed { - var isHover by remember { mutableStateOf(false) } - - if (isHover) { - LocalAppWindow.current.window.cursor = Cursor( - if (isHorizontal) Cursor.E_RESIZE_CURSOR else Cursor.S_RESIZE_CURSOR - ) - } else { - LocalAppWindow.current.window.cursor = Cursor.getDefaultCursor() - } - pointerMoveFilter( - onEnter = { isHover = true; true }, - onExit = { isHover = false; true } - ) -} +@OptIn(ExperimentalComposeUiApi::class) +private fun Modifier.cursorForHorizontalResize(isHorizontal: Boolean): Modifier = + pointerIcon(PointerIcon(Cursor(if (isHorizontal) Cursor.E_RESIZE_CURSOR else Cursor.S_RESIZE_CURSOR))) @Composable private fun DesktopSplitPaneSeparator(