mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
🔀 Fix icon don't be scaled after density changed (#239)
* Fix icon don't be scaled after density changed * Fix comments GitOrigin-RevId: 1b8f1854e5d8262d24d359a886a4a1d0d95dd1ad
This commit is contained in:
committed by
intellij-monorepo-bot
parent
67402e13fb
commit
9e5c1ff64f
@@ -44,13 +44,17 @@ public final class org/jetbrains/jewel/bridge/JewelBridgeException$KeysNotFoundE
|
||||
public fun <init> (Ljava/util/List;Ljava/lang/String;)V
|
||||
}
|
||||
|
||||
public final class org/jetbrains/jewel/bridge/JewelComposePanelKt {
|
||||
public static final fun JewelComposePanel (Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent;
|
||||
public static final fun getLocalComponent ()Landroidx/compose/runtime/ProvidableCompositionLocal;
|
||||
}
|
||||
|
||||
public final class org/jetbrains/jewel/bridge/ToolWindowExtensionsKt {
|
||||
public static final fun addComposeTab (Lcom/intellij/openapi/wm/ToolWindow;Ljava/lang/String;ZZLkotlin/jvm/functions/Function3;)V
|
||||
public static synthetic fun addComposeTab$default (Lcom/intellij/openapi/wm/ToolWindow;Ljava/lang/String;ZZLkotlin/jvm/functions/Function3;ILjava/lang/Object;)V
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/jewel/bridge/ToolWindowScope {
|
||||
public abstract fun getPanel ()Landroidx/compose/ui/awt/ComposePanel;
|
||||
public abstract fun getToolWindow ()Lcom/intellij/openapi/wm/ToolWindow;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.jetbrains.skiko.awt.font.AwtFontManager
|
||||
import org.jetbrains.skiko.toSkikoTypefaceOrNull
|
||||
import java.awt.Dimension
|
||||
import java.awt.Font
|
||||
import java.awt.GraphicsEnvironment
|
||||
import java.awt.Insets
|
||||
import javax.swing.UIManager
|
||||
|
||||
@@ -222,13 +221,9 @@ internal operator fun TextUnit.plus(delta: Float): TextUnit =
|
||||
else -> this
|
||||
}
|
||||
|
||||
internal fun retrieveDensity(): Density {
|
||||
internal fun retrieveIdeaDensity(sourceDensity: Density): Density {
|
||||
val ideaScale = UISettingsUtils.getInstance().currentIdeScale
|
||||
val scale = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.defaultScreenDevice
|
||||
.defaultConfiguration
|
||||
.defaultTransform
|
||||
.scaleX * ideaScale
|
||||
val scale = ideaScale * sourceDensity.density
|
||||
|
||||
return Density(scale.toFloat(), 1f)
|
||||
return Density(scale, sourceDensity.fontScale)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.jetbrains.jewel.bridge
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.awt.ComposePanel
|
||||
import org.jetbrains.jewel.bridge.actionSystem.ComponentDataProviderBridge
|
||||
import org.jetbrains.jewel.bridge.theme.SwingBridgeTheme
|
||||
import org.jetbrains.jewel.foundation.ExperimentalJewelApi
|
||||
import javax.swing.JComponent
|
||||
|
||||
public fun JewelComposePanel(
|
||||
content: @Composable () -> Unit,
|
||||
): JComponent {
|
||||
return ComposePanel().apply {
|
||||
setContent {
|
||||
SwingBridgeTheme {
|
||||
CompositionLocalProvider(LocalComponent provides this@apply) {
|
||||
ComponentDataProviderBridge(this@apply, content = content)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalJewelApi
|
||||
public val LocalComponent: ProvidableCompositionLocal<JComponent> = staticCompositionLocalOf {
|
||||
error("CompositionLocal LocalComponent not provided")
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jewel.bridge
|
||||
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.Density
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.Service.Level
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -42,14 +41,12 @@ internal class SwingBridgeService(scope: CoroutineScope) {
|
||||
return BridgeThemeData(
|
||||
themeDefinition = createBridgeThemeDefinition(),
|
||||
componentStyling = createBridgeComponentStyling(themeDefinition),
|
||||
density = retrieveDensity(),
|
||||
)
|
||||
}
|
||||
|
||||
internal data class BridgeThemeData(
|
||||
val themeDefinition: ThemeDefinition,
|
||||
val componentStyling: ComponentStyling,
|
||||
val density: Density,
|
||||
) {
|
||||
|
||||
public companion object {
|
||||
@@ -67,7 +64,6 @@ internal class SwingBridgeService(scope: CoroutineScope) {
|
||||
dropdownTextStyle = TextStyle.Default,
|
||||
linkTextStyle = TextStyle.Default,
|
||||
),
|
||||
density = retrieveDensity(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jewel.bridge
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.awt.ComposePanel
|
||||
import com.intellij.openapi.wm.ToolWindow
|
||||
import org.jetbrains.jewel.foundation.enableNewSwingCompositing
|
||||
|
||||
@@ -15,15 +14,17 @@ public fun ToolWindow.addComposeTab(
|
||||
// The operation is idempotent, so we can safely do it every time.
|
||||
enableNewSwingCompositing()
|
||||
|
||||
val composePanel = ComposePanel()
|
||||
|
||||
val scope = object : ToolWindowScope {
|
||||
override val toolWindow: ToolWindow = this@addComposeTab
|
||||
override val panel: ComposePanel = composePanel
|
||||
}
|
||||
|
||||
composePanel.setContent { scope.content() }
|
||||
val tabContent = contentManager.factory.createContent(composePanel, tabDisplayName, isLockable)
|
||||
val tabContent = contentManager.factory.createContent(
|
||||
JewelComposePanel {
|
||||
val scope = object : ToolWindowScope {
|
||||
override val toolWindow: ToolWindow
|
||||
get() = this@addComposeTab
|
||||
}
|
||||
scope.content()
|
||||
},
|
||||
tabDisplayName,
|
||||
isLockable,
|
||||
)
|
||||
tabContent.isCloseable = isCloseable
|
||||
contentManager.addContent(tabContent)
|
||||
}
|
||||
@@ -31,6 +32,4 @@ public fun ToolWindow.addComposeTab(
|
||||
public interface ToolWindowScope {
|
||||
|
||||
public val toolWindow: ToolWindow
|
||||
|
||||
public val panel: ComposePanel
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.ui.platform.LocalDensity
|
||||
import com.intellij.openapi.components.service
|
||||
import org.jetbrains.jewel.bridge.BridgePainterHintsProvider
|
||||
import org.jetbrains.jewel.bridge.SwingBridgeService
|
||||
import org.jetbrains.jewel.bridge.retrieveIdeaDensity
|
||||
import org.jetbrains.jewel.foundation.ExperimentalJewelApi
|
||||
import org.jetbrains.jewel.ui.ComponentStyling
|
||||
import org.jetbrains.jewel.ui.painter.LocalPainterHintsProvider
|
||||
@@ -28,7 +29,7 @@ public fun SwingBridgeTheme(content: @Composable () -> Unit) {
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
LocalPainterHintsProvider provides BridgePainterHintsProvider(themeData.themeDefinition.isDark),
|
||||
LocalDensity provides themeData.density,
|
||||
LocalDensity provides retrieveIdeaDensity(LocalDensity.current),
|
||||
) {
|
||||
content()
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import androidx.compose.ui.unit.dp
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ui.JBColor
|
||||
import icons.JewelIcons
|
||||
import org.jetbrains.jewel.bridge.LocalComponent
|
||||
import org.jetbrains.jewel.bridge.ToolWindowScope
|
||||
import org.jetbrains.jewel.bridge.theme.SwingBridgeTheme
|
||||
import org.jetbrains.jewel.bridge.toComposeColor
|
||||
import org.jetbrains.jewel.foundation.lazy.tree.buildTree
|
||||
import org.jetbrains.jewel.foundation.modifier.onActivated
|
||||
@@ -49,21 +49,19 @@ import org.jetbrains.jewel.ui.component.Tooltip
|
||||
|
||||
@Composable
|
||||
internal fun ToolWindowScope.ComponentShowcaseTab() {
|
||||
SwingBridgeTheme {
|
||||
val bgColor by remember(JewelTheme.isDark) { mutableStateOf(JBColor.PanelBackground.toComposeColor()) }
|
||||
val bgColor by remember(JewelTheme.isDark) { mutableStateOf(JBColor.PanelBackground.toComposeColor()) }
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
Row(
|
||||
modifier = Modifier.trackComponentActivation(panel)
|
||||
.fillMaxSize()
|
||||
.background(bgColor)
|
||||
.verticalScroll(scrollState)
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
ColumnOne()
|
||||
ColumnTwo()
|
||||
}
|
||||
val scrollState = rememberScrollState()
|
||||
Row(
|
||||
modifier = Modifier.trackComponentActivation(LocalComponent.current)
|
||||
.fillMaxSize()
|
||||
.background(bgColor)
|
||||
.verticalScroll(scrollState)
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
ColumnOne()
|
||||
ColumnTwo()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,6 @@ import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.datetime.toJavaLocalDate
|
||||
import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified
|
||||
import org.jetbrains.jewel.bridge.retrieveTextStyle
|
||||
import org.jetbrains.jewel.bridge.theme.SwingBridgeTheme
|
||||
import org.jetbrains.jewel.bridge.toComposeColor
|
||||
import org.jetbrains.jewel.bridge.toFontFamily
|
||||
import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn
|
||||
@@ -103,28 +102,26 @@ import kotlin.time.Duration.Companion.seconds
|
||||
@OptIn(DependsOnJBR::class)
|
||||
@Composable
|
||||
fun ReleasesSampleCompose(project: Project) {
|
||||
SwingBridgeTheme {
|
||||
var selectedItem: ContentItem? by remember { mutableStateOf(null) }
|
||||
HorizontalSplitLayout(
|
||||
first = { modifier ->
|
||||
LeftColumn(
|
||||
project = project,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
onSelectedItemChange = { selectedItem = it },
|
||||
)
|
||||
},
|
||||
second = { modifier ->
|
||||
RightColumn(
|
||||
selectedItem = selectedItem,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
)
|
||||
},
|
||||
Modifier.fillMaxSize(),
|
||||
initialDividerPosition = 400.dp,
|
||||
minRatio = .15f,
|
||||
maxRatio = .7f,
|
||||
)
|
||||
}
|
||||
var selectedItem: ContentItem? by remember { mutableStateOf(null) }
|
||||
HorizontalSplitLayout(
|
||||
first = { modifier ->
|
||||
LeftColumn(
|
||||
project = project,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
onSelectedItemChange = { selectedItem = it },
|
||||
)
|
||||
},
|
||||
second = { modifier ->
|
||||
RightColumn(
|
||||
selectedItem = selectedItem,
|
||||
modifier = modifier.fillMaxSize(),
|
||||
)
|
||||
},
|
||||
Modifier.fillMaxSize(),
|
||||
initialDividerPosition = 400.dp,
|
||||
minRatio = .15f,
|
||||
maxRatio = .7f,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ResourcePainterProvider(
|
||||
currentHintsProvider.hints(basePath)
|
||||
.forEach { scope.resolveHint(it) }
|
||||
|
||||
val cacheKey = scope.acceptedHints.hashCode()
|
||||
val cacheKey = scope.acceptedHints.hashCode() * 31 + LocalDensity.current.hashCode()
|
||||
|
||||
if (inDebugMode && cache[cacheKey] != null) {
|
||||
println("Cache hit for $basePath(${scope.acceptedHints.joinToString()})")
|
||||
|
||||
Reference in New Issue
Block a user