Aller au contenu
galdurdocs

GaldurIconButton

classclient uniquementdepuis 0.1.0

com.galdurstudio.galdurui.api.widget.GaldurIconButton

Pas encore traduit : texte d’origine en anglais.

Square button without text that shows an icon: a GUI sprite or an item.

Same background, states and behaviour as GaldurButton; only the contents change. The label is not drawn but is required: it is the tooltip and the narrated text.

Example.java
row.addChild(GaldurIconButton.ofItem(new ItemStack(Items.HOPPER),        Component.literal("Sort"), button -> sort()));row.addChild(GaldurIconButton.of(ResourceLocation.fromNamespaceAndPath("mymod", "icon/sort"),        Component.literal("Sort"), button -> sort()));

A sprite is drawn 16 × 16, tinted text (text_muted when disabled): provide it in grayscale. An item is drawn as in an inventory and veiled when disabled. The side is spacing.button_height, to line up with text buttons in the same row.

public class GaldurIconButton extends GaldurButton
PAQUETapi.widget
CÔTÉclient uniquement
HÉRITE DEGaldurButton

MEMBRES · 9

Constructeurs 1

GaldurIconButton

protected
protected GaldurIconButton(int size, ResourceLocation sprite, ItemStack item, Component label, OnPress onPress)

Prefer of or ofItem, which also set the label as tooltip.

PARAMÈTRES

sizeint—
spriteResourceLocationsprite to show, or null to show item
itemItemStackitem shown when there is no sprite; copied
labelComponent—
onPressOnPress—

Méthodes 8

of

static
public static GaldurIconButton of(ResourceLocation sprite, Component label, OnPress onPress)

PARAMÈTRES

spriteResourceLocation—
labelComponent—
onPressOnPress—

RENVOIEGaldurIconButton — a button showing a grayscale GUI sprite, at (0, 0)

ofItem

static
public static GaldurIconButton ofItem(ItemStack item, Component label, OnPress onPress)

PARAMÈTRES

itemItemStack—
labelComponent—
onPressOnPress—

RENVOIEGaldurIconButton — a button showing an item (copied), at (0, 0)

getPreferredWidth

public int getPreferredWidth()

RENVOIEint — the button side: an icon button does not widen to its label

withSprites

de GaldurButton
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

renderContent

de GaldurButtonprotected
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—
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—
public boolean isHeld()

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

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.

© 2026 Galdur Studio · galdurstudio.com · Discord · LGPL-3.0-onlyProduit non officiel. Non approuvé par Mojang ou Microsoft, ni associé à eux.