Complete Example
The following example combines common SSGL features in a single screen.
It demonstrates a title, a scroll area, nested layouts, bound values, toggles, fields, sliders, buttons, and an image button.
package com.example.mymod.client;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import smilenotalive.ssgl.SSGL;
import smilenotalive.ssgl.gui.Alignment;
import smilenotalive.ssgl.gui.Gui;
import smilenotalive.ssgl.gui.GuiElement;
import smilenotalive.ssgl.gui.GuiLayout;
import smilenotalive.ssgl.gui.GuiScrollArea;
import smilenotalive.ssgl.gui.GuiValue;
public final class CameraScreen {
private final GuiValue<Boolean> enabled = GuiValue.of(true);
private final GuiValue<Boolean> flash = GuiValue.of(false);
private final GuiValue<String> filename = GuiValue.of("screenshot");
private final GuiValue<Double> zoom = GuiValue.of(1.0);
public void open() {
Gui gui = SSGL.create(
Component.translatable("mymod.gui.title")
)
.contentWidth(320)
.spacing(8)
.boldTitle(true);
Identifier cameraIcon =
Identifier.fromNamespaceAndPath(
"mymod",
"textures/gui/camera.png"
);
gui.add(
GuiScrollArea.vertical(220)
.gap(10)
.add(
GuiElement.label(
Component.translatable("mymod.gui.general")
).align(Alignment.CENTER)
)
.add(
GuiLayout.horizontal()
.gap(8)
.add(GuiElement.toggle(
Component.translatable("mymod.gui.enabled"),
enabled
))
.add(GuiElement.toggle(
Component.translatable("mymod.gui.flash"),
flash
))
)
.add(GuiElement.textField(
Component.translatable("mymod.gui.filename"),
Component.translatable("mymod.gui.filename.placeholder"),
filename
))
.add(GuiElement.slider(
Component.translatable("mymod.gui.zoom"),
1.0,
5.0,
0.1,
zoom
))
.add(
GuiElement.imageButton(
Component.translatable("mymod.gui.camera.narration"),
cameraIcon,
96,
64,
Component.translatable("mymod.gui.camera.tooltip"),
this::capturePhoto
).align(Alignment.CENTER)
)
.add(GuiElement.button(
Component.translatable("mymod.gui.reset"),
this::resetSettings
))
);
gui.add(
GuiLayout.horizontal()
.gap(8)
.add(GuiElement.button(
Component.translatable("mymod.gui.apply"),
this::applySettings
))
.add(GuiElement.button(
Component.translatable("mymod.gui.close"),
gui::close
))
);
gui.open(false);
}
private void capturePhoto() {
// Capture a photo using your camera implementation
}
private void applySettings() {
// Apply the current values to your mod
}
private void resetSettings() {
enabled.set(true);
flash.set(false);
filename.set("screenshot");
zoom.set(1.0);
}
}