Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,18 @@ private void setup() {
track.widthProperty().unbind();
track.heightProperty().unbind();

double offset = 4;

if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
track.relocate(0, -8);
track.widthProperty().bind(scrollBar.widthProperty());
track.setHeight(8);
track.relocate(offset, -5.0);
NumberBinding trackWidth = Bindings.subtract(scrollBar.widthProperty(), offset * 2);
track.widthProperty().bind(trackWidth);
track.setHeight(5.0);
} else {
track.relocate(-8, 0);
track.setWidth(8);
track.heightProperty().bind(scrollBar.heightProperty());
track.relocate(-5.0, offset);
track.setWidth(5.0);
NumberBinding trackHeight = Bindings.subtract(scrollBar.heightProperty(), offset * 2);
track.heightProperty().bind(trackHeight);
}

thumb.xProperty().unbind();
Expand All @@ -144,15 +148,25 @@ private void setup() {
thumb.heightProperty().unbind();

if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
thumb.relocate(0, -8);
thumb.widthProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(scrollBar.widthProperty())));
thumb.setHeight(8);
thumb.xProperty().bind(Bindings.subtract(scrollBar.widthProperty(), thumb.widthProperty()).multiply(position));
thumb.relocate(0, -5.0);
thumb.setHeight(5.0);

NumberBinding trackWidth = Bindings.subtract(scrollBar.widthProperty(), offset * 2);
thumb.widthProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(trackWidth)));
thumb.xProperty().bind(
Bindings.add(offset,
Bindings.subtract(trackWidth, thumb.widthProperty()).multiply(position))
);
} else {
thumb.relocate(-8, 0);
thumb.setWidth(8);
thumb.heightProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(scrollBar.heightProperty())));
thumb.yProperty().bind(Bindings.subtract(scrollBar.heightProperty(), thumb.heightProperty()).multiply(position));
thumb.relocate(-5.0, 0);
thumb.setWidth(5.0);

NumberBinding trackHeight = Bindings.subtract(scrollBar.heightProperty(), offset * 2);
thumb.heightProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(trackHeight)));
thumb.yProperty().bind(
Bindings.add(offset,
Bindings.subtract(trackHeight, thumb.heightProperty()).multiply(position))
);
}
Comment on lines 150 to 170
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

使用前面定义的 thicknessisHorizontaltrackLength 变量来简化滑块(thumb)的配置,避免重复的逻辑判断和绑定计算。

                if (isHorizontal) {
                    thumb.relocate(0, -thickness);
                    thumb.setHeight(thickness);

                    thumb.widthProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(trackLength)));
                    thumb.xProperty().bind(
                            Bindings.add(offset,
                                    Bindings.subtract(trackLength, thumb.widthProperty()).multiply(position))
                    );
                } else {
                    thumb.relocate(-thickness, 0);
                    thumb.setWidth(thickness);

                    thumb.heightProperty().bind(Bindings.max(20, scrollBar.visibleAmountProperty().divide(range).multiply(trackLength)));
                    thumb.yProperty().bind(
                            Bindings.add(offset,
                                    Bindings.subtract(trackLength, thumb.heightProperty()).multiply(position))
                    );
                }

}

Expand All @@ -162,7 +176,7 @@ protected double computeMaxWidth(double height) {
return Double.MAX_VALUE;
}

return 8;
return 5.0;
}

@Override
Expand All @@ -171,7 +185,7 @@ protected double computeMaxHeight(double width) {
return Double.MAX_VALUE;
}

return 8;
return 5.0;
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions HMCL/src/main/resources/assets/css/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

.scroll-bar .thumb {
-fx-fill: -monet-surface-tint;
-fx-arc-width: 8;
-fx-arc-height: 8;
-fx-arc-width: 4.5;
-fx-arc-height: 4.5;
}

.title-label {
Expand Down