Skip to content

Commit

Permalink
Fix Mouse Interactions with Scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Dec 28, 2024
1 parent f9407b9 commit 5212756
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.nomiceu.nomilabs.mixin.betterp2p;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.projecturanus.betterp2p.client.gui.widget.WidgetScrollBar;

/**
* Fixes clicking scrollbar.
*/
@Mixin(value = WidgetScrollBar.class, remap = false)
public abstract class WidgetScrollBarMixin {

@Shadow
protected abstract int getRange();

@Shadow
private int displayX;

@Shadow
private int width;

@Shadow
private int displayY;

@Shadow
private int height;

@Shadow
private int currentScroll;

@Shadow
private int minScroll;

@Shadow
private boolean moving;

@Shadow
protected abstract void applyRange();

@Inject(method = "click", at = @At("HEAD"), cancellable = true)
private void properlyHandleClick(int x, int y, CallbackInfo ci) {
ci.cancel();
if (getRange() == 0) {
return;
}

if (y > displayY && y <= displayY + height) {
if (x > displayX && x <= displayX + width) {
currentScroll = y - displayY;
currentScroll = minScroll + currentScroll * 2 * getRange() / height;
currentScroll = (currentScroll + 1) >> 1;
applyRange();
moving = true;
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.nomilabs.betterp2p.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"RenderHandlerMixin",
"WidgetP2PColumnMixin",
"WidgetP2PDeviceMixin",
"WidgetScrollBarMixin",
"WidgetTypeSelectorMixin"
],
"server": []
Expand Down

0 comments on commit 5212756

Please sign in to comment.