Skip to content

Commit 89496db

Browse files
committed
feat(javafx): Let icon units be specified
Closes #150
1 parent fc56a22 commit 89496db

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

core/ikonli-javafx/src/main/java/org/kordamp/ikonli/javafx/FontIcon.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import javafx.beans.property.IntegerProperty;
2121
import javafx.beans.property.ObjectProperty;
22+
import javafx.beans.property.SimpleStringProperty;
23+
import javafx.beans.property.StringProperty;
2224
import javafx.css.CssMetaData;
2325
import javafx.css.StyleOrigin;
2426
import javafx.css.Styleable;
@@ -53,6 +55,7 @@ public class FontIcon extends Text implements Icon {
5355
protected StyleableIntegerProperty iconSize;
5456
protected StyleableObjectProperty<Paint> iconColor;
5557
private StyleableObjectProperty<Ikon> iconCode;
58+
private final StringProperty units;
5659

5760
public FontIcon() {
5861
getStyleClass().setAll("ikonli-font-icon");
@@ -87,6 +90,8 @@ public FontIcon() {
8790
}
8891
}
8992
});
93+
94+
units = new SimpleStringProperty("px");
9095
}
9196

9297
public FontIcon(String iconCode) {
@@ -99,6 +104,10 @@ public FontIcon(Ikon iconCode) {
99104
setIconCode(iconCode);
100105
}
101106

107+
public StringProperty unitsProperty() {
108+
return units;
109+
}
110+
102111
@Override
103112
public String toString() {
104113
Ikon iconCode = getIconCode();
@@ -133,13 +142,18 @@ public StyleOrigin getStyleOrigin() {
133142
Font font = FontIcon.this.getFont();
134143
if (Math.abs(font.getSize() - n.doubleValue()) >= EPSILON) {
135144
FontIcon.this.setFont(Font.font(font.getFamily(), n.doubleValue()));
136-
FontIcon.this.setStyle(normalizeStyle(getStyle(), "-fx-font-size", n.intValue() + "px"));
145+
FontIcon.this.setStyle(normalizeStyle(getStyle(), "-fx-font-size", n.intValue() + resolveUnits()));
137146
}
138147
});
139148
}
140149
return iconSize;
141150
}
142151

152+
private String resolveUnits() {
153+
String u = units.get();
154+
return null == u || u.isBlank() ? "px" : u;
155+
}
156+
143157
@Override
144158
public ObjectProperty<Paint> iconColorProperty() {
145159
if (iconColor == null) {

docs/guide/src/docs/asciidoc/usage.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ di-java:32
8585
di-java:64:BLUE
8686
----
8787

88+
.Icon Size Units
89+
90+
The default unit for icon size is _px_. You may set a different value using the `units` property, such as _em_.
91+
8892
.Stylable Properties
8993

9094
`{api_link_fonticon_javafx}` exposes properties that can be styled using CSS. It defines a node class named `ikonli-font-icon`.

0 commit comments

Comments
 (0)