From 084985537dae8106c262f5f8a5d3917df2f66ed3 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sat, 16 May 2020 18:46:02 +0300 Subject: WWidget + GuiDescription docs, improve "host is null" logging message --- .../github/cottonmc/cotton/gui/GuiDescription.java | 2 +- .../github/cottonmc/cotton/gui/widget/WWidget.java | 33 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'src/main/java') 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; } -- cgit