💄 nicer looking input box
This commit is contained in:
parent
4941870e2d
commit
1bac194aa4
2 changed files with 54 additions and 8 deletions
|
|
@ -5,11 +5,35 @@ import com.intellij.openapi.editor.colors.EditorColors
|
|||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import java.awt.Color
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
|
||||
class GetTheme {
|
||||
fun getSecondaryDark(): Color {
|
||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||
val defaultBackground = globalScheme.defaultBackground
|
||||
val grayscale = (defaultBackground.red * 0.3 + defaultBackground.green * 0.59 + defaultBackground.blue * 0.11).toInt()
|
||||
|
||||
val adjustedRed: Int
|
||||
val adjustedGreen: Int
|
||||
val adjustedBlue: Int
|
||||
|
||||
val tint: Int = 20
|
||||
if (grayscale > 128) { // if closer to white
|
||||
adjustedRed = max(0, defaultBackground.red - tint)
|
||||
adjustedGreen = max(0, defaultBackground.green - tint)
|
||||
adjustedBlue = max(0, defaultBackground.blue - tint)
|
||||
} else { // if closer to black
|
||||
adjustedRed = min(255, defaultBackground.red + tint)
|
||||
adjustedGreen = min(255, defaultBackground.green + tint)
|
||||
adjustedBlue = min(255, defaultBackground.blue + tint)
|
||||
}
|
||||
|
||||
return Color(adjustedRed, adjustedGreen, adjustedBlue)
|
||||
}
|
||||
|
||||
fun getTheme(): Map<String, String> {
|
||||
try {
|
||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.continuedev.continueintellijextension.editor
|
||||
|
||||
import com.github.continuedev.continueintellijextension.`continue`.GetTheme
|
||||
import com.github.continuedev.continueintellijextension.factories.CustomSchemeHandlerFactory
|
||||
import com.github.continuedev.continueintellijextension.toolWindow.ContinueBrowser
|
||||
import com.github.continuedev.continueintellijextension.toolWindow.JS_QUERY_POOL_SIZE
|
||||
|
|
@ -113,17 +114,17 @@ class InlineEditAction : AnAction(), DumbAware {
|
|||
// }
|
||||
// }
|
||||
|
||||
val textArea = CustomTextArea("Text", 2, 40).apply {
|
||||
val textArea = CustomTextArea( 2, 40).apply {
|
||||
lineWrap = true
|
||||
wrapStyleWord = true
|
||||
isOpaque = false
|
||||
background = Color(0, 0, 0, 0)
|
||||
background = GetTheme().getSecondaryDark()
|
||||
maximumSize = Dimension(400, Short.MAX_VALUE.toInt())
|
||||
margin = Insets(10, 10, 10, 10)
|
||||
margin = Insets(8, 8, 8, 8)
|
||||
}
|
||||
textArea.putClientProperty(UIUtil.HIDE_EDITOR_FROM_DATA_CONTEXT_PROPERTY, true)
|
||||
|
||||
val panel = JPanel(MigLayout("wrap 1, insets 10 $leftInset 10 10, gap 0!, fillx, scrolly")).apply {
|
||||
val panel = JPanel(MigLayout("wrap 1, insets 10 $leftInset 10 10, gap 0!, fillx")).apply {
|
||||
// Transparent background
|
||||
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||
val defaultBackground = globalScheme.defaultBackground
|
||||
|
|
@ -145,7 +146,7 @@ class InlineEditAction : AnAction(), DumbAware {
|
|||
}
|
||||
}
|
||||
|
||||
class CustomTextArea(text: String, rows: Int, columns: Int) : JTextArea(text, rows, columns) {
|
||||
class CustomTextArea(rows: Int, columns: Int) : JTextArea(rows, columns) {
|
||||
override fun paintComponent(g: Graphics) {
|
||||
val g2 = g as Graphics2D
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
|
|
@ -154,10 +155,31 @@ class CustomTextArea(text: String, rows: Int, columns: Int) : JTextArea(text, ro
|
|||
g2.color = background
|
||||
g2.fillRoundRect(0, 0, width - 1, height - 1, 15, 15)
|
||||
|
||||
// Draw the box shadow
|
||||
// val shadowColor = Color(0, 0, 0, 100) // Change this to your desired shadow color and opacity
|
||||
// val shadowOffset = 5 // Change this to your desired shadow offset
|
||||
// val shadowSize = 10 // Change this to your desired shadow size
|
||||
//
|
||||
// g2.color = shadowColor
|
||||
// g2.fillRoundRect(
|
||||
// shadowOffset,
|
||||
// shadowOffset,
|
||||
// width - shadowOffset * 2,
|
||||
// height - shadowOffset * 2,
|
||||
// 15,
|
||||
// 15
|
||||
// )
|
||||
|
||||
// Draw placeholder
|
||||
if (getText().isEmpty()) {
|
||||
g.setColor(Color(128, 128, 128, 200))
|
||||
g.drawString("Enter instructions to edit highlighted code", 8, 21);
|
||||
}
|
||||
|
||||
// Draw the rounded border
|
||||
val borderColor = Color.BLUE // Change this to your desired border color
|
||||
val borderThickness = 1 // Change this to your desired border thickness
|
||||
val borderRadius = 15 // Change this to your desired border radius
|
||||
val borderColor = Color(128, 128, 128, 128)
|
||||
val borderThickness = 1
|
||||
val borderRadius = 16
|
||||
|
||||
g2.color = borderColor
|
||||
g2.stroke = BasicStroke(borderThickness.toFloat())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue