aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java18
1 files changed, 16 insertions, 2 deletions
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 1f9525d..987f50b 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
@@ -11,6 +11,7 @@ import net.minecraft.text.Text;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Alignment;
+import org.lwjgl.glfw.GLFW;
public class WButton extends WWidget {
private Text label;
@@ -33,13 +34,18 @@ public class WButton extends WWidget {
public boolean canResize() {
return true;
}
-
+
+ @Override
+ public boolean canFocus() {
+ return true;
+ }
+
@Override
public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) {
boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX<getWidth() && mouseY<getHeight());
int state = 1; //1=regular. 2=hovered. 0=disabled.
if (!enabled) state = 0;
- else if (hovered) state = 2;
+ else if (hovered || isFocused()) state = 2;
float px = 1/256f;
float buttonLeft = 0 * px;
@@ -83,6 +89,14 @@ public class WButton extends WWidget {
}
}
+ @Environment(EnvType.CLIENT)
+ @Override
+ public void onKeyPressed(int ch, int key, int modifiers) {
+ if (ch == GLFW.GLFW_KEY_SPACE || ch == GLFW.GLFW_KEY_ENTER || ch == GLFW.GLFW_KEY_KP_ENTER) {
+ onClick(0, 0, 0);
+ }
+ }
+
public WButton setOnClick(Runnable r) {
this.onClick = r;
return this;