mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-155000 Overlapping texts in completion popup
This commit is contained in:
+24
-7
@@ -45,6 +45,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
@@ -58,8 +59,6 @@ import java.util.Set;
|
||||
public class LookupCellRenderer implements ListCellRenderer {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.lookup.impl.LookupCellRenderer");
|
||||
//TODO[kb]: move all these awesome constants to Editor's Fonts & Colors settings
|
||||
private static final int AFTER_TAIL = 10;
|
||||
private static final int AFTER_TYPE = 6;
|
||||
private Icon myEmptyIcon = EmptyIcon.create(5);
|
||||
private final Font myNormalFont;
|
||||
private final Font myBoldFont;
|
||||
@@ -100,17 +99,16 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
|
||||
myTailComponent = new MySimpleColoredComponent();
|
||||
myTailComponent.setIpad(new Insets(0, 0, 0, 0));
|
||||
myTailComponent.setBorder(new EmptyBorder(0, 0, 0, JBUI.scale(10)));
|
||||
|
||||
myTypeLabel = new MySimpleColoredComponent();
|
||||
myTypeLabel.setIpad(new Insets(0, 0, 0, 0));
|
||||
myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, JBUI.scale(6)));
|
||||
|
||||
myPanel = new LookupPanel();
|
||||
myPanel.add(myNameComponent, BorderLayout.WEST);
|
||||
myPanel.add(myTailComponent, BorderLayout.CENTER);
|
||||
myTailComponent.setBorder(new EmptyBorder(0, 0, 0, AFTER_TAIL));
|
||||
|
||||
myPanel.add(myTypeLabel, BorderLayout.EAST);
|
||||
myTypeLabel.setBorder(new EmptyBorder(0, 0, 0, AFTER_TYPE));
|
||||
|
||||
myNormalMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myNormalFont);
|
||||
myBoldMetrics = myLookup.getTopLevelEditor().getComponent().getFontMetrics(myBoldFont);
|
||||
@@ -137,7 +135,7 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR :
|
||||
isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
|
||||
|
||||
int allowedWidth = list.getWidth() - AFTER_TAIL - AFTER_TYPE - getTextIndent();
|
||||
int allowedWidth = list.getWidth() - calcSpacing(myNameComponent, myEmptyIcon) - calcSpacing(myTailComponent, null) - calcSpacing(myTypeLabel, null);
|
||||
|
||||
FontMetrics normalMetrics = getRealFontMetrics(item, false);
|
||||
FontMetrics boldMetrics = getRealFontMetrics(item, true);
|
||||
@@ -226,6 +224,24 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
private static int calcSpacing(@NotNull SimpleColoredComponent component, @Nullable Icon icon) {
|
||||
Insets iPad = component.getIpad();
|
||||
int width = iPad.left + iPad.right;
|
||||
Border myBorder = component.getMyBorder();
|
||||
if (myBorder != null) {
|
||||
Insets insets = myBorder.getBorderInsets(component);
|
||||
width += insets.left + insets.right;
|
||||
}
|
||||
Insets insets = component.getInsets();
|
||||
if (insets != null) {
|
||||
width += insets.left + insets.right;
|
||||
}
|
||||
if (icon != null) {
|
||||
width += icon.getIconWidth() + component.getIconTextGap();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
private static Color getForegroundColor(boolean isSelected) {
|
||||
return isSelected ? SELECTED_FOREGROUND_COLOR : FOREGROUND_COLOR;
|
||||
}
|
||||
@@ -466,7 +482,8 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
myEmptyIcon = new EmptyIcon(Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight()));
|
||||
}
|
||||
|
||||
return RealLookupElementPresentation.calculateWidth(p, getRealFontMetrics(item, false), getRealFontMetrics(item, true)) + AFTER_TAIL + AFTER_TYPE;
|
||||
return RealLookupElementPresentation.calculateWidth(p, getRealFontMetrics(item, false), getRealFontMetrics(item, true)) +
|
||||
calcSpacing(myTailComponent, null) + calcSpacing(myTypeLabel, null);
|
||||
}
|
||||
|
||||
public int getTextIndent() {
|
||||
|
||||
Reference in New Issue
Block a user