add fine adjustment control for fee rate slider using mouse scroll

This commit is contained in:
Craig Raw 2024-04-18 12:12:40 +02:00
parent 8baa8e2e96
commit c407a41475

View file

@ -13,6 +13,8 @@ import java.util.stream.Collectors;
import static com.sparrowwallet.sparrow.AppServices.*; import static com.sparrowwallet.sparrow.AppServices.*;
public class FeeRangeSlider extends Slider { public class FeeRangeSlider extends Slider {
private static final double FEE_RATE_SCROLL_INCREMENT = 0.01;
public FeeRangeSlider() { public FeeRangeSlider() {
super(0, FEE_RATES_RANGE.size() - 1, 0); super(0, FEE_RATES_RANGE.size() - 1, 0);
setMajorTickUnit(1); setMajorTickUnit(1);
@ -45,6 +47,16 @@ public class FeeRangeSlider extends Slider {
updateMaxFeeRange(newValue.doubleValue()); updateMaxFeeRange(newValue.doubleValue());
} }
}); });
setOnScroll(event -> {
double newFeeRate = getFeeRate() + (event.getDeltaY() > 0 ? FEE_RATE_SCROLL_INCREMENT : -FEE_RATE_SCROLL_INCREMENT);
if(newFeeRate < LONG_FEE_RATES_RANGE.get(0)) {
newFeeRate = LONG_FEE_RATES_RANGE.get(0);
} else if(newFeeRate > LONG_FEE_RATES_RANGE.get(LONG_FEE_RATES_RANGE.size() - 1)) {
newFeeRate = LONG_FEE_RATES_RANGE.get(LONG_FEE_RATES_RANGE.size() - 1);
}
setFeeRate(newFeeRate);
});
} }
public double getFeeRate() { public double getFeeRate() {