ikonli
ikonli copied to clipboard
Specifying icon size in "em" is not working
The only "em" size that works is "1em". If I specify a number smaller than 1 then the icon does not show up at all. If I specify a number larger than 1 then I can see the icon quickly grow bigger and bigger until it disappears. The attached screenshot shows an intermediate step of this growth process.

If you want to try it yourself simply clone my "GemsFX" project and run TagFieldApp after changing this rule:
.tags-field .graphic-wrapper .ikonli-font-icon {
-fx-icon-size: 1.0em;
-fx-icon-color: -fx-text-background-color;
}
FontIcon
can only handle sizes in pixels at the moment
https://github.com/kordamp/ikonli/blob/f73e0aa6bde3fdbd291d2c26752f746ff6e2ec25/core/ikonli-javafx/src/main/java/org/kordamp/ikonli/javafx/FontIcon.java#L130-L136
I think it's a bug and the problem is here:
FontIcon.this.setFont(Font.font(font.getFamily(), n.doubleValue()));
FontIcon.this.setStyle(normalizeStyle(getStyle(), "-fx-font-size", n.intValue() + "px"));
It's sets the font size twice and the second line forces size listener to call itself recursively. Just removing it is enough to fix the issue, because iconSize
styleable property already uses SizeConverter
which is capable to parse all supported SizeUnits
including em
.
To workaround this simply extend FontIcon
and remove this line. Seems like everything works to me.