SSGL Wiki

Creating a GUI

Creating a screen

Start by calling SSGL.create().

It accepts either a String or a Minecraft Component as the screen title.

Gui gui = SSGL.create("My GUI");

For translated titles, use:

Gui gui = SSGL.create(
    Component.translatable("mymod.gui.title")
);

The returned Gui instance represents your screen.

Basic configuration

SSGL provides a few options to configure the screen.

Gui gui = SSGL.create("My GUI")
    .contentWidth(320)
    .spacing(8)
    .boldTitle(true);
Method Description
contentWidth(int) Sets the preferred content width
spacing(int) Sets the spacing between root elements
boldTitle(boolean) Enables or disables bold title text

The title is displayed above the main content panel.

SSGL automatically adds the panel padding and uses a compact layout. The preferred panel width is constrained to fit the available screen width.

Adding components

Use gui.add() to add components to the screen.

gui.add(
    GuiElement.label("General Settings")
);

gui.add(
    GuiElement.button("Apply", this::applySettings)
);

You can add:

  • GuiElement
  • GuiLayout
  • GuiScrollArea

Root-level elements are arranged vertically.

Opening the GUI

Opening a GUI requires an explicit boolean argument:

gui.open(false);

The argument determines whether the GUI pauses the singleplayer game.

Closing the GUI

Close the screen using:

gui.close();

SSGL restores the screen that was open before the GUI was opened.

You can also close the screen from a button:

GuiElement.button("Close", gui::close);

Updating an existing GUI

You can add or remove root-level elements using:

gui.add(
    GuiElement.label("Additional content")
);

Clear the root elements with:

gui.clear();