mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
[dotnet, inlays] support custom icon scale for block inlays
GitOrigin-RevId: 87f09546d5325e78e640c3627221fb8564cd4f51
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7c5f6e7e55
commit
5b2556c776
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user