[dotnet, inlays] support custom icon scale for block inlays

GitOrigin-RevId: 87f09546d5325e78e640c3627221fb8564cd4f51
This commit is contained in:
Nikolay Plyusnin
2024-06-07 20:27:39 +03:00
committed by intellij-monorepo-bot
parent 7c5f6e7e55
commit 5b2556c776
2 changed files with 23 additions and 3 deletions

View File

@@ -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
{

View File

@@ -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 = "<image>"
}
@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
}