aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:46:02 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:46:02 +0300
commit084985537dae8106c262f5f8a5d3917df2f66ed3 (patch)
treea3a69b98a3abd9dc298bcd586d0c4b64f23dc723
parent1251c42512ef376074eb4bdfaf7e496954cd5b0d (diff)
downloadLibGui-084985537dae8106c262f5f8a5d3917df2f66ed3.tar.gz
LibGui-084985537dae8106c262f5f8a5d3917df2f66ed3.tar.bz2
LibGui-084985537dae8106c262f5f8a5d3917df2f66ed3.zip
WWidget + GuiDescription docs, improve "host is null" logging message
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java33
2 files changed, 32 insertions, 3 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
index a0b75cc..fec799b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
@@ -45,7 +45,7 @@ public interface GuiDescription {
@Nullable
public WWidget getFocus();
- /** Notifies this gui that the widget waants to acquire focus. */
+ /** Notifies this gui that the widget wants to acquire focus. */
public void requestFocus(WWidget widget);
/** Notifies this gui that the widget wants to give up its hold over focus. */
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 cee18d5..656f24f 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
@@ -4,13 +4,14 @@ import java.util.ArrayList;
import java.util.List;
import io.github.cottonmc.cotton.gui.GuiDescription;
-import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
@@ -18,15 +19,22 @@ import javax.annotation.Nullable;
* The base class for all widgets.
*/
public class WWidget {
+ private static final Logger LOGGER = LogManager.getLogger();
+
/**
* The containing panel of this widget.
* Can be null if this widget is the root panel or a HUD widget.
*/
@Nullable
protected WPanel parent;
+
+ /** The X coordinate of this widget relative to its parent. */
protected int x = 0;
+ /** The Y coordinate of this widget relative to its parent. */
protected int y = 0;
+ /** The width of this widget, defaults to 18 pixels. */
protected int width = 18;
+ /** The height of this widget, defaults to 18 pixels. */
protected int height = 18;
/**
@@ -245,23 +253,44 @@ public class WWidget {
public void onFocusLost() {
}
+ /**
+ * Tests whether this widget has focus.
+ *
+ * @return true if this widget widget has focus, false otherwise
+ * @see GuiDescription#isFocused(WWidget)
+ */
public boolean isFocused() {
if (host==null) return false;
return host.isFocused(this);
}
+ /**
+ * If this widget has a host, requests the focus from the host.
+ *
+ * @see GuiDescription#requestFocus(WWidget)
+ */
public void requestFocus() {
if (host!=null) {
host.requestFocus(this);
} else {
- System.out.println("host is null");
+ LOGGER.warn("Requesting focus for {}, but the host is null", this);
}
}
+ /**
+ * If this widget has a host, releases this widget's focus.
+ *
+ * @see GuiDescription#releaseFocus(WWidget)
+ */
public void releaseFocus() {
if (host!=null) host.releaseFocus(this);
}
+ /**
+ * Tests whether this widget can have the focus in the GUI.
+ *
+ * @return true if this widget can be focused, false otherwise
+ */
public boolean canFocus() {
return false;
}