aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-04-15 16:06:32 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-04-15 16:06:32 +0300
commit35174a9af664d5eedc8d89a82be120c4ac6119fa (patch)
tree84548fca8dde668dcde96737d2b0c939a04f292d
parent99464faaa1af676ded58f2719bf15e71db274678 (diff)
downloadLibGui-35174a9af664d5eedc8d89a82be120c4ac6119fa.tar.gz
LibGui-35174a9af664d5eedc8d89a82be120c4ac6119fa.tar.bz2
LibGui-35174a9af664d5eedc8d89a82be120c4ac6119fa.zip
Add Environment annotations to interaction methods
Should fix #41.
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java7
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java1
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java1
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java10
8 files changed, 41 insertions, 9 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index 7d19288..b5e1344 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -105,6 +105,7 @@ public abstract class WAbstractSlider extends WWidget {
return true;
}
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseDown(int x, int y, int button) {
// Check if cursor is inside or <=2px away from track
@@ -114,6 +115,7 @@ public abstract class WAbstractSlider extends WWidget {
return super.onMouseDown(x, y, button);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseDrag(int x, int y, int button) {
if (isFocused()) {
@@ -122,6 +124,7 @@ public abstract class WAbstractSlider extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
moveSlider(x, y);
@@ -136,6 +139,7 @@ public abstract class WAbstractSlider extends WWidget {
if (value != previousValue) onValueChanged(value);
}
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
dragging = false;
@@ -143,6 +147,7 @@ public abstract class WAbstractSlider extends WWidget {
return super.onMouseUp(x, y, button);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseScroll(int x, int y, double amount) {
int previous = value;
@@ -245,6 +250,7 @@ public abstract class WAbstractSlider extends WWidget {
if (valueChangeListener != null) valueChangeListener.accept(value);
}
+ @Environment(EnvType.CLIENT)
@Override
public void onKeyPressed(int ch, int key, int modifiers) {
boolean valueChanged = false;
@@ -272,6 +278,7 @@ public abstract class WAbstractSlider extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onKeyReleased(int ch, int key, int modifiers) {
if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch) || isIncreasingKey(ch))) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index fbf664d..a03bd2a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -2,6 +2,8 @@ package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Alignment;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.sound.PositionedSoundInstance;
@@ -66,7 +68,8 @@ public class WButton extends WWidget {
public void setSize(int x, int y) {
super.setSize(x, 20);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
super.onClick(x, y, button);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index 75b102f..9163d4f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -88,6 +88,7 @@ public class WLabel extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
Text hoveredText = getTextAt(x, y);
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 373479b..e7bdeab 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
@@ -86,7 +86,8 @@ public abstract class WPanel extends WWidget {
int pushDown = w.getY()+w.getHeight();
this.setSize(Math.max(this.getWidth(), pushRight), Math.max(this.getHeight(), pushDown));
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
if (children.isEmpty()) return super.onMouseUp(x, y, button);
@@ -101,7 +102,8 @@ public abstract class WPanel extends WWidget {
}
return super.onMouseUp(x, y, button);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseDown(int x, int y, int button) {
if (children.isEmpty()) return super.onMouseDown(x, y, button);
@@ -116,7 +118,8 @@ public abstract class WPanel extends WWidget {
}
return super.onMouseDown(x, y, button);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseDrag(int x, int y, int button) {
if (children.isEmpty()) return;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java
index 0d67d00..152bf2f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java
@@ -3,6 +3,8 @@ package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.LibGuiClient;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Axis;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
public class WScrollBar extends WWidget {
protected Axis axis = Axis.HORIZONTAL;
@@ -150,12 +152,14 @@ public class WScrollBar extends WWidget {
sliding = true;
return this;
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onMouseDrag(int x, int y, int button) {
adjustSlider(x, y);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
//TODO: Clicking before or after the handle should jump instead of scrolling
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
index 9761a6d..ab9333b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
@@ -95,6 +95,7 @@ public class WText extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
if (button != 0) return; // only left clicks
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
index 97023aa..8f5c5c1 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
@@ -529,13 +529,15 @@ public class WTextField extends WWidget {
renderButton(x, y);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
requestFocus();
cursor = getCaretPos(this.text, x-OFFSET_X_TEXT);
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onCharTyped(char ch) {
if (this.text.length()<this.maxLength) {
@@ -553,7 +555,8 @@ public class WTextField extends WWidget {
public void insertText(int ofs, String s) {
//TODO: Implement
}
-
+
+ @Environment(EnvType.CLIENT)
@Override
public void onKeyPressed(int ch, int key, int modifiers) {
if (!this.editable) return;
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 8c229fc..73edba6 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
@@ -134,6 +134,7 @@ public class WWidget {
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @param button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
*/
+ @Environment(EnvType.CLIENT)
public WWidget onMouseDown(int x, int y, int button) {
return this;
}
@@ -151,6 +152,7 @@ public class WWidget {
*
* @since 1.5.0
*/
+ @Environment(EnvType.CLIENT)
public void onMouseDrag(int x, int y, int button, double deltaX, double deltaY) {
onMouseDrag(x, y, button);
}
@@ -161,6 +163,7 @@ public class WWidget {
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @param button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
*/
+ @Environment(EnvType.CLIENT)
public void onMouseDrag(int x, int y, int button) {
}
@@ -170,6 +173,7 @@ public class WWidget {
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @param button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
*/
+ @Environment(EnvType.CLIENT)
public WWidget onMouseUp(int x, int y, int button) {
return this;
}
@@ -180,6 +184,7 @@ public class WWidget {
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @param button The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
*/
+ @Environment(EnvType.CLIENT)
public void onClick(int x, int y, int button) {
}
@@ -189,6 +194,7 @@ public class WWidget {
* @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.
*/
+ @Environment(EnvType.CLIENT)
public void onMouseScroll(int x, int y, double amount) {
}
@@ -199,6 +205,7 @@ public class WWidget {
* @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
* @since 1.5.0
*/
+ @Environment(EnvType.CLIENT)
public void onMouseMove(int x, int y) {
}
@@ -207,6 +214,7 @@ public class WWidget {
* and may be called for characters that do not directly have a corresponding keyboard key.
* @param ch the character typed
*/
+ @Environment(EnvType.CLIENT)
public void onCharTyped(char ch) {
}
@@ -214,6 +222,7 @@ public class WWidget {
* Notifies this widget that a key has been pressed.
* @param key the GLFW scancode of the key
*/
+ @Environment(EnvType.CLIENT)
public void onKeyPressed(int ch, int key, int modifiers) {
}
@@ -221,6 +230,7 @@ public class WWidget {
* Notifies this widget that a key has been released
* @param key the GLFW scancode of the key
*/
+ @Environment(EnvType.CLIENT)
public void onKeyReleased(int ch, int key, int modifiers) {
}