diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java index a9d1d9b..6294ac6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java @@ -51,7 +51,7 @@ public enum CottonHud implements HudRenderCallback { * @param x the x offset * @param y the y offset * @param width the width of the widget - * @param height the heigh of the widget + * @param height the height of the widget * @see Positioner#of documentation about the offsets */ public void add(WWidget widget, int x, int y, int width, int height) { @@ -71,6 +71,20 @@ public enum CottonHud implements HudRenderCallback { } /** + * Adds a new widget to the HUD with a custom positioner and resizes it. + * + * @param widget the widget + * @param positioner the positioner + * @param width the width of the widget + * @param height the height of the widget + */ + public void add(WWidget widget, Positioner positioner, int width, int height) { + widgets.add(widget); + widget.setSize(width, height); + setPositioner(widget, positioner); + } + + /** * Sets the positioner of the widget. * * @param widget the widget @@ -132,5 +146,19 @@ public enum CottonHud implements HudRenderCallback { widget.setLocation((hudWidth + x) % hudWidth, (hudHeight + y) % hudHeight); }; } + + /** + * Creates a new positioner that centers widgets on the X axis and offsets them on the Y axis. + * + * <p>If the Y offset is negative, the offset is subtracted from the HUD height. + * + * @param y the y offset + * @return a centering positioner + */ + static Positioner horizontallyCentered(int y) { + return (widget, hudWidth, hudHeight) -> { + widget.setLocation((hudWidth - widget.getWidth()) / 2, (hudHeight + y) % hudHeight); + }; + } } } |