kordamp / ikonli

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

Re-draw issue on scaling #133

Open lanthale opened 3 years ago

lanthale commented 3 years ago

I have in my PhotoSlide app a zoom slider for the gridview. The zoom slider increases the size of the stackpanes where inside icons are added. During zoom the icon represantation is changed to the stanard one (menu buttton) and than back to the given icon. This is only happening during the zoom. What I mean you drag the slider and the stackpanes are increased and redrawn. During this process the burger icon is shown for the icons used and after the zoom finishes the icons are back as before.

It is a very small issue but the user sees it which is bad. Thank you for your help in advance. Clemens

aalmiray commented 3 years ago

I'm afraid I don't quite follow what's the problem.

  1. During zoom an icon changes to a different shape/glyph but comes back to the original shape/glyph when zoom stops.
  2. During zoom an icon changes size but comes back to the original size when zoom stops.
lanthale commented 3 years ago

The issue is that during zoom the icon changes to a default glyph and at the end of the zoom the defined glyph is shown.

Point 2 from your explaination

JonathanVusich commented 3 years ago

@aalmiray I have also run into the issue when using these icons in a JavaFX TableView. The icons looks like a rectangle while scrolling, but are drawn correctly when the scrolling stops. It only happens when the scrolling is quite fast, such as dragging the scroll slider around. Still kind of an annoying bug.

johantiden commented 1 year ago

I get the same behavior when refreshing a TableView with new (identical) content, re-initializing the icons. The burger glyph shows up momentarily, causing all icons in the table to flicker.

It would be better if the default glyph was empty so that at least it isn't larger than my other icons. I would rather have them flicker "to transparent" than to a big white blob.

johantiden commented 1 year ago

https://github.com/kordamp/ikonli/assets/22770524/6d931f55-fad1-443f-a365-eff0aa320ac5

johantiden commented 1 year ago

I can reproduce it by:

https://github.com/kordamp/ikonli/assets/22770524/6e04fa8e-1ade-48eb-930b-a4576bd277c4

johantiden commented 1 year ago

If I set a breakpoint in the iconSize listener at FontIcon:131, I can see the default behavior frozen in the gui, until the pulse is completed. Notice the stack trace comes from the css processor image

johantiden commented 1 year ago

To be fair, the flickering is there even if I just use a Text instead of FontIcon.

My workaround for now will be to use a Text directly, it doesn't produce the box when the font isn't setup yet, resulting in an "empty" icon until loaded:

    public static Node createIcon(String code, int fontSize, Color white) {
        return createIcon(resolve(code), fontSize, white);
    }

    public static Node createIcon(Ikon ikon, int fontSize, Color color) {
        Text text = new Text(getIconCode(ikon));
        text.setFont(Font.font("Material Design Icons", fontSize));
        text.setFill(color);
        return  text;
    }

    private static Ikon resolve(String ikon) {
        return IkonResolver.getInstance().resolve(ikon).resolve(ikon);
    }

    // Copy pasted from org.kordamp.ikonli.javafx.FontIcon
    public static String getIconCode(Ikon ikon) {
        int code = ikon.getCode();
        if (code <= '\uFFFF') {
            return String.valueOf((char) code);
        } else {
            char[] charPair = Character.toChars(code);
            return new String(charPair);
        }
    }