From fdf0ce3f5327dc2efcab8789fd4a41d5d8962ada Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Mon, 13 Apr 2020 21:32:54 +0300
Subject: Improve panel and list docs
---
.../cottonmc/cotton/gui/widget/WListPanel.java | 36 ++++++++++++++++++++--
.../github/cottonmc/cotton/gui/widget/WPanel.java | 30 ++++++++++++++++--
2 files changed, 60 insertions(+), 6 deletions(-)
(limited to 'src/main/java')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
index 7c92191..ff2b897 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
@@ -16,25 +16,49 @@ import io.github.cottonmc.cotton.gui.widget.data.Axis;
*
W is the WWidget class that will represent a single D of data.
*/
public class WListPanel extends WClippedPanel {
+ /**
+ * The list of data that this list represents.
+ */
protected List data;
+
+ /**
+ * The supplier of new empty widgets.
+ */
protected Supplier supplier;
+
+ /**
+ * The widget configurator that configures the passed widget
+ * to display the passed data.
+ */
protected BiConsumer configurator;
protected HashMap configured = new HashMap<>();
protected List unconfigured = new ArrayList<>();
+
+ /**
+ * The height of each child cell.
+ */
protected int cellHeight = 20;
+
+ /**
+ * Whether this list has a fixed height for items.
+ */
protected boolean fixedHeight = false;
protected int margin = 4;
-
+
+ /**
+ * The scroll bar of this list.
+ */
protected WScrollBar scrollBar = new WScrollBar(Axis.VERTICAL);
- int lastScroll = -1;
+ private int lastScroll = -1;
public WListPanel(List data, Supplier supplier, BiConsumer configurator) {
this.data = data;
this.supplier = supplier;
this.configurator = configurator;
scrollBar.setMaxValue(data.size());
+ scrollBar.setParent(this);
}
/**
@@ -157,7 +181,13 @@ public class WListPanel extends WClippedPanel {
//System.out.println("Children: "+children.size());
}
-
+
+ /**
+ * Sets the height of this list's items to a constant value.
+ *
+ * @param height the item height
+ * @return this list
+ */
public WListPanel setListItemHeight(int height) {
cellHeight = height;
fixedHeight = true;
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 706a71b..373479b 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
@@ -9,7 +9,15 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+/**
+ * Panels are widgets tthat contain other widgets.
+ */
public abstract class WPanel extends WWidget {
+ /**
+ * The widgets contained within this panel.
+ *
+ * The list is mutable.
+ */
protected final List children = Lists.newArrayList();
@Environment(EnvType.CLIENT)
private BackgroundPainter backgroundPainter = null;
@@ -21,7 +29,12 @@ public abstract class WPanel extends WWidget {
child.createPeers(c);
}
}
-
+
+ /**
+ * Removes the widget from this panel.
+ *
+ * @param w the removed widget
+ */
public void remove(WWidget w) {
children.remove(w);
}
@@ -30,13 +43,24 @@ public abstract class WPanel extends WWidget {
public boolean canResize() {
return true;
}
-
+
+ /**
+ * Sets the {@link BackgroundPainter} of this panel.
+ *
+ * @param painter the new painter
+ * @return this panel
+ */
@Environment(EnvType.CLIENT)
public WPanel setBackgroundPainter(BackgroundPainter painter) {
this.backgroundPainter = painter;
return this;
}
-
+
+ /**
+ * Gets the current {@link BackgroundPainter} of this panel.
+ *
+ * @return the painter
+ */
@Environment(EnvType.CLIENT)
public BackgroundPainter getBackgroundPainter() {
return this.backgroundPainter;
--
cgit