KT-32366: Extract text styling variables to outputStylingUtils

This commit is contained in:
Roman Golyshev
2019-08-19 15:18:12 +03:00
committed by Roman Golyshev
parent 358ec2b8bd
commit d0cd4967a7
2 changed files with 40 additions and 32 deletions
@@ -21,7 +21,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch
private fun getFontInfo(editor: Editor): FontInfo {
val colorsScheme = editor.colorsScheme
val fontPreferences = colorsScheme.fontPreferences
val attributes = getAttributes()
val attributes = getAttributesForOutputType(outputType)
val fontStyle = attributes.fontType
return ComplementaryFontsRegistry.getFontAbleToDisplay(
'a'.toInt(), fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.contentComponent)
@@ -34,7 +34,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch
}
override fun paint(editor: Editor, g: Graphics, r: Rectangle, textAttributes: TextAttributes) {
val attributes = getAttributes()
val attributes = getAttributesForOutputType(outputType)
val fgColor = attributes.foregroundColor ?: return
g.color = fgColor
val fontInfo = getFontInfo(editor)
@@ -43,36 +43,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch
g.drawString(text, r.x, r.y + metrics.ascent)
}
private fun getAttributes(): TextAttributes {
return when (outputType) {
ScratchOutputType.OUTPUT -> userOutputAttributes
ScratchOutputType.RESULT -> normalAttributes
ScratchOutputType.ERROR -> errorAttributes
}
}
override fun toString(): String {
return "${text.takeWhile { it.isWhitespace() }}${outputType.name}: ${text.trim()}"
}
companion object {
private val normalAttributes = TextAttributes(
JBColor.GRAY,
null, null, null,
Font.ITALIC
)
private val errorAttributes = TextAttributes(
JBColor(Colors.DARK_RED, Colors.DARK_RED),
null, null, null,
Font.ITALIC
)
private val userOutputColor = Color(0x5C5CFF)
private val userOutputAttributes = TextAttributes(
JBColor(userOutputColor, userOutputColor),
null, null, null,
Font.ITALIC
)
}
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.scratch.output
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.ui.Colors
import com.intellij.ui.JBColor
import java.awt.Color
import java.awt.Font
fun getAttributesForOutputType(outputType: ScratchOutputType): TextAttributes {
return when (outputType) {
ScratchOutputType.OUTPUT -> userOutputAttributes
ScratchOutputType.RESULT -> normalAttributes
ScratchOutputType.ERROR -> errorAttributes
}
}
private val userOutputColor = Color(0x5C5CFF)
private val normalAttributes = TextAttributes().apply {
foregroundColor = JBColor.GRAY
fontType = Font.ITALIC
}
private val errorAttributes = TextAttributes().apply {
foregroundColor = JBColor(Colors.DARK_RED, Colors.DARK_RED)
fontType = Font.ITALIC
}
private val userOutputAttributes = TextAttributes().apply {
foregroundColor = JBColor(userOutputColor, userOutputColor)
fontType = Font.ITALIC
}