From a89579449dcfa56d171b59e8a7d23da5266b426f Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Mon, 23 Apr 2018 22:38:15 +0300 Subject: [PATCH] IDEA-164920 Wrap toolbar --- .../actionSystem/impl/ActionToolbarImpl.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 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 6cc146735e7f..78da5e9edb16 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 @@ -842,8 +842,22 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct @Override public Dimension getPreferredSize() { final ArrayList bounds = new ArrayList<>(); - calculateBounds(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE), bounds); + calculateBounds(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE), bounds);//it doesn't take into account wrapping if (bounds.isEmpty()) return JBUI.emptySize(); + int forcedHeight = 0; + if (getWidth() > 0 && getLayoutPolicy() == ActionToolbar.WRAP_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL) { + final ArrayList limitedBounds = new ArrayList<>(); + calculateBounds(new Dimension(getWidth(), Integer.MAX_VALUE), limitedBounds); + Rectangle union = null; + for (Rectangle bound : limitedBounds) { + if (union == null) { + union = bound; + } else { + union = union.union(bound); + } + } + forcedHeight = union != null ? union.height : 0; + } int xLeft = Integer.MAX_VALUE; int yTop = Integer.MAX_VALUE; int xRight = Integer.MIN_VALUE; @@ -856,7 +870,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar, QuickAct xRight = Math.max(xRight, each.x + each.width); yBottom = Math.max(yBottom, each.y + each.height); } - final Dimension dimension = new Dimension(xRight - xLeft, yBottom - yTop); + final Dimension dimension = new Dimension(xRight - xLeft, Math.max(yBottom - yTop, forcedHeight)); if (myLayoutPolicy == AUTO_LAYOUT_POLICY && myReservePlaceAutoPopupIcon && !isInsideNavBar()) { if (myOrientation == SwingConstants.HORIZONTAL) {