-
Notifications
You must be signed in to change notification settings - Fork 0
Text and Buttons
The basic visible primitives.
Renders a string. Two flavours: a static one that takes a String, and a reactive one that takes a Supplier<String> re-read every frame. Pair the reactive form with state.map(...) to get auto-updating labels.
Text(String content)
Text(String content, Style style)
Text(Supplier<String> contentSupplier)
Text(Supplier<String> contentSupplier, Style style)Text("hello", Style.fontSize(20).textColor(WHITE).build());
State<Integer> counter = State.of(0);
Text(counter.map(v -> "count: " + v),
Style.fontSize(14).textColor(0xFF_AA_AA_AA).build());Style properties that affect Text:
textColorfontSizeboldpadding-
align(horizontal, vertical)(within the text's measured box)
The intrinsic height is roughly 10 px at the default font size of 9.
Clickable rectangle with a centered label. The click handler comes from the style (Style.onClick(...) or Style.builder().onClick(...)), not from a separate parameter.
Button(String label)
Button(String label, Style style)Button("Save",
Style.width(120).height(28)
.backgroundColor(0xFF_00_AA_FF)
.textColor(WHITE)
.borderRadius(4)
.onClick((x, y, btn) -> save())
.build());Behavior:
- Minimum size 60 × 20 (the layout will not shrink it below this).
- Background darkens slightly on hover.
- The click handler is
(double x, double y, int button) -> void—buttonis the Minecraft mouse-button code (0= left,1= right,2= middle).
Draws a Minecraft texture identifier. Three overloads cover the common cases.
Image(Identifier texture)
Image(Identifier texture, Style style)
Image(Identifier texture, int textureWidth, int textureHeight, Style style)Image(Identifier.of("modid", "textures/gui/banner.png"),
256, 64,
Style.width(MATCH_PARENT).height(64).build());The third overload exists because DrawContext.drawTexture needs the source texture's actual dimensions to sample correctly. The two-arg overload assumes a 256 × 256 texture; if yours is different, use the four-arg form.
Style properties that affect Image:
-
width/height— destination size (the texture is stretched / squeezed). -
padding— applied around the drawn region.