From e7d1b01e4e8d1dc6fc9731a51f7e2b815d6558de Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 15 Mar 2020 22:40:57 +0100 Subject: [PATCH] Fixed layout for square icon only buttons. --- .../weisj/darklaf/ui/button/DarkButtonUI.java | 16 +++++++++------- .../darklaf/properties/ui/button.properties | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index 2f18789f..40e0e655 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java @@ -222,17 +222,19 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); + if (isSquare(c) && isIconOnly(b)) { + int size = Math.min(viewRect.width, viewRect.height); + viewRect.width = viewRect.height = size; + } textRect.x = textRect.y = textRect.width = textRect.height = 0; iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; - // layout the text and icon - return SwingUtilities.layoutCompoundLabel( - b, fm, b.getText(), b.getIcon(), - b.getVerticalAlignment(), b.getHorizontalAlignment(), - b.getVerticalTextPosition(), b.getHorizontalTextPosition(), - viewRect, iconRect, textRect, - b.getText() == null ? 0 : b.getIconTextGap()); + return SwingUtilities.layoutCompoundLabel(b, fm, b.getText(), b.getIcon(), + b.getVerticalAlignment(), b.getHorizontalAlignment(), + b.getVerticalTextPosition(), b.getHorizontalTextPosition(), + viewRect, iconRect, textRect, + b.getText() == null || isIconOnly(b) ? 0 : b.getIconTextGap()); } protected void paintText(final Graphics g, final AbstractButton b, final JComponent c, final String text) { diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties index fb580422..783e0f9d 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties @@ -48,7 +48,7 @@ Button.borderThickness = %borderThickness Button.shadowHeight = %shadowHeight Button.rolloverEnabled = false -Button.borderInsets = 6,16,7,16 +Button.borderInsets = 7,16,7,16 Button.thinBorderInsets = 4,8,4,8 Button.squareThinBorderInsets = 4,4,4,4 Button.squareBorderInsets = 6,6,6,6