Skip to content

Commit

Permalink
Rewrite ThreeWaySplitter as a Recursive MultiSplitter (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonalbert authored May 3, 2024
1 parent c37cad2 commit 661fc13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
35 changes: 14 additions & 21 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/Splitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

}
}

0 comments on commit 661fc13

Please sign in to comment.