diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt index 5b0caf6ab930..089bf68c2398 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt @@ -121,6 +121,12 @@ class PresentationFactory(private val editor: Editor) : InlayPresentationFactory @Contract(pure = true) override fun icon(icon: Icon): IconPresentation = IconPresentation(icon, editor.component) + @Contract(pure = true) + fun scaledIcon(icon: Icon, scaleFactor: Float): InlayPresentation + { + return ScaledIconWithCustomFactorPresentation(textMetricsStorage, false, icon, editor.component, scaleFactor) + } + @Contract(pure = true) override fun smallScaledIcon(icon: Icon): InlayPresentation { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/ScaledIconPresentation.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/ScaledIconPresentation.kt index 3abb3c5715c0..f9d3e43d0dd9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/ScaledIconPresentation.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/ScaledIconPresentation.kt @@ -9,12 +9,13 @@ import java.awt.AlphaComposite import java.awt.Component import java.awt.Graphics2D import javax.swing.Icon +import kotlin.math.ceil /** * Draws image. If you need to position image inside inlay, use [InsetPresentation] */ @ApiStatus.Internal -class ScaledIconPresentation( +open class ScaledIconPresentation( private val metricsStorage: InlayTextMetricsStorage, val isSmall: Boolean, icon: Icon, private val component: Component) : BasePresentation() { @@ -25,8 +26,7 @@ class ScaledIconPresentation( } private fun getMetrics() = metricsStorage.getFontMetrics(isSmall) - - private fun getScaleFactor() = (getMetrics().fontHeight.toDouble() / icon.iconHeight) + protected open fun getScaleFactor() = (getMetrics().fontHeight.toDouble() / icon.iconHeight) override val width: Int get() = (icon.iconWidth * getScaleFactor()).toInt() @@ -42,4 +42,18 @@ class ScaledIconPresentation( } override fun toString(): String = "" +} + +@ApiStatus.Internal +class ScaledIconWithCustomFactorPresentation( + metricsStorage: InlayTextMetricsStorage, + isSmall: Boolean, + icon: Icon, + component: Component, + private val iconScaleFactor: Float = 1f) : ScaledIconPresentation(metricsStorage, isSmall, icon, component) { + + override val height: Int + get() = ceil(super.height * iconScaleFactor).toInt() + + override fun getScaleFactor(): Double = super.getScaleFactor() * iconScaleFactor } \ No newline at end of file