SSGL Wiki

Sliders and Input Fields

Sliders

Sliders uses Minecraft's native slider widget. They support continuous and stepped values.

A slider requires a GuiValue<Double>.

Continuous slider

GuiValue<Double> volume = GuiValue.of(0.5);

gui.add(
    GuiElement.slider(
        "Volume",
        0.0,
        1.0,
        volume
    )
);

The no-step overload uses continuous movement.

You can also use a translated label:

GuiElement.slider(
    Component.translatable("mymod.gui.volume"),
    0.0,
    1.0,
    volume
);

Stepped slider

Provide an additional step argument to enable snapping.

GuiValue<Double> zoom = GuiValue.of(2.0);

gui.add(
    GuiElement.slider(
        "Zoom",
        1.0,
        10.0,
        0.5,
        zoom
    )
);

The slider moves in increments of 0.5.

Slider parameters

Parameter Description
label Slider label
min Minimum value
max Maximum value
step Increment between values
value Bound GuiValue<Double>

A step of 0.0 means continuous movement. Positive values enable snapping.

The current value is displayed alongside the label.

Slider values are clamped to their configured range.

External changes to the bound GuiValue are reflected by the slider.

Text fields

Text fields support editable strings.

GuiValue<String> username = GuiValue.of("Steve");

gui.add(
    GuiElement.textField("Username", username)
);

With a placeholder:

GuiElement.textField(
    "Username",
    "Enter username",
    username
);

Translated labels and placeholders are also supported:

GuiElement.textField(
    Component.translatable("mymod.gui.username"),
    Component.translatable("mymod.gui.username.placeholder"),
    username
);

The field updates the bound value as the user edits the text. External changes to the value are also synchronized.

Integer fields

Integer fields accept integer values.

GuiValue<Integer> amount = GuiValue.of(25);

gui.add(
    GuiElement.integerField("Amount", amount)
);

With a placeholder:

GuiElement.integerField(
    "Amount",
    "Enter an amount",
    amount
);

A translated version:

GuiElement.integerField(
    Component.translatable("mymod.gui.amount"),
    Component.translatable("mymod.gui.amount.placeholder"),
    amount
);

Decimal fields

Decimal fields accept floating-point values using Double.

GuiValue<Double> scale = GuiValue.of(1.5);

gui.add(
    GuiElement.doubleField("Scale", scale)
);

With a placeholder:

GuiElement.doubleField(
    "Scale",
    "Enter scale",
    scale
);

A translated version:

GuiElement.doubleField(
    Component.translatable("mymod.gui.scale"),
    Component.translatable("mymod.gui.scale.placeholder"),
    scale
);

Input field dimensions

Text and numeric fields consist of a label area and the native input area.

Their default and minimum height is 32 pixels.

Other default component heights are:

Component Default height
Button 20
Label 10
Toggle 20
Slider 20
Text field 32
Integer field 32
Decimal field 32

You can increase the height using .height(). SSGL validates minimum heights when configuring an element.