aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2019-09-01 00:48:19 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2019-09-01 00:48:19 +0300
commit60ec3fbc34d8266c15aeb1d0be7795efd821d73d (patch)
tree39dc699e9da6c4410e0c5746e3a163077cc67840 /src
parent15707f388229ed62cddc6e95a3b0a9c653afc7a0 (diff)
downloadLibGui-60ec3fbc34d8266c15aeb1d0be7795efd821d73d.tar.gz
LibGui-60ec3fbc34d8266c15aeb1d0be7795efd821d73d.tar.bz2
LibGui-60ec3fbc34d8266c15aeb1d0be7795efd821d73d.zip
Improve scrolling
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java4
4 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index d862b29..26176e7 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -171,7 +171,13 @@ public class CottonClientScreen extends Screen {
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount);
- return description.getRootPanel().onMouseScroll((int) mouseX - left, (int) mouseY - top, amount);
+ WPanel root = description.getRootPanel();
+ WWidget child = root.hit((int) mouseX - left, (int) mouseY - top);
+ if (child == root) return false;
+ // Use root.onMouseScroll to work in cases where the hit result is in a nested panel
+ // and the mouse position can't be moved to the widget space by subtracting the widget's position
+ root.onMouseScroll((int) mouseX - left, (int) mouseY - top, amount);
+ return true;
}
@Override
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index b2d16a7..961d6f9 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -144,7 +144,13 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount);
- return description.getRootPanel().onMouseScroll((int) mouseX - left, (int) mouseY - top, amount);
+ WPanel root = description.getRootPanel();
+ WWidget child = root.hit((int) mouseX - left, (int) mouseY - top);
+ if (child == root) return false;
+ // Use root.onMouseScroll to work in cases where the hit result is in a nested panel
+ // and the mouse position can't be moved to the widget space by subtracting the widget's position
+ root.onMouseScroll((int) mouseX - left, (int) mouseY - top, amount);
+ return true;
}
@Override
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
index 8648ceb..14faa2d 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
@@ -120,10 +120,9 @@ public abstract class WPanel extends WWidget {
}*/
@Override
- public boolean onMouseScroll(int x, int y, double amount) {
- if (children.isEmpty()) return false;
+ public void onMouseScroll(int x, int y, double amount) {
WWidget child = hit(x, y);
- return child != this && child.onMouseScroll(x - child.getX(), y - child.getY(), amount);
+ if (child != this) child.onMouseScroll(x - child.getX(), y - child.getY(), amount);
}
/**
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
index 8362573..e4c5746 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
@@ -110,10 +110,8 @@ public class WWidget {
* @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget)
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @param amount The scrolled amount. Positive values are up and negative values are down.
- * @return true if the scrolling was handled
*/
- public boolean onMouseScroll(int x, int y, double amount) {
- return false;
+ public void onMouseScroll(int x, int y, double amount) {
}
/**