kordamp / ikonli

Icon packs for Java applications
http://kordamp.org/ikonli/
Apache License 2.0
496 stars 49 forks source link

Specifying icon size in "em" is not working #150

Open dlemmermann opened 2 years ago

dlemmermann commented 2 years ago

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.

Bildschirmfoto 2022-03-09 um 17 38 40
dlemmermann commented 2 years ago

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;
}
aalmiray commented 2 years ago

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

mkpaz commented 1 year ago

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.

image