From 661fc1378140949476d1f18c44b653e3edb76d84 Mon Sep 17 00:00:00 2001 From: alonalbert Date: Thu, 2 May 2024 18:10:39 -0700 Subject: [PATCH] Rewrite ThreeWaySplitter as a Recursive MultiSplitter (#24) --- .../kotlin/explorer/KotlinExplorer.kt | 2 +- .../dev/romainguy/kotlin/explorer/Splitter.kt | 35 ++++++++----------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt index 5f0595ce..813967ee 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt @@ -141,7 +141,7 @@ private fun FrameWindowScope.KotlinExplorer( Column( modifier = Modifier.background(JewelTheme.globalColors.paneBackground) ) { - ThreeWaySplitter( + MultiSplitter( modifier = Modifier.weight(1.0f), { SourcePanel(sourceTextArea, explorerState) }, { TextPanel(dexTextArea, explorerState) }, diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Splitter.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Splitter.kt index 677f7d44..0e3dbb72 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Splitter.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Splitter.kt @@ -54,27 +54,20 @@ fun SplitterScope.HorizontalSplitter() { } @Composable -fun ThreeWaySplitter( - modifier: Modifier = Modifier, - panel1: @Composable () -> Unit, - panel2: @Composable () -> Unit, - panel3: @Composable () -> Unit, -) { - HorizontalSplitPane( - modifier = modifier, - splitPaneState = rememberSplitPaneState(initialPositionPercentage = 1.0f / 3) - ) { - first { panel1() } - second { - HorizontalSplitPane( - modifier = modifier, - splitPaneState = rememberSplitPaneState(initialPositionPercentage = 1.0f / 2) - ) { - first { panel2() } - second { panel3() } - splitter { HorizontalSplitter() } - } +fun MultiSplitter(modifier: Modifier = Modifier, vararg panels: @Composable () -> Unit) { + val size = panels.size + if (size == 1) { + panels[0]() + } else { + HorizontalSplitPane( + modifier = modifier, + splitPaneState = rememberSplitPaneState(initialPositionPercentage = 1.0f / size) + ) { + first { panels[0]() } + second { MultiSplitter(modifier = modifier, *panels.drop(1).toTypedArray()) } + splitter { HorizontalSplitter() } } - splitter { HorizontalSplitter() } + } } +