IDEA-285044 16x16 icons used instead of 20x20

GitOrigin-RevId: 7d417db800c9b15f33374812e0722a2c104abdb7
This commit is contained in:
Mikhail Sokolov
2021-12-30 14:52:53 +03:00
committed by intellij-monorepo-bot
parent 1b45f3fd30
commit 0725eb0eaa

View File

@@ -1,17 +1,23 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.wm.impl.headertoolbar
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionButtonComponent
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.actionSystem.impl.ActionButton
import com.intellij.openapi.actionSystem.impl.IdeaActionButtonLook
import com.intellij.openapi.util.IconLoader
import com.intellij.openapi.util.ScalableIcon
import com.intellij.util.ui.JBUI
import java.awt.*
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.UIManager
private const val iconSize = 20
internal class ActionToolbar(actions: List<AnAction>) : JPanel(FlowLayout(FlowLayout.LEFT, 5, 0)) {
init {
@@ -21,15 +27,26 @@ internal class ActionToolbar(actions: List<AnAction>) : JPanel(FlowLayout(FlowLa
}
private fun createButton(action: AnAction): JComponent {
val presentation = action.templatePresentation
val insets = UIManager.getInsets("MainToolbar.icon.borderInsets") ?: JBUI.insets(10)
val iconSize = presentation.icon?.let { Dimension(it.iconWidth, it.iconHeight) } ?: Dimension(16, 16)
val size = Dimension(iconSize.width + insets.left + insets.right,
iconSize.height + insets.top + insets.bottom)
val presentation = action.templatePresentation.clone()
presentation.scaleIcon(iconSize)
presentation.addPropertyChangeListener { evt -> if (evt.propertyName == Presentation.PROP_ICON) presentation.scaleIcon(iconSize) }
if (presentation.icon == null) presentation.icon = AllIcons.Toolbar.Unknown
val size = Dimension(iconSize + insets.left + insets.right,
iconSize + insets.top + insets.bottom)
val button = ActionButton(action, presentation, ActionPlaces.MAIN_TOOLBAR, size)
button.setLook(MainToolbarLook())
return button
}
private fun Presentation.scaleIcon(size: Int) {
if (icon == null) return
if (icon is ScalableIcon && icon.iconWidth != size) {
icon = IconLoader.loadCustomVersionOrScale(icon as ScalableIcon, size.toFloat())
}
}
}
private class MainToolbarLook : IdeaActionButtonLook() {