SSGL Wiki

Components

Components are created through GuiElement.

They can be added directly to a GUI or placed inside layouts and scroll areas.

Labels

Labels just display text without user interaction.

GuiElement.label("General Settings");

For translated text:

GuiElement.label(
    Component.translatable("mymod.gui.general")
);

Labels support left, center, and right alignment.

GuiElement.label("Centered Label")
    .align(Alignment.CENTER);

Buttons

Buttons use Minecraft's native button widget.

GuiElement.button("Apply", () -> {
    saveSettings();
});

You can also use a Component:

GuiElement.button(
    Component.translatable("mymod.gui.apply"),
    this::saveSettings
);

Buttons executes the supplied Runnable when activated.

Example with a lambda:

GuiElement.button("Reset", () -> {
    LOGGER.info("Settings reset!");
});

Toggle Buttons

Toggles buttons provide a simple ON/OFF control.

They use a vanilla button displaying the current state.

GuiValue<Boolean> enabled = GuiValue.of(true);

gui.add(
    GuiElement.toggle("Enabled", enabled)
);

The resulting button displays either:

Enabled: ON

or:

Enabled: OFF

The displayed state stays synchronized with its GuiValue, including when the value is changed externally.

For example:

enabled.set(false);

The next render reflects the updated value.