diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-04-15 16:06:32 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-04-26 00:42:02 +0300 |
commit | cf26e57d6846474702c0a86b0d199667a233ffc0 (patch) | |
tree | 46842eaec3e9e51f5f55d35c4936a20864765170 | |
parent | 308915315a358ce14c8951bc97bac76abb0da8bf (diff) | |
download | LibGui-cf26e57d6846474702c0a86b0d199667a233ffc0.tar.gz LibGui-cf26e57d6846474702c0a86b0d199667a233ffc0.tar.bz2 LibGui-cf26e57d6846474702c0a86b0d199667a233ffc0.zip |
Add Environment annotations to interaction methods
Should fix #41.
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 aa025f0..b3fc425 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 e815723..1ab42b1 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 @@ -87,6 +87,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 aa64567..7f2dac3 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 b94a626..f71f53b 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 @@ -91,6 +91,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 7896f6e..75e7628 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 83003cc..a2242b2 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 @@ -137,6 +137,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; } @@ -154,6 +155,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); } @@ -164,6 +166,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) { } @@ -173,6 +176,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; } @@ -183,6 +187,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) { } @@ -192,6 +197,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) { } @@ -202,6 +208,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) { } @@ -210,6 +217,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) { } @@ -217,6 +225,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) { } @@ -224,6 +233,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) { } |