From 73d53ffcded09776ce19153e13316d71601df57a Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Sat, 23 Mar 2024 16:51:18 +0100 Subject: [PATCH] Fixed focus border for borderless ComboBox GitOrigin-RevId: a3651f57c285c98dd4065abcbbf7c9643719a4f1 --- .../ide/ui/laf/darcula/DarculaNewUIUtils.kt | 4 +- .../laf/darcula/ui/DarculaComboBoxBorder.kt | 8 ++++ .../ui/laf/darcula/ui/DarculaComboBoxUI.java | 4 +- .../ui/sandbox/components/JComboBoxPanel.kt | 45 +++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtils.kt b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtils.kt index d0bcdfa93d29..b4f168a4312a 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtils.kt +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaNewUIUtils.kt @@ -11,7 +11,8 @@ import kotlin.math.max /** * Paints rounded border for focusable component. Non focused border rect is inside [rect], focused/outlined border can come outside */ -internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: DarculaUIUtil.Outline?, focused: Boolean, enabled: Boolean) { +internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: DarculaUIUtil.Outline?, focused: Boolean, enabled: Boolean, + bw: Int = DarculaUIUtil.BW.get()) { val g2 = g.create() as Graphics2D try { @@ -20,7 +21,6 @@ internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: Darcula if (MacUIUtil.USE_QUARTZ) RenderingHints.VALUE_STROKE_PURE else RenderingHints.VALUE_STROKE_NORMALIZE) val lw = DarculaUIUtil.LW.get() - val bw = DarculaUIUtil.BW.get() val arc = DarculaUIUtil.COMPONENT_ARC.get() when { diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxBorder.kt b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxBorder.kt index ddf0fe9f5903..afb5ddcff154 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxBorder.kt +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxBorder.kt @@ -91,6 +91,9 @@ open class DarculaComboBoxBorder : Border, ErrorBorderCapable, UIResource { Type.TABLE_CELL_EDITOR, Type.EMBEDDED -> { DarculaUIUtil.paintCellEditorBorder(g2, comboBox, r, focused) } + Type.BORDERLESS -> { + paintBorderlessBorder(g2, comboBox, r, focused) + } else -> { paintNormalBorder(g2, comboBox, r, focused) } @@ -106,6 +109,11 @@ open class DarculaComboBoxBorder : Border, ErrorBorderCapable, UIResource { paintComponentBorder(g, r, DarculaUIUtil.getOutline(comboBox), focused, comboBox.isEnabled) } + protected fun paintBorderlessBorder(g: Graphics2D, comboBox: JComboBox<*>, r: Rectangle, focused: Boolean) { + JBInsets.removeFrom(r, getBorderInsets(comboBox)) + paintComponentBorder(g, r, DarculaUIUtil.getOutline(comboBox), focused, comboBox.isEnabled, bw = DarculaUIUtil.LW.get()) + } + /** * Returns DarculaComboBoxUI if it should be used as border instead of [DarculaComboBoxBorder] itself. * See [DarculaComboBoxUI.isNewBorderSupported] for details diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index b567a9706bd1..e38fcad2fbb5 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java @@ -317,14 +317,14 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border, ErrorB } Graphics2D g2 = (Graphics2D)g.create(); - Rectangle r = new Rectangle(c.getSize()); - JBInsets.removeFrom(r, myBorderCompensation); if (comboBox.getBorder() instanceof DarculaComboBoxBorder comboBoxBorder && isNewBorderSupported(comboBox)) { comboBoxBorder.paintComboBoxBackground(g2, comboBox, getBackgroundColor()); } else { try { + Rectangle r = new Rectangle(c.getSize()); + JBInsets.removeFrom(r, myBorderCompensation); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g2.translate(r.x, r.y); diff --git a/platform/platform-impl/src/com/intellij/internal/ui/sandbox/components/JComboBoxPanel.kt b/platform/platform-impl/src/com/intellij/internal/ui/sandbox/components/JComboBoxPanel.kt index dd7bebd913a8..79bd2fdb307e 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/sandbox/components/JComboBoxPanel.kt +++ b/platform/platform-impl/src/com/intellij/internal/ui/sandbox/components/JComboBoxPanel.kt @@ -47,6 +47,51 @@ internal class JComboBoxPanel : UISandboxPanel { } } + group("IS_EMBEDDED_PROPERTY") { + withStateLabel { + comboBox(items).applyToComponent { + putClientProperty(ComboBox.IS_EMBEDDED_PROPERTY, true) + } + } + withStateLabel { + comboBox(items) + .enabled(false) + .applyToComponent { + putClientProperty(ComboBox.IS_EMBEDDED_PROPERTY, true) + } + } + } + + group("IS_BORDERLESS_PROPERTY") { + withStateLabel { + comboBox(items).applyToComponent { + putClientProperty(ComboBox.IS_BORDERLESS_PROPERTY, true) + } + } + withStateLabel { + comboBox(items) + .enabled(false) + .applyToComponent { + putClientProperty(ComboBox.IS_BORDERLESS_PROPERTY, true) + } + } + } + + group("IS_TABLE_CELL_EDITOR_PROPERTY") { + withStateLabel { + comboBox(items).applyToComponent { + putClientProperty(ComboBox.IS_TABLE_CELL_EDITOR_PROPERTY, true) + } + } + withStateLabel { + comboBox(items) + .enabled(false) + .applyToComponent { + putClientProperty(ComboBox.IS_TABLE_CELL_EDITOR_PROPERTY, true) + } + } + } + group("Validation") { withStateLabel("Error") { comboBox(items).validationOnInput {