diff options
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 36 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 30 |
2 files changed, 60 insertions, 6 deletions
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; * <p> W is the WWidget class that will represent a single D of data. */ public class WListPanel<D, W extends WWidget> extends WClippedPanel { + /** + * The list of data that this list represents. + */ protected List<D> data; + + /** + * The supplier of new empty widgets. + */ protected Supplier<W> supplier; + + /** + * The widget configurator that configures the passed widget + * to display the passed data. + */ protected BiConsumer<D, W> configurator; protected HashMap<D, W> configured = new HashMap<>(); protected List<W> 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<D> data, Supplier<W> supplier, BiConsumer<D, W> configurator) { this.data = data; this.supplier = supplier; this.configurator = configurator; scrollBar.setMaxValue(data.size()); + scrollBar.setParent(this); } /** @@ -157,7 +181,13 @@ public class WListPanel<D, W extends WWidget> 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<D, W> 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. + * + * <p>The list is mutable. + */ protected final List<WWidget> 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; |