Browse Source

Tooltip: Correct shadow size insets for top alignment.

pull/235/head
weisj 4 years ago
parent
commit
cbf0260358
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 7
      core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java
  2. 17
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java
  3. 14
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java

7
core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java

@ -366,8 +366,11 @@ public class ToolTipContext {
public void updateToolTip() { public void updateToolTip() {
if (toolTip != null) { if (toolTip != null) {
toolTip.putClientProperty(DarkToolTipUI.KEY_POINTER_LOCATION, toolTip.putClientProperty(DarkToolTipUI.KEY_POINTER_LOCATION,
alignment == Alignment.CENTER ? centerAlignment.opposite() alignment == Alignment.CENTER
: alignInside ? alignment : alignment.opposite()); ? centerAlignment.opposite()
: alignInside
? alignment
: alignment.opposite());
toolTip.putClientProperty(DarkToolTipUI.KEY_INSETS, insets); toolTip.putClientProperty(DarkToolTipUI.KEY_INSETS, insets);
toolTip.doLayout(); toolTip.doLayout();
} }

17
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java

@ -55,9 +55,10 @@ public class DarkToolTipUI extends BasicToolTipUI
boolean inside = isInside(e); boolean inside = isInside(e);
if (!inside) { if (!inside) {
ToolTipManager.sharedInstance() ToolTipManager.sharedInstance()
.mouseExited(new MouseEvent(toolTip.getComponent(), e.getID(), e.getWhen(), e.getModifiersEx(), .mouseExited(new MouseEvent(
Integer.MIN_VALUE, Integer.MIN_VALUE, e.getClickCount(), e.isPopupTrigger(), toolTip.getComponent(), e.getID(), e.getWhen(),
e.getButton())); e.getModifiersEx(), Integer.MIN_VALUE, Integer.MIN_VALUE,
e.getClickCount(), e.isPopupTrigger(), e.getButton()));
} }
} }
}; };
@ -77,8 +78,11 @@ public class DarkToolTipUI extends BasicToolTipUI
if (p.y == c.getHeight()) p.y--; if (p.y == c.getHeight()) p.y--;
p.x = Math.max(p.x, 0); p.x = Math.max(p.x, 0);
p.y = Math.max(p.y, 0); p.y = Math.max(p.y, 0);
ToolTipManager.sharedInstance().mouseEntered(new MouseEvent(c, e.getID(), e.getWhen(), e.getModifiersEx(), ToolTipManager.sharedInstance()
p.x, p.y, e.getClickCount(), e.isPopupTrigger(), e.getButton())); .mouseEntered(new MouseEvent(
c, e.getID(), e.getWhen(),
e.getModifiersEx(), p.x, p.y,
e.getClickCount(), e.isPopupTrigger(), e.getButton()));
} }
@Override @Override
@ -209,7 +213,10 @@ public class DarkToolTipUI extends BasicToolTipUI
Insets insets = c.getInsets(); Insets insets = c.getInsets();
Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right), Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right),
size.height - (insets.top + insets.bottom)); size.height - (insets.top + insets.bottom));
Rectangle r = new Rectangle(paintTextR);
StringPainter.drawString(g, c, tipText, paintTextR); StringPainter.drawString(g, c, tipText, paintTextR);
g.setColor(Color.GREEN);
PaintUtil.drawRect(g, r);
} }
} }

14
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java

@ -99,7 +99,7 @@ public class DarkTooltipBorder implements Border, AlignableTooltipBorder {
} else if (align == Alignment.WEST) { } else if (align == Alignment.WEST) {
si.left -= pointerSize; si.left -= pointerSize;
} else if (align.isNorth()) { } else if (align.isNorth()) {
si.top = 0; si.top -= pointerSize;
} }
} }
@ -147,14 +147,10 @@ public class DarkTooltipBorder implements Border, AlignableTooltipBorder {
Insets ins = new Insets(0, 0, 0, 0); Insets ins = new Insets(0, 0, 0, 0);
Insets bi = bubbleBorder.getBorderInsets(c); Insets bi = bubbleBorder.getBorderInsets(c);
Insets si = shadowBorder.getBorderInsets(c); Insets si = shadowBorder.getBorderInsets(c);
ins.bottom = Math.max(bi.bottom, si.bottom); ins.bottom = Math.max(bi.bottom, si.bottom) + uIns.bottom;
ins.left = Math.max(bi.left, si.left); ins.left = Math.max(bi.left, si.left) + uIns.left;
ins.right = Math.max(bi.right, si.right); ins.right = Math.max(bi.right, si.right) + uIns.right;
ins.top = Math.max(bi.top, si.top); ins.top = Math.max(bi.top, si.top) + uIns.top;
ins.left += uIns.left;
ins.top += uIns.top;
ins.right += uIns.right;
ins.bottom += uIns.bottom;
return ins; return ins;
} }

Loading…
Cancel
Save