Skip to content

优化 ScrollBar 样式#5784

Open
CiiLu wants to merge 4 commits intoHMCL-dev:mainfrom
CiiLu:scroll
Open

优化 ScrollBar 样式#5784
CiiLu wants to merge 4 commits intoHMCL-dev:mainfrom
CiiLu:scroll

Conversation

@CiiLu
Copy link
Copy Markdown
Contributor

@CiiLu CiiLu commented Mar 13, 2026

感觉有点过于圆+粗了

@Calboot
Copy link
Copy Markdown
Contributor

Calboot commented Mar 14, 2026

恭喜你,你成功的 reverse 了 #5716

之前调粗是为了防止被吞圆角,比如

image

这里你调细就会出问题

不幸的是,我没有在 m3 中找到任何滚动条的描述


当然,也有一种解决办法是让它不要顶到头上

另外如果你执意要这么改的话建议改成 4,因为原来就是 4(

@CiiLu CiiLu marked this pull request as draft March 15, 2026 01:37
@CiiLu CiiLu marked this pull request as ready for review April 5, 2026 12:50
@Glavo
Copy link
Copy Markdown
Member

Glavo commented Apr 5, 2026

/gemini review

@Glavo
Copy link
Copy Markdown
Member

Glavo commented Apr 5, 2026

我感觉改之后又有点太细了(可能是习惯了新的样式),我感觉还是粗一点容易操控。

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adjusts the scroll bar's appearance by reducing its thickness from 8 to 4.5 and introducing a layout offset. The changes affect both the Java skin implementation and the CSS styling. Feedback suggests improving code maintainability by replacing hardcoded values with constants or variables and refactoring redundant binding logic for the track and thumb components to reduce duplication.

Comment on lines 150 to 170
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, -4.5);
thumb.setHeight(4.5);

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(-4.5, 0);
thumb.setWidth(4.5);

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))
);
}
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))
                    );
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants