Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround to fix resize issue or switching to another window #282

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.git.luolix.topposegears.valkyrie

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.toSize
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
Expand All @@ -27,18 +34,34 @@ class ValkyrieToolWindow :
toolWindow.apply {
setTitleActions(listOf(RefreshPluginAction()))
addComposePanel {
ValkyrieTheme(
project = project,
currentComponent = this,
) {
CompositionLocalProvider(LocalSnackBar provides rememberSnackbarState()) {
ValkyriePlugin()
Compose17IJSizeBugWorkaround {
ValkyrieTheme(
project = project,
currentComponent = this,
) {
CompositionLocalProvider(LocalSnackBar provides rememberSnackbarState()) {
ValkyriePlugin()
}
}
}
}
}
}

/**
* Workaround until the issue with Compose 1.7 + fillMax__ + IntelliJ Panels is fixed:
* https://youtrack.jetbrains.com/issue/CMP-5856
*/
@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun Compose17IJSizeBugWorkaround(content: @Composable () -> Unit) {
with(LocalDensity.current) {
Box(modifier = Modifier.requiredSize(LocalWindowInfo.current.containerSize.toSize().toDpSize())) {
content()
}
}
}

companion object {
const val ID = "Valkyrie"
}
Expand Down