HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
694 stars 131 forks source link

Gauge doesn't display current value after rapid update with animation #197

Closed mcarlin closed 4 years ago

mcarlin commented 4 years ago

Description

I'm encountering an issue with setting gauge values quickly with animation. It results in the gauge displaying a old value while under the hood containing the correct currentValue. However, if I disable animation the issue isn't encountered any longer. Is there something I'm doing incorrectly?

Environment

I've tried the two following environments and seen the issue in both:

First

Second

Demonstration

Here are the two relevant snippets.

 Gauge progressGauge = GaugeBuilder.create()
                                           .skinType(Gauge.SkinType.BAR)
                                           .barColor(Color.DEEPSKYBLUE)
//                                           .animated(false) // without animation it all works, with animation enabled the issue is experienced
                                           .build();

SimpleDoubleProperty value = new SimpleDoubleProperty(100);
progressGauge.valueProperty().bind(value);

And

new Thread(() -> {
    try {
         Platform.runLater(() -> value.set(100)); // ensure we start at 100
         Thread.sleep(2000);
         Platform.runLater(() -> value.set(50));
         Thread.sleep(20);
         Platform.runLater(() -> value.set(1));
    }
    catch (InterruptedException ignore) {}
}.start()

Here's a repo demonstrating the issue: https://github.com/mcarlin/MedusaIssue

And a gif demonstrating the behavior:

HanSolo commented 4 years ago

That is exactly what I was expecting. So the animation should only be used for slow changing values, if the values changing fast you should switch animated=false. You could try to reduce the animationPeriod which is set to 800 ms as a default. But when changing values faster the animated property should usually be switched off.