Skip to content

GaldurButton

classclient onlysince 0.1.0

com.galdurstudio.galdurui.api.widget.GaldurButton

Themed button with a centred label.

Four states, each with a grayscale 9-slice sprite tinted by a theme colour: idle (accent), hovered or keyboard-focused (accent_hover, faded in), pressed (accent_pressed) and disabled (surface, label in text_muted). Disable it with the inherited active field.

Example.java
layout.addChild(GaldurButton.of(Component.literal("Confirm"), button -> confirm()));

Colours are read from the theme every frame. The size is fixed at construction: of() sizes the button from its label and the theme spacings.

public class GaldurButton extends AbstractWidget
PACKAGEapi.widget
SIDEclient only
EXTENDSAbstractWidget

Constructors 1

GaldurButton

public GaldurButton(int x, int y, int width, int height, Component label, OnPress onPress)

Creates a button with a given position and size; of() sizes it from its label instead.

PARAMETERS

xint—
yint—
widthint—
heightint—
labelComponent—
onPressOnPress—

Methods 7

of

static
public static GaldurButton of(Component label, OnPress onPress)

PARAMETERS

labelComponent—
onPressOnPress—

RETURNSGaldurButton — a button sized from its label, at (0, 0) for a layout to place

withSprites

public GaldurButton withSprites(ResourceLocation normal, ResourceLocation hovered, ResourceLocation pressed, ResourceLocation disabled)

Replaces the sprites. They are tinted like the default ones, so provide them in grayscale: white takes the exact theme colour.

PARAMETERS

normalResourceLocation—
hoveredResourceLocation—
pressedResourceLocation—
disabledResourceLocation—

RETURNSGaldurButton — this button

getPreferredWidth

public int getPreferredWidth()

RETURNSint — the smallest width that shows the whole label

renderContent

protected
protected void renderContent(GuiGraphics guiGraphics)

Draws the button contents over its background: by default the centred label, in text or text_muted when disabled. Override it to show something else while keeping the states and behaviour (see GaldurIconButton).

PARAMETERS

guiGraphicsGuiGraphics—

onRelease

public void onRelease(double mouseX, double mouseY)

Fires only if the press started on this button and ends on it: dragging away cancels, as everywhere in the game.

PARAMETERS

mouseXdouble—
mouseYdouble—

isHeld

public boolean isHeld()

RETURNSboolean — true while the mouse button is held down on this button

clearHeld

public void clearHeld()

Forgets the pressed state now. Rarely needed: a press whose release was not seen is forgotten on the first frame where the mouse button is up. Useful for a Screen that keeps its buttons across init() calls and wants a clean state before the next frame.

Nested types 1

OnPress

public interface OnPress

Action run when the button is activated, by mouse or keyboard.

© 2026 Galdur Studio · galdurstudio.com · Discord · LGPL-3.0-onlyNot an official Minecraft product. Not approved by or associated with Mojang or Microsoft.