diff options
Diffstat (limited to 'api/src/main/java/me')
3 files changed, 63 insertions, 5 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java index f1860280a..d157a6d3c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; +import org.jetbrains.annotations.ApiStatus; public abstract class WidgetWithBounds extends Widget { public abstract Rectangle getBounds(); @@ -42,4 +43,34 @@ public abstract class WidgetWithBounds extends Widget { render(matrices, mouseX, mouseY, delta); getBounds().setBounds(clone); } + + @ApiStatus.Experimental + public final WidgetWithBounds withPadding(int padding) { + return Widgets.padded(padding, this); + } + + @ApiStatus.Experimental + public final WidgetWithBounds withPadding(int padX, int padY) { + return Widgets.padded(padX, padY, this); + } + + @ApiStatus.Experimental + public final WidgetWithBounds withPaddingHorizontal(int padX) { + return Widgets.padded(padX, 0, this); + } + + @ApiStatus.Experimental + public final WidgetWithBounds withPaddingVertical(int padY) { + return Widgets.padded(0, padY, this); + } + + @ApiStatus.Experimental + public final WidgetWithBounds withPadding(int padLeft, int padRight, int padTop, int padBottom) { + return Widgets.padded(padLeft, padRight, padTop, padBottom, this); + } + + @ApiStatus.Experimental + public final WidgetWithBounds withScissors() { + return Widgets.scissored(this); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index 44e18b32e..1de228f80 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -52,7 +52,8 @@ import java.util.function.Supplier; @Environment(EnvType.CLIENT) public final class Widgets { - private Widgets() {} + private Widgets() { + } public static Widget createDrawableWidget(DrawableConsumer drawable) { return ClientInternals.getWidgetsProvider().createDrawableWidget(drawable); @@ -63,10 +64,11 @@ public final class Widgets { } public static WidgetWithBounds withTooltip(WidgetWithBounds widget, Collection<Component> texts) { - return withBounds(concat( + return concatWithBounds( + widget::getBounds, widget, createTooltip(widget::getBounds, texts) - ), widget::getBounds); + ); } public static Widget createTooltip(Rectangle bounds, Component... texts) { @@ -161,11 +163,11 @@ public final class Widgets { } public static WidgetWithBounds withBounds(Widget widget) { - return wrapWidgetWithBounds(widget, null); + return withBounds(widget, (Rectangle) null); } public static WidgetWithBounds withBounds(Widget widget, Rectangle bounds) { - return wrapWidgetWithBoundsSupplier(widget, bounds == null ? null : () -> bounds); + return withBounds(widget, bounds == null ? null : () -> bounds); } public static WidgetWithBounds withBounds(Widget widget, Supplier<Rectangle> bounds) { @@ -304,6 +306,22 @@ public final class Widgets { return ClientInternals.getWidgetsProvider().concatWidgets(widgets); } + public static WidgetWithBounds concatWithBounds(Rectangle bounds, Widget... widgets) { + return concatWithBounds(bounds, Arrays.asList(widgets)); + } + + public static WidgetWithBounds concatWithBounds(Rectangle bounds, List<Widget> widgets) { + return ClientInternals.getWidgetsProvider().concatWidgetsWithBounds(() -> bounds, widgets); + } + + public static WidgetWithBounds concatWithBounds(Supplier<Rectangle> bounds, Widget... widgets) { + return concatWithBounds(bounds, Arrays.asList(widgets)); + } + + public static WidgetWithBounds concatWithBounds(Supplier<Rectangle> bounds, List<Widget> widgets) { + return ClientInternals.getWidgetsProvider().concatWidgetsWithBounds(bounds, widgets); + } + public static WidgetWithBounds noOp() { return ClientInternals.getWidgetsProvider().noOp(); } @@ -319,6 +337,11 @@ public final class Widgets { } @ApiStatus.Experimental + public static WidgetWithBounds scissored(WidgetWithBounds widget) { + return ClientInternals.getWidgetsProvider().wrapScissored(widget); + } + + @ApiStatus.Experimental public static WidgetWithBounds padded(int padding, WidgetWithBounds widget) { return padded(padding, padding, padding, padding, widget); } diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java index 7fc29b400..af177e30a 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -228,12 +228,16 @@ public final class ClientInternals { Widget concatWidgets(List<Widget> widgets); + WidgetWithBounds concatWidgetsWithBounds(Supplier<Rectangle> bounds, List<Widget> widgets); + WidgetWithBounds noOp(); WidgetWithBounds wrapOverflow(Rectangle bounds, WidgetWithBounds widget); WidgetWithBounds wrapScissored(Rectangle bounds, Widget widget); + WidgetWithBounds wrapScissored(WidgetWithBounds widget); + WidgetWithBounds wrapPadded(int padLeft, int padRight, int padTop, int padBottom, WidgetWithBounds widget); } |
