From 54cd8e5713aaa3f3cf604dca5ae7ba843d6cbaeb Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Tue, 2 Apr 2024 20:11:22 +0200 Subject: [PATCH] IDEA-345293 Tool window stripes are not scaled on zoom if 'Show tool window names' option is on GitOrigin-RevId: f93cbb3d84c5742430bb3ca0bafec3c049131f2d --- .../toolWindow/ResizeStripeManager.kt | 39 ++++++++++++++++--- .../ToolWindowPaneNewButtonManager.kt | 2 + .../intellij/toolWindow/ToolWindowToolbar.kt | 6 +++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/toolWindow/ResizeStripeManager.kt b/platform/platform-impl/src/com/intellij/toolWindow/ResizeStripeManager.kt index a452b5f497ec..d44fa7ee8a3d 100644 --- a/platform/platform-impl/src/com/intellij/toolWindow/ResizeStripeManager.kt +++ b/platform/platform-impl/src/com/intellij/toolWindow/ResizeStripeManager.kt @@ -42,6 +42,7 @@ class ResizeStripeManager(private val myComponent: ToolWindowToolbar) : Splittab private var myCalculateDelta = false private var myDelta = 0 private var myCustomWidth = 0 + private var myCurrentScale = 0f init { myComponent.addMouseListener(object : PopupHandler() { @@ -89,6 +90,7 @@ class ResizeStripeManager(private val myComponent: ToolWindowToolbar) : Splittab val enabled = isShowNames() if (enabled) { myCustomWidth = getSideCustomWidth(myComponent.anchor) + myCurrentScale = UISettings.getInstance().currentIdeScale myComponent.add(mySplitter) } else { @@ -102,11 +104,11 @@ class ResizeStripeManager(private val myComponent: ToolWindowToolbar) : Splittab } else { myCustomWidth = getSideCustomWidth(myComponent.anchor) + myCurrentScale = UISettings.getInstance().currentIdeScale } updateView() } - override fun setProportion(proportion: Float) { if (myIgnoreProportion) { return @@ -124,18 +126,43 @@ class ResizeStripeManager(private val myComponent: ToolWindowToolbar) : Splittab } width += myDelta - val min = JBUI.scale(if (UISettings.Companion.getInstance().compactMode) 32 else 40) + width = checkMinMax(width) + + myCustomWidth = width + myCurrentScale = UISettings.getInstance().currentIdeScale + setSideCustomWidth(myComponent, width) + updateView() + } + + private fun checkMinMax(width: Int): Int { + val min = JBUI.scale(if (UISettings.getInstance().compactMode) 32 else 40) if (width < min) { - width = min + return min } val max = JBUI.scale(100) if (width > max) { - width = max + return max } - myCustomWidth = width - setSideCustomWidth(myComponent, width) + return width + } + + fun updateNamedState() { + val currentScale = UISettings.getInstance().currentIdeScale + if (myCustomWidth == 0 && myCurrentScale == 0f) { + myCustomWidth = getSideCustomWidth(myComponent.anchor) + val width = checkMinMax(myCustomWidth) + if (width != myCustomWidth) { + myCustomWidth = width + setSideCustomWidth(myComponent, width) + } + } + else if (myCurrentScale != currentScale) { + myCustomWidth = (myCustomWidth * currentScale / myCurrentScale).toInt() + setSideCustomWidth(myComponent, myCustomWidth) + } + myCurrentScale = currentScale updateView() } diff --git a/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowPaneNewButtonManager.kt b/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowPaneNewButtonManager.kt index c1eb08f160d5..66ac2fe4f0a1 100644 --- a/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowPaneNewButtonManager.kt +++ b/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowPaneNewButtonManager.kt @@ -34,6 +34,8 @@ internal class ToolWindowPaneNewButtonManager(paneId: String, isPrimary: Boolean val visible = showButtons || state.isStripesOverlaid left.isVisible = visible right.isVisible = visible + left.updateNamedState() + right.updateNamedState() return oldSquareVisible != visible } diff --git a/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowToolbar.kt b/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowToolbar.kt index a8fbdc3b0fa6..c92009f9ada0 100644 --- a/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowToolbar.kt +++ b/platform/platform-impl/src/com/intellij/toolWindow/ToolWindowToolbar.kt @@ -67,6 +67,12 @@ abstract class ToolWindowToolbar(private val isPrimary: Boolean, val anchor: Too myResizeManager.updateState(toolbar) } + fun updateNamedState() { + if (isVisible && ResizeStripeManager.isShowNames()) { + myResizeManager.updateNamedState() + } + } + open fun createBorder():Border = JBUI.Borders.empty() open fun getBorderColor(): Color? = JBUI.CurrentTheme.ToolWindow.borderColor()