IDEA-299042 Run widget popup: inline actions have incorrect width
authorMikhail Sokolov <mikhail.sokolov@jetbrains.com>
Tue, 9 Aug 2022 16:42:10 +0000 (18:42 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 10 Aug 2022 11:33:11 +0000 (11:33 +0000)
GitOrigin-RevId: a7c4a06eef391593180a963af0e9b84ed08ca9a2

platform/platform-impl/src/com/intellij/ui/popup/list/PopupInlineActionsSupportImpl.kt
platform/platform-impl/src/com/intellij/ui/popup/list/PopupListElementRenderer.java
platform/platform-resources/src/themes/expUI/expUI_dark.theme.json
platform/platform-resources/src/themes/expUI/expUI_light.theme.json
platform/platform-resources/src/themes/metadata/IntelliJPlatform.themeMetadata.json
platform/util/ui/src/com/intellij/util/ui/JBUI.java

index 00e839b23e984ddf0d355043a391eba02f330fe5..abced35be1bb2778866d8a7402fc4f5530e09ac4 100644 (file)
@@ -4,17 +4,20 @@ package com.intellij.ui.popup.list
 import com.intellij.icons.AllIcons
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.ui.ExperimentalUI
+import com.intellij.ui.components.panels.Wrapper
 import com.intellij.ui.popup.ActionPopupStep
 import com.intellij.ui.popup.PopupFactoryImpl.ActionItem
 import com.intellij.ui.popup.PopupFactoryImpl.InlineActionItem
 import com.intellij.ui.popup.list.ListPopupImpl.ListWithInlineButtons
+import com.intellij.ui.scale.JBUIScale
 import com.intellij.util.ui.JBInsets
 import com.intellij.util.ui.JBUI
-import java.awt.BorderLayout
 import java.awt.Point
 import java.awt.event.InputEvent
 import javax.swing.*
 
+private const val INLINE_BUTTON_WIDTH = 16
+
 class PopupInlineActionsSupportImpl(private val myListPopup: ListPopupImpl) : PopupInlineActionsSupport {
 
   private val myStep = myListPopup.listStep as ActionPopupStep
@@ -41,11 +44,10 @@ class PopupInlineActionsSupportImpl(private val myListPopup: ListPopupImpl) : Po
     if (buttonsCount <= 0) return null
 
     val distanceToRight = bounds.x + bounds.width - point.x
-    val buttonsToRight = distanceToRight / (PopupListElementRenderer.INLINE_BUTTON_WIDTH + PopupListElementRenderer.INLINE_BUTTONS_GAP)
+    val buttonsToRight = distanceToRight / buttonWidth()
     if (buttonsToRight >= buttonsCount) return null
 
-    val distanceToNearest = distanceToRight - buttonsToRight * (PopupListElementRenderer.INLINE_BUTTON_WIDTH + PopupListElementRenderer.INLINE_BUTTONS_GAP)
-    return if (distanceToNearest > PopupListElementRenderer.INLINE_BUTTON_WIDTH) null else buttonsCount - buttonsToRight - 1
+    return buttonsCount - buttonsToRight - 1
   }
 
   override fun runInlineAction(element: Any, index: Int, event: InputEvent?) = getExtraButtonsActions(element, event)[index].run()
@@ -89,10 +91,11 @@ class PopupInlineActionsSupportImpl(private val myListPopup: ListPopupImpl) : Po
 
   private fun createExtraButton(icon: Icon, active: Boolean): JComponent {
     val label = JLabel(icon)
-    val panel = JPanel(BorderLayout())
-    panel.add(label)
+    val leftRightInsets = JBUI.CurrentTheme.List.buttonLeftRightInsets()
+    label.border = JBUI.Borders.empty(0, leftRightInsets)
+    val panel = Wrapper(label)
     val size = panel.preferredSize
-    size.width = PopupListElementRenderer.INLINE_BUTTON_WIDTH
+    size.width = buttonWidth(leftRightInsets)
     panel.preferredSize = size
     panel.minimumSize = size
     panel.isOpaque = active
@@ -100,10 +103,9 @@ class PopupInlineActionsSupportImpl(private val myListPopup: ListPopupImpl) : Po
     return panel
   }
 
-  private fun createNextStepRunnable(element: ActionItem) =
-    Runnable { myListPopup.showNextStepPopup(myStep.onChosen(element, false), element) }
+  private fun buttonWidth(leftRightInsets: Int = JBUI.CurrentTheme.List.buttonLeftRightInsets()) : Int = JBUIScale.scale(INLINE_BUTTON_WIDTH + leftRightInsets * 2)
 
-  private fun createInlineActionRunnable(action: AnAction, inputEvent: InputEvent?) = Runnable {
-    myStep.performAction(action, inputEvent)
-  }
+  private fun createNextStepRunnable(element: ActionItem) = Runnable { myListPopup.showNextStepPopup(myStep.onChosen(element, false), element) }
+
+  private fun createInlineActionRunnable(action: AnAction, inputEvent: InputEvent?) = Runnable { myStep.performAction(action, inputEvent) }
 }
\ No newline at end of file
index 2351f08877e231279fc7d2237e34e63e37f1b2f2..d768d52f1883bdde3c44ba469ff528e12de3f1fe 100644 (file)
@@ -29,9 +29,6 @@ import java.awt.*;
 
 public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
 
-  static final int INLINE_BUTTONS_GAP = 8;
-  static final int INLINE_BUTTON_WIDTH = 20;
-
   public static final Key<@NlsSafe String> CUSTOM_KEY_STROKE_TEXT = new Key<>("CUSTOM_KEY_STROKE_TEXT");
   protected final ListPopupImpl myPopup;
   private JLabel myShortcutLabel;
@@ -382,13 +379,7 @@ public class PopupListElementRenderer<E> extends GroupedItemsListRenderer<E> {
     java.util.List<JComponent> extraButtons = myInlineActionsSupport.getExtraButtons(list, value, isSelected);
     if (!extraButtons.isEmpty()) {
       myButtonsSeparator.setVisible(true);
-      int size = extraButtons.size();
-      for (int i = 0; i < size; i++) {
-        JComponent comp = extraButtons.get(i);
-        gb.next();
-        if (i < size - 1) gb.insetRight(INLINE_BUTTONS_GAP);
-        myButtonPane.add(comp, gb);
-      }
+      extraButtons.forEach(comp -> myButtonPane.add(comp, gb.next()));
     }
     else {
       myButtonsSeparator.setVisible(false);
index 2bee581c247eab516c2572c43bff1bc380e6abba..93482c1c95f16dc9e085d3bb2113d2273747df97 100644 (file)
 
     "List": {
       "rowHeight": "24",
-      "border": "4,0,4,0"
+      "border": "4,0,4,0",
+      "Button.leftRightInset": 8
     },
 
     "MemoryIndicator": {
index 70cf1fd90671545be8e3b809f34654a78405f12f..3fca24d88ab67dadb4743e02e1e924b1d6031ee5 100644 (file)
 
     "List": {
       "rowHeight": "24",
-      "border": "4,0,4,0"
+      "border": "4,0,4,0",
+      "Button.leftRightInset": 8
     },
 
     "Menu": {
index a1e09ad8b799ef8dd9fff1a955aa9a8b017c590d..956022b725c7cdb0e181253941fddfdab8512c46 100644 (file)
       "since": "2020.3",
       "description": "A background of a hovered row in an unfocused list if hover is allowed."
     },
+    {
+      "key": "List.Button.leftRightInset",
+      "since": "2022.3",
+      "description": "An insets for popup inline actions buttons"
+    },
     {
       "key": "TabbedPane.tabSelectionArc",
       "since": "2022.2",
index 65fa1d01b687fa3186f59f17a4bc4c5a962efd53..f25b6abeead0990d281601e7542a88688870e6c0 100644 (file)
@@ -1330,6 +1330,10 @@ public final class JBUI {
         return result <= 0 ? defaultHeight : result;
       }
 
+      static int buttonLeftRightInsets() {
+        return getInt("List.Button.leftRightInset", 8);
+      }
+
       final class Selection {
         private static final Color BACKGROUND = JBColor.namedColor("List.selectionBackground", DEFAULT_RENDERER_SELECTION_BACKGROUND);
         private static final Color FOREGROUND = JBColor.namedColor("List.selectionForeground", Label.foreground(true));