ikonli icon indicating copy to clipboard operation
ikonli copied to clipboard

Specifying icon size in "em" is not working

Open dlemmermann opened this issue 2 years ago • 3 comments

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 avatar Mar 09 '22 16:03 dlemmermann

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;
}

dlemmermann avatar Mar 09 '22 16:03 dlemmermann

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

aalmiray avatar Mar 11 '22 20:03 aalmiray

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

mkpaz avatar Feb 23 '23 17:02 mkpaz