Icon rendered in Inlay not transparent

Answered

I have got following Kotlin code that puts an inlay with one of two images based on a condition into the editor. The icons themselves for testing are Intellijs own Commit Action Icon and General Error Icons. Both are transparent and SVGs. Yet with following Kotlin code:

private fun applyOnEditor(editor: Editor) {
val vs = FileDocumentManager.getInstance().getFile(editor.document) ?: return
val path = vs.path
val info = myHighlighting[path] ?: return
myActiveInlays.plusAssign(info.branchInfo.map { (startPos, steppedIn, skipped) ->
editor.inlayModel.addInlineElement(
editor.logicalPositionToOffset(startPos),
PresentationRenderer(
IconPresentation(
if (steppedIn && skipped) AllIcons.Actions.Commit else AllIcons.General.Error,
editor.contentComponent
)
)
)
})
}

I get the following output:

Is this a bug or am I doing something wrong for the background to be black and not transparent?
Tested in a plugin for CLion 2019.2.3
0
1 comment

Hello!
Yes, it is indeed bug, as we actually didn't use this presentation in our codebase, it wasn't properly tested. I'll do a fix today.
As a workaround for now you can create your own IconPresentation with the following content:

class IconPresentation(var icon: Icon, var component: Component) : BasePresentation() {
override val width: Int
get() = icon.iconWidth
override val height: Int
get() = icon.iconHeight

override fun paint(g: Graphics2D, attributes: TextAttributes) {
val graphics = g.create() as Graphics2D
graphics.composite = AlphaComposite.SrcAtop.derive(1.0f)
icon.paintIcon(component, graphics, 0, 0)
graphics.dispose()
}

override fun toString(): String = "<image>"
}
0

Please sign in to leave a comment.