Browse Source

Changed clear icon for search variant.

Fixed border opacity for search variant.
pull/15/head
weisj 5 years ago
parent
commit
f15d0ae50b
  1. 5
      src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java
  2. 17
      src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java
  3. 3
      src/main/resources/com/weis/darklaf/properties/ui/text.properties

5
src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java

@ -44,8 +44,7 @@ public class DarkTextBorder implements Border, UIResource {
g.setColor(DarkTextFieldUI.getBorderColor(c));
if (((JComponent) c).getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) {
if (c.hasFocus()) {
DarkUIUtil.paintOutlineBorder(g, width, height, arcSize, true,
true, DarkUIUtil.Outline.focus);
DarkUIUtil.paintFocusBorder(g, width, height, arcSize, true);
}
g.setColor(DarkTextFieldUI.getBorderColor(c));
DarkUIUtil.paintLineBorder(g, BORDER_SIZE, BORDER_SIZE, width - 2 * BORDER_SIZE,
@ -62,7 +61,7 @@ public class DarkTextBorder implements Border, UIResource {
BORDER_SIZE + PADDING, BORDER_SIZE + PADDING);
if (DarkTextFieldUI.isSearchField(c)) {
int searchWidth = DarkTextFieldUI.getSearchIcon(c).getIconWidth();
int clearWidth = DarkTextFieldUI.getClearIcon().getIconWidth();
int clearWidth = DarkTextFieldUI.getClearIcon(false).getIconWidth();
insets.left += PADDING + searchWidth;
insets.right += PADDING + clearWidth;
} else if (DarkPasswordFieldUI.hasShowIcon(c)) {

17
src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java

@ -66,6 +66,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
lastSearchEvent = System.currentTimeMillis();
}
};
private boolean clearHovered;
@NotNull
@Contract("_ -> new")
@ -81,8 +82,9 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
}
@Contract(pure = true)
public static Icon getClearIcon() {
return UIManager.getIcon("TextField.search.clear.icon");
public static Icon getClearIcon(final boolean clearHovered) {
return clearHovered ? UIManager.getIcon("TextField.search.clearHover.icon")
: UIManager.getIcon("TextField.search.clear.icon");
}
public static Color getBorderColor(@NotNull final Component c) {
@ -130,6 +132,11 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
private void updateCursor(final Point p) {
var action = getActionUnder(p);
boolean oldClear = clearHovered;
clearHovered = action == ClickAction.CLEAR;
if (oldClear != clearHovered) {
editor.repaint();
}
var drawRect = getDrawingRect(getComponent());
var textRect = getTextRect(getComponent());
int rightBoundary = getComponent().getText().isEmpty()
@ -210,7 +217,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
private void paintClearIcon(final Graphics2D g) {
Point p = getClearIconCoord();
getClearIcon().paintIcon(null, g, p.x, p.y);
getClearIcon(clearHovered).paintIcon(null, g, p.x, p.y);
}
private void paintSearchIcon(final Graphics2D g) {
@ -220,14 +227,14 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
protected Point getClearIconCoord() {
Rectangle r = getDrawingRect(getComponent());
int w = getClearIcon().getIconWidth();
int w = getClearIcon(clearHovered).getIconWidth();
return new Point(r.x + r.width - w - DarkTextBorder.PADDING, r.y + (r.height - w) / 2);
}
private ClickAction getActionUnder(final Point p) {
var c = getComponent();
if (isSearchField(c)) {
if (isOver(getClearIconCoord(), getClearIcon(), p)) {
if (isOver(getClearIconCoord(), getClearIcon(clearHovered), p)) {
return ClickAction.CLEAR;
}
if (isOver(getSearchIconCoord(), getSearchIcon(c), p)) {

3
src/main/resources/com/weis/darklaf/properties/ui/text.properties

@ -46,4 +46,5 @@ PasswordField.show.icon = navigation/eye.svg[dual]
PasswordField.showPressed.icon = navigation/eye.svg[aware]
TextField.search.searchWithHistory.icon = navigation/searchWithHistory.svg[aware]
TextField.search.search.icon = navigation/search.svg[aware]
TextField.search.clear.icon = navigation/clear.svg[aware](12,12)
TextField.search.clear.icon = navigation/close.svg[aware]
TextField.search.clearHover.icon = navigation/closeHovered.svg[aware]
Loading…
Cancel
Save