Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbar-Thumb scaling issues #8386

Open
heinrich26 opened this issue Feb 20, 2025 · 0 comments
Open

Scrollbar-Thumb scaling issues #8386

heinrich26 opened this issue Feb 20, 2025 · 0 comments
Labels
bug Self explanatory?

Comments

@heinrich26
Copy link

Describe the bug

hey,

when using a texturepack with a higher resolution, the scrollbar thumb is just drawn as is—without respect to its expected size—breaching its bounds.

I found this in version 1.20.4 (neoforge-17.13.0-beta), but the code suggests it behaves the same in newer versions (this line would need to be changed)
It's quite funny to use, as the hitbox also gets larger.

Example

Image
(Image is fabricated, as I already fixed it at this point and didn't want to redownload the old mod ^^)

Solution

I already came up with a fix, using hardcoded dimensions (which I found kinda "sus", but the Vanilla code did the same, so should be fine 🤷; it does respect UI-Scaling).
There is no PR, because I didn't know on which branch to push my changes for an older version, but I've outlined the changes below. If you want me to push it to somewhere, just give me a notice!

All changes are to Scrollbar.java

I propose the following change to Style:

    public static final Style DEFAULT = Style.create(
            ..., ...,
            12, 15); // hardcoded numbers here

    public static final Style SMALL = Style.create(
            ..., ...,
            7, 15); // hardcoded numbers here

    public record Style(
            ..., ...,
            int width, int height) {
        public static Style create(
                ..., ...,
                int width, int height) { // add new args
            return new Style(enabledSprite, disabledSprite, width, height); // add new args
        }

Additionally, these changes are required to reflect the name-changes in the Style class and to draw the Thumb with the correct size in drawForegroundLayer:

    @Override
    public Rect2i getBounds() {
        return new Rect2i(displayX, displayY, style.width, height); // add the width here
    }

    @Override
    public void drawForegroundLayer(GuiGraphics guiGraphics, Rect2i bounds, Point mouse) {
        ...
        image.dest(this.displayX, this.displayY + yOffset, style.width, style.height).blit(guiGraphics); // respect the expected dimensions here
    }

    private int getHandleYOffset() {
        ...
        int availableHeight = this.height - style.height; // use the new height here
        ...
    }

    @Override
    public boolean onMouseDown(Point mousePos, int button) {
        ...
        } else if (relY < handleYOffset + style.height) { // use the new height here
            ...
        } else {
            ...
        }

        return true;
    }

    @Override
    public boolean onMouseDrag(Point mousePos, int button) {
        ...
        double availableHeight = this.height - style.height; // use the new height here
        ...
    }

Here's a git patch, if that is easier for you
Respect_texture-resolution_in_Scrollbar-Thumb.patch

How to reproduce the bug

Use a resource pack with 2x/4x UI (e.g.: BDcraft 64x)

Expected behavior

Scrollbar thumb gets big and uggly

Additional details

No response

Which minecraft version are you using?

1.20

On which mod loaders does it happen?

NeoForge

Crash log

there is no crash

@heinrich26 heinrich26 added the bug Self explanatory? label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Self explanatory?
Projects
None yet
Development

No branches or pull requests

1 participant