Browse Source

Fixed button content overlapping border. Fixes #148

pull/154/head
weisj 5 years ago
parent
commit
c301049450
  1. 29
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java
  2. 21
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

29
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java

@ -199,36 +199,31 @@ public class DarkButtonBorder implements Border, UIResource {
boolean paintLeft = DarkUIUtil.hasFocus(left);
if (paintLeft) {
int h = height - Math.max(0, getShadowSize(left) - borderSize);
int arc = getFocusArc(left);
g2.translate(-2 * borderSize, 0);
PaintUtil.paintLineBorder(g2, -borderSize, borderSize, 3 * borderSize, h, arc);
PaintUtil.paintFocusBorder(g2, 3 * borderSize, h, arc, borderSize);
g2.translate(2 * borderSize, 0);
g2.translate(-3 * borderSize + 1, 0);
PaintUtil.paintFocusBorder(g2, 4 * borderSize, h, getFocusArc(left), borderSize);
g2.translate(-(-3 * borderSize + 1), 0);
}
JComponent right = ButtonConstants.getNeighbour(DarkButtonUI.KEY_RIGHT_NEIGHBOUR, c);
boolean paintRight = DarkUIUtil.hasFocus(right);
g2.setColor(focusBorderColor);
if (paintRight) {
int h = height - Math.max(0, getShadowSize(right) - borderSize);
g2.translate(width - borderSize, 0);
PaintUtil.paintFocusBorder(g2, 3 * borderSize, h, getFocusArc(right), borderSize);
g2.translate(borderSize - width, 0);
g2.translate(width - borderSize - 1, 0);
PaintUtil.paintFocusBorder(g2, 4 * borderSize, h, getFocusArc(right), borderSize);
g2.translate(-(width - borderSize - 1), 0);
}
JComponent top = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_NEIGHBOUR, c);
boolean paintTop = DarkUIUtil.hasFocus(top);
if (paintTop) {
g2.translate(0, -2 * borderSize);
PaintUtil.paintFocusBorder(g2, width, 3 * borderSize,
getFocusArc(top), borderSize);
g2.translate(0, 2 * borderSize);
g2.translate(0, -3 * borderSize + 1);
PaintUtil.paintFocusBorder(g2, width, 4 * borderSize, getFocusArc(top), borderSize);
g2.translate(0, -(-3 * borderSize + 1));
}
JComponent bottom = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_NEIGHBOUR, c);
boolean paintBottom = DarkUIUtil.hasFocus(bottom);
if (paintBottom) {
g2.translate(0, height - borderSize);
PaintUtil.paintFocusBorder(g2, width, 3 * borderSize,
getFocusArc(bottom), borderSize);
g2.translate(0, borderSize - height);
g2.translate(0, height - borderSize - 1);
PaintUtil.paintFocusBorder(g2, width, 4 * borderSize, getFocusArc(bottom), borderSize);
g2.translate(0, -(height - borderSize - 1));
}
}

21
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -149,17 +149,6 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
ToggleButtonFocusNavigationActions.uninstallActions(b);
}
@Override
public void update(final Graphics g, final JComponent c) {
super.update(g, c);
boolean isDefaultButton = ButtonConstants.isDefaultButton(c) && !SystemInfo.isMac;
if (isDefaultButton && !c.getFont().isBold()) {
c.setFont(c.getFont().deriveFont(Font.BOLD));
} else if (!isDefaultButton && c.getFont().isBold()) {
c.setFont(c.getFont().deriveFont(Font.PLAIN));
}
}
@Override
public void paint(final Graphics g, final JComponent c) {
GraphicsContext config = new GraphicsContext(g);
@ -391,14 +380,14 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
}
AlignmentExt corner = DarkButtonBorder.getCornerFlag(c);
Insets insetMask = new Insets(borderSize, borderSize, borderSize, borderSize);
if (corner != null) {
Insets insetMask = new Insets(borderSize, borderSize, borderSize, borderSize);
insetMask = corner.maskInsetsInverted(insetMask, 0);
i.left -= insetMask.left;
i.right -= insetMask.right;
i.top -= insetMask.top;
i.bottom -= insetMask.bottom;
}
i.left -= insetMask.left;
i.right -= insetMask.right;
i.top -= insetMask.top;
i.bottom -= insetMask.bottom;
viewRect.x = i.left;
viewRect.y = i.top;

Loading…
Cancel
Save