Aller au contenu
galdurdocs

GaldurButton

classclient uniquementdepuis 0.1.0

com.galdurstudio.galdurui.api.widget.GaldurButton

Pas encore traduit : texte d’origine en anglais.

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
PAQUETapi.widget
CÔTÉclient uniquement
HÉRITE DEAbstractWidget

Constructeurs 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.

PARAMÈTRES

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

Méthodes 7

of

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

PARAMÈTRES

labelComponent—
onPressOnPress—

RENVOIEGaldurButton — 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.

PARAMÈTRES

normalResourceLocation—
hoveredResourceLocation—
pressedResourceLocation—
disabledResourceLocation—

RENVOIEGaldurButton — this button

getPreferredWidth

public int getPreferredWidth()

RENVOIEint — 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).

PARAMÈTRES

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.

PARAMÈTRES

mouseXdouble—
mouseYdouble—

isHeld

public boolean isHeld()

RENVOIEboolean — 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.

Types imbriqués 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-onlyProduit non officiel. Non approuvé par Mojang ou Microsoft, ni associé à eux.