From 93573017e221bbe1b366e9a6eba02c5d816a29dd Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Fri, 25 May 2018 17:53:31 +0300 Subject: [PATCH] ui: fix rendering of separators with text on toolbar * do not multiply `stringWidth` on HiDPI Linux follow-up: 1e38c3fcb3a2bd2f37d7f4b2878a097f435967e8 --- .../actionSystem/impl/ActionToolbarImpl.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java index 7e4793eedb49..e2da3f137840 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java @@ -983,8 +983,14 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct @Override public Dimension getPreferredSize() { if (myOrientation == SwingConstants.HORIZONTAL) { - int separatorWidth = myText == null ? 0 : getFontMetrics(getFont()).stringWidth(myText) + JBUI.scale(4); - return JBUI.size(7 + separatorWidth, 24); + if (myText != null) { + FontMetrics fontMetrics = getFontMetrics(getFont()); + return new JBDimension(JBUI.scale(9) + fontMetrics.stringWidth(myText) + JBUI.scale(4), + Math.max(fontMetrics.getHeight(), JBUI.scale(24)), true); + } + else { + return JBUI.size(7, 24); + } } else { return JBUI.size(24, 7); @@ -1004,22 +1010,22 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct offset = ActionToolbarImpl.this.getWidth() - getMaxButtonWidth() - 1; } - g.setColor(UIUtil.getSeparatorColor()); - if (myOrientation == SwingConstants.HORIZONTAL) { - int y2 = ActionToolbarImpl.this.getHeight() - gap * 2 - offset; - LinePainter2D.paint((Graphics2D)g, center, gap, center, y2); + g.setColor(UIUtil.getSeparatorColor()); + if (myOrientation == SwingConstants.HORIZONTAL) { + int y2 = ActionToolbarImpl.this.getHeight() - gap * 2 - offset; + LinePainter2D.paint((Graphics2D)g, center, gap, center, y2); - if (myText != null) { - FontMetrics fontMetrics = getFontMetrics(getFont()); - int top = (getHeight() - fontMetrics.getHeight()) / 2; - UISettings.setupAntialiasing(g); - g.setColor(JBColor.foreground()); - g.drawString(myText, JBUI.scale(9), top + fontMetrics.getAscent()); - } - } - else { - LinePainter2D.paint((Graphics2D)g, gap, center, ActionToolbarImpl.this.getWidth() - gap * 2 - offset, center); + if (myText != null) { + FontMetrics fontMetrics = getFontMetrics(getFont()); + int top = (getHeight() - fontMetrics.getHeight()) / 2; + UISettings.setupAntialiasing(g); + g.setColor(JBColor.foreground()); + g.drawString(myText, JBUI.scale(9), top + fontMetrics.getAscent()); } + } + else { + LinePainter2D.paint((Graphics2D)g, gap, center, ActionToolbarImpl.this.getWidth() - gap * 2 - offset, center); + } } }