You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.2 KiB
76 lines
2.2 KiB
package org.jetbrains.compose.splitpane |
|
|
|
import androidx.compose.foundation.background |
|
import androidx.compose.foundation.gestures.detectDragGestures |
|
import androidx.compose.foundation.layout.* |
|
import androidx.compose.material.MaterialTheme |
|
import androidx.compose.runtime.Composable |
|
import androidx.compose.ui.ExperimentalComposeUiApi |
|
import androidx.compose.ui.Modifier |
|
import androidx.compose.ui.graphics.Color |
|
import androidx.compose.ui.input.pointer.* |
|
import androidx.compose.ui.unit.dp |
|
import java.awt.Cursor |
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
private fun Modifier.cursorForHorizontalResize(isHorizontal: Boolean): Modifier = |
|
pointerHoverIcon(PointerIcon(Cursor(if (isHorizontal) Cursor.E_RESIZE_CURSOR else Cursor.S_RESIZE_CURSOR))) |
|
|
|
@Composable |
|
private fun DesktopSplitPaneSeparator( |
|
isHorizontal: Boolean, |
|
color: Color = MaterialTheme.colors.background |
|
) = Box( |
|
Modifier |
|
.run { |
|
if (isHorizontal) { |
|
this.width(1.dp) |
|
.fillMaxHeight() |
|
} else { |
|
this.height(1.dp) |
|
.fillMaxWidth() |
|
} |
|
} |
|
.background(color) |
|
) |
|
|
|
@OptIn(ExperimentalSplitPaneApi::class) |
|
@Composable |
|
private fun DesktopHandle( |
|
isHorizontal: Boolean, |
|
splitPaneState: SplitPaneState |
|
) = Box( |
|
Modifier |
|
.pointerInput(splitPaneState) { |
|
detectDragGestures { change, _ -> |
|
change.consumeAllChanges() |
|
splitPaneState.dispatchRawMovement( |
|
if (isHorizontal) change.position.x else change.position.y |
|
) |
|
} |
|
} |
|
.cursorForHorizontalResize(isHorizontal) |
|
.run { |
|
if (isHorizontal) { |
|
this.width(8.dp) |
|
.fillMaxHeight() |
|
} else { |
|
this.height(8.dp) |
|
.fillMaxWidth() |
|
} |
|
} |
|
) |
|
|
|
@OptIn(ExperimentalSplitPaneApi::class) |
|
internal actual fun defaultSplitter( |
|
isHorizontal: Boolean, |
|
splitPaneState: SplitPaneState |
|
): Splitter = Splitter( |
|
measuredPart = { |
|
DesktopSplitPaneSeparator(isHorizontal) |
|
}, |
|
handlePart = { |
|
DesktopHandle(isHorizontal, splitPaneState) |
|
} |
|
) |
|
|
|
|