Skip to content

Commit

Permalink
Rollback to Compose Foundation SplitPane (#10)
Browse files Browse the repository at this point in the history
(cherry picked from commit 461e2d7)
  • Loading branch information
fscarponi committed Jan 11, 2024
1 parent 07dccb3 commit b77aedc
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 19 deletions.
1 change: 1 addition & 0 deletions packagesearch.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jewel-ui = { module = "org.jetbrains.jewel:jewel-ui", version.ref = "jewel" }
jewel-foundation = { module = "org.jetbrains.jewel:jewel-foundation", version.ref = "jewel" }
jewel-bridge-ij232 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-232" }
jewel-bridge-ij233 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-233" }
compose-desktop-components-splitpane = { module = "org.jetbrains.compose.components:components-splitpane", version.ref = "composeDesktop" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
Expand Down
4 changes: 4 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ val tooling: Configuration by configurations.creating {

dependencies {
implementation(packageSearchCatalog.kotlinx.serialization.core)
implementation(packageSearchCatalog.compose.desktop.components.splitpane){
exclude(group = "org.jetbrains.compose.runtime")
exclude(group = "org.jetbrains.compose.foundation")
}
implementation(packageSearchCatalog.ktor.client.logging)
implementation(packageSearchCatalog.packagesearch.api.models)
implementation(projects.plugin.gradle.base)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ object PackageSearchMetrics {
metrics.trackPadding.calculateEndPadding(LocalLayoutDirection.current)
}

object Splitpane {

val minWidth: Dp = 300.dp
const val firstSplitterPositionPercentage = .20f

const val secondSplittePositionPercentage = .80f
}

object Popups {

val minWidth: Dp = 50.dp
Expand Down Expand Up @@ -54,5 +62,4 @@ object PackageSearchMetrics {
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.jetbrains.packagesearch.plugin.ui

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.intellij.ui.JBColor
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.ui.bridge.packageSearchSplitter
import com.jetbrains.packagesearch.plugin.ui.model.ToolWindowViewModel
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItemEvent
import com.jetbrains.packagesearch.plugin.ui.panels.packages.PackageSearchCentralPanel
import com.jetbrains.packagesearch.plugin.ui.panels.side.PackageSearchInfoPanel
import com.jetbrains.packagesearch.plugin.ui.panels.tree.PackageSearchModulesTree
import org.jetbrains.jewel.ui.component.HorizontalSplitLayout
import org.jetbrains.compose.splitpane.HorizontalSplitPane
import org.jetbrains.jewel.bridge.toComposeColor
import org.jetbrains.jewel.foundation.theme.JewelTheme

@Composable
fun PackageSearchPackagePanel(
Expand All @@ -16,19 +26,31 @@ fun PackageSearchPackagePanel(
onLinkClick: (String) -> Unit,
onPackageEvent: (PackageListItemEvent) -> Unit,
) {
HorizontalSplitLayout(
first = { PackageSearchModulesTree(it, onSelectionModulesSelectionChanged) },
second = {
val toolWindowsViewModel = viewModel<ToolWindowViewModel>()

val splitPaneState by remember { toolWindowsViewModel.firstSplitPaneState }
val innerSplitPaneState by remember { toolWindowsViewModel.secondSplitPaneState }
val splitterColor by remember(JewelTheme.isDark) { mutableStateOf(JBColor.border().toComposeColor()) }

HorizontalSplitPane(Modifier.fillMaxSize(), splitPaneState) {
first(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchModulesTree(Modifier, onSelectionModulesSelectionChanged)
}
packageSearchSplitter(splitterColor)
second {
if (isInfoPanelOpen) {
HorizontalSplitLayout(
modifier = it,
initialDividerPosition = 700.dp,
first = { PackageSearchCentralPanel(it, onLinkClick) },
second = { PackageSearchInfoPanel(it, onLinkClick, onPackageEvent) },
maxRatio = 0.8f
)
} else PackageSearchCentralPanel(it, onLinkClick)
},
minRatio = 0.1f,
)
HorizontalSplitPane(Modifier.fillMaxSize(), innerSplitPaneState) {
first(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchCentralPanel(onLinkClick = onLinkClick)
}
packageSearchSplitter(splitterColor)
second(PackageSearchMetrics.Splitpane.minWidth) {
PackageSearchInfoPanel(onLinkClick = onLinkClick, onPackageEvent = onPackageEvent)
}
}

} else PackageSearchCentralPanel(onLinkClick = onLinkClick)
}
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.jetbrains.packagesearch.plugin.ui.bridge

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -15,8 +21,11 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.intellij.icons.AllIcons
import com.jetbrains.packagesearch.plugin.ui.PackageSearchMetrics
import java.awt.Cursor
import org.jetbrains.compose.splitpane.SplitPaneScope
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.LocalTextStyle
import org.jetbrains.jewel.ui.component.DropdownLink
Expand Down Expand Up @@ -130,3 +139,35 @@ internal fun PackageActionPopup(
}
}
}



internal fun SplitPaneScope.packageSearchSplitter(
splitterColor: Color,
cursor: PointerIcon = PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)),
hidden: Boolean = false,
) {
splitter {
visiblePart {
if (!hidden) {
Box(
modifier = Modifier
.fillMaxHeight()
.width(1.dp)
.background(splitterColor),
)
}
}
handle {
if (!hidden) {
Box(
modifier = Modifier
.fillMaxHeight()
.width(8.dp)
.markAsHandle()
.pointerHoverIcon(cursor),
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.jetbrains.packagesearch.plugin.ui.model

import androidx.compose.runtime.mutableStateOf
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.Service.Level
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.packagesearch.plugin.PackageSearchBundle.message
import com.jetbrains.packagesearch.plugin.core.utils.smartModeFlow
import com.jetbrains.packagesearch.plugin.ui.PackageSearchMetrics
import com.jetbrains.packagesearch.plugin.ui.bridge.openLinkInBrowser
import com.jetbrains.packagesearch.plugin.ui.model.tree.TreeViewModel
import com.jetbrains.packagesearch.plugin.utils.PackageSearchProjectService
Expand All @@ -18,10 +20,25 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import org.jetbrains.compose.splitpane.SplitPaneState

@Service(Level.PROJECT)
class ToolWindowViewModel(project: Project, private val viewModelScope: CoroutineScope) {


val firstSplitPaneState = mutableStateOf(
SplitPaneState(
initialPositionPercentage = PackageSearchMetrics.Splitpane.firstSplitterPositionPercentage,
moveEnabled = true,
)
)
val secondSplitPaneState = mutableStateOf(
SplitPaneState(
initialPositionPercentage = PackageSearchMetrics.Splitpane.secondSplittePositionPercentage,
moveEnabled = true,
)
)

fun openLinkInBrowser(url: String) {
viewModelScope.openLinkInBrowser(url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.jetbrains.jewel.ui.component.VerticalScrollbar

@Composable
fun PackageSearchCentralPanel(
modifier: Modifier,
modifier: Modifier = Modifier,
onLinkClick: (String) -> Unit,
) = Column(modifier) {
val viewModel: PackageListViewModel = viewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.jetbrains.jewel.ui.component.VerticalScrollbar

@Composable
fun PackageSearchInfoPanel(
modifier: Modifier,
modifier: Modifier = Modifier,
onLinkClick: (String) -> Unit,
onPackageEvent: (PackageListItemEvent) -> Unit,
) = Box(modifier) {
Expand Down

0 comments on commit b77aedc

Please sign in to comment.