Skip to content

Commit a6e0acc

Browse files
authored
在滚动条处于按下状态时保持不透明状态 (HMCL-dev#6366)
1 parent 3d312f9 commit a6e0acc

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FloatScrollBarSkin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import javafx.animation.KeyValue;
2424
import javafx.animation.Timeline;
2525
import javafx.beans.binding.Bindings;
26+
import javafx.beans.binding.BooleanBinding;
2627
import javafx.beans.binding.NumberBinding;
27-
import javafx.beans.value.ChangeListener;
2828
import javafx.geometry.Orientation;
2929
import javafx.geometry.Point2D;
3030
import javafx.scene.Node;
@@ -43,11 +43,10 @@
4343
public class FloatScrollBarSkin implements Skin<ScrollBar> {
4444
private ScrollBar scrollBar;
4545
private Region group;
46-
private Rectangle track = new Rectangle();
47-
private Rectangle thumb = new Rectangle();
46+
private final Rectangle track = new Rectangle();
47+
private final Rectangle thumb = new Rectangle();
4848

49-
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"})
50-
private ChangeListener<Boolean> thumbHoverListener;
49+
private BooleanBinding hoverOrPressed;
5150
private Animation thumbHoverAnimation;
5251

5352
public FloatScrollBarSkin(final ScrollBar scrollBar) {
@@ -214,7 +213,8 @@ protected double computeMaxHeight(double width) {
214213
}
215214
};
216215

217-
this.thumbHoverListener = FXUtils.onWeakChangeAndOperate(thumb.hoverProperty(), newValue -> {
216+
this.hoverOrPressed = thumb.hoverProperty().or(thumb.pressedProperty());
217+
FXUtils.onChangeAndOperate(hoverOrPressed, newValue -> {
218218
if (thumbHoverAnimation != null) {
219219
thumbHoverAnimation.stop();
220220
thumbHoverAnimation = null;
@@ -249,7 +249,7 @@ public void dispose() {
249249
thumbHoverAnimation.stop();
250250
thumbHoverAnimation = null;
251251
}
252-
thumbHoverListener = null;
252+
hoverOrPressed = null;
253253
scrollBar = null;
254254
group = null;
255255
}

0 commit comments

Comments
 (0)