Skip to content

Commit

Permalink
[core] Fix mouse scroll in ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper committed Aug 1, 2024
1 parent 672ab6a commit ba4ff63
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/br/nullexcept/mux/widget/ScrollView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class ScrollView extends ViewGroup {
private final double[] scroll = new double[2];
private final Point space = new Point();
private final Point pixelScroll = new Point();
private final Point downMousePosition = new Point();
private final ScrollContainer container;
private Drawable scrollDrawable = new ColorDrawable(Color.GREEN);
private final Point mouseScroll = new Point();
private boolean capturedMouseScroll = true;
private final Rect scrollbar = new Rect();
private long lastMouseEvent;

public ScrollView(Context context) {
super(context);
Expand Down Expand Up @@ -81,11 +83,17 @@ protected boolean dispatchMouseEvent(MouseEvent mouseEvent) {
mouseEvent.setTarget(hashCode());
return true;
}
} else if (mouseEvent.getTarget() == hashCode()) {
double percent = mouseEvent.getY() / getMeasuredHeight();
} else if (mouseEvent.getTarget() == hashCode() && mouseEvent.getAction() == MotionEvent.ACTION_DOWN) {
if (lastMouseEvent != mouseEvent.getDownTime()) {
lastMouseEvent = mouseEvent.getDownTime();
downMousePosition.set((scrollbar.height()-((int) mouseEvent.getY()-scrollbar.top)), (int) mouseEvent.getY()-scrollbar.top);
return true;
}
double percent = (mouseEvent.getY()) / (getMeasuredHeight()-downMousePosition.x);
percent = Math.max(0, Math.min(1.0, percent));
scroll[1] = percent;
measureContent();
measureContent();
return true;
}

Expand Down

0 comments on commit ba4ff63

Please sign in to comment.