Browse Source

Fix split panel (#2175)

* Fix ignoring modifier when one of the parts is missing

* Fix ignoring density for min size when measuring

* Fix a copypasta for secondMinSizePx
pull/2183/head
Ilya Ryzhenkov 2 years ago committed by GitHub
parent
commit
010576557f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPane.kt
  2. 23
      components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitPane.kt

19
components/SplitPane/library/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPane.kt

@ -28,20 +28,15 @@ fun VerticalSplitPane(
content: SplitPaneScope.() -> Unit
) {
with(SplitPaneScopeImpl(isHorizontal = false, splitPaneState).apply(content)) {
if (firstPlaceableContent != null && secondPlaceableContent != null) {
SplitPane(
modifier = modifier,
isHorizontal = false,
splitPaneState = splitPaneState,
minimalSizesConfiguration = minimalSizes,
first = firstPlaceableContent!!,
second = secondPlaceableContent!!,
first = firstPlaceableContent,
second = secondPlaceableContent,
splitter = splitter
)
} else {
firstPlaceableContent?.invoke()
secondPlaceableContent?.invoke()
}
}
}
@ -63,7 +58,6 @@ fun HorizontalSplitPane(
content: SplitPaneScope.() -> Unit
) {
with(SplitPaneScopeImpl(isHorizontal = true, splitPaneState).apply(content)) {
if (firstPlaceableContent != null && secondPlaceableContent != null) {
SplitPane(
modifier = modifier,
isHorizontal = true,
@ -73,10 +67,6 @@ fun HorizontalSplitPane(
second = secondPlaceableContent!!,
splitter = splitter
)
} else {
firstPlaceableContent?.invoke()
secondPlaceableContent?.invoke()
}
}
}
@ -105,12 +95,13 @@ internal expect fun defaultSplitter(
* @param splitter separator composable, by default [Splitter] is used
* */
@Composable
@OptIn(ExperimentalSplitPaneApi::class)
internal expect fun SplitPane(
modifier: Modifier = Modifier,
isHorizontal: Boolean = true,
splitPaneState: SplitPaneState,
minimalSizesConfiguration: MinimalSizes = MinimalSizes(0.dp, 0.dp),
first: @Composable () -> Unit,
second: @Composable () -> Unit,
first: (@Composable () -> Unit)?,
second: (@Composable () -> Unit)?,
splitter: Splitter
)

23
components/SplitPane/library/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitPane.kt

@ -19,10 +19,16 @@ internal actual fun SplitPane(
isHorizontal: Boolean,
splitPaneState: SplitPaneState,
minimalSizesConfiguration: MinimalSizes,
first: @Composable () -> Unit,
second: @Composable () -> Unit,
first: (@Composable () -> Unit)?,
second: (@Composable () -> Unit)?,
splitter: Splitter
) {
if (first == null || second == null) {
first?.let { Box(modifier) { it() } }
second?.let { Box(modifier) { it() } }
return
}
Layout(
{
Box {
@ -41,12 +47,13 @@ internal actual fun SplitPane(
modifier,
) { measurables, constraints ->
with(minimalSizesConfiguration) {
with(splitPaneState) {
val constrainedMin = constraints.minByDirection(isHorizontal) + firstPlaceableMinimalSize.value
val firstMinSizePx = firstPlaceableMinimalSize.value * density
val secondMinSizePx = secondPlaceableMinimalSize.value * density
with(splitPaneState) {
val constrainedMin = constraints.minByDirection(isHorizontal) + firstMinSizePx
val constrainedMax =
(constraints.maxByDirection(isHorizontal).toFloat() - secondPlaceableMinimalSize.value).let {
(constraints.maxByDirection(isHorizontal).toFloat() - secondMinSizePx).let {
if (it <= 0 || it <= constrainedMin) {
constraints.maxByDirection(isHorizontal).toFloat()
} else {
@ -60,7 +67,7 @@ internal actual fun SplitPane(
if (maxPosition != constrainedMax) {
maxPosition =
if ((firstPlaceableMinimalSize + secondPlaceableMinimalSize).value < constraints.maxByDirection(isHorizontal)) {
if (firstMinSizePx + secondMinSizePx < constraints.maxByDirection(isHorizontal)) {
constrainedMax
} else {
minPosition
@ -68,7 +75,7 @@ internal actual fun SplitPane(
}
val constrainedPosition =
(constraints.maxByDirection(isHorizontal) - (firstPlaceableMinimalSize + secondPlaceableMinimalSize).value).let {
(constraints.maxByDirection(isHorizontal) - (firstMinSizePx + secondMinSizePx)).let {
if (it > 0f) {
(it * positionPercentage).coerceIn(constrainedMin, constrainedMax).roundToInt()
} else {

Loading…
Cancel
Save