Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dlemmermann opened this issue Mar 9, 2022 · 3 comments
Open

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

dlemmermann opened this issue Mar 9, 2022 · 3 comments

Comments

@dlemmermann
Copy link

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
Copy link
Author

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
Copy link
Collaborator

FontIcon can only handle sizes in pixels at the moment

iconSize.addListener((v, o, n) -> {
Font font = FontIcon.this.getFont();
if (Math.abs(font.getSize() - n.doubleValue()) >= EPSILON) {
FontIcon.this.setFont(Font.font(font.getFamily(), n.doubleValue()));
FontIcon.this.setStyle(normalizeStyle(getStyle(), "-fx-font-size", n.intValue() + "px"));
}
});

@mkpaz
Copy link

mkpaz commented Feb 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants