diff options
Diffstat (limited to 'src/main/java')
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) { } /** |