SSGL Wiki

Scroll Areas

Scroll areas are useful when a GUI contains more content than can comfortably fit on the screen.

SSGL provides vertical scroll areas.

Creating a scroll area

Use GuiScrollArea.vertical():

GuiScrollArea.vertical(200)
    .gap(8)
    .add(GuiElement.label("Scrollable Content"))
    .add(GuiElement.button("Item 1", this::selectItem))
    .add(GuiElement.button("Item 2", this::selectItem))
    .add(GuiElement.button("Item 3", this::selectItem));

The argument represents the preferred viewport height.

Adding a scroll area to a GUI

gui.add(
    GuiScrollArea.vertical(200)
        .gap(8)
        .add(GuiElement.label("General"))
        .add(GuiElement.toggle("Enabled", enabled))
        .add(GuiElement.button("Apply", this::apply))
);

Nested content

Scroll areas can contain components and layouts.

gui.add(
    GuiScrollArea.vertical(220)
        .gap(10)

        .add(GuiElement.label("Display"))

        .add(
            GuiLayout.horizontal()
                .gap(8)
                .add(GuiElement.toggle("Fullscreen", fullscreen))
                .add(GuiElement.toggle("VSync", vsync))
        )

        .add(GuiElement.slider(
            "Brightness",
            0.0,
            1.0,
            brightness
        ))
);

Automatic sizing

The requested viewport height is treated as a preferred height.

When the available screen height is smaller, SSGL reduces the viewport to fit the available space. This helps prevent the GUI from clipping at larger GUI scales.

The scroll area can also be placed inside nested layouts.

Input

Users can scroll through the content using the mouse wheel or the scroll bar. Elements inside the scroll area move together, including their labels.