Section

Section groups entries under a title, collapsible by default so its children stay hidden until the player expands it, or as a plain heading.

Last updated

On this page

A titled group of entries. A collapsible section (the default) hides its children until the player clicks its header; a non-collapsible one is just a heading above always-visible entries.

Section advanced = Section.builder("advanced")
        .title(Text.translatable("mymod.advanced", "Advanced"))
        .expanded(config.advancedOpen)                  // start as the player left it
        .onToggle(open -> config.advancedOpen = open)   // remember it
        .add(Toggle.builder("debug")
                .label(Text.translatable("mymod.debug", "Debug output"))
                .value(() -> config.debug)
                .onChange(v -> config.debug = v)
                .build())
        .add(Slider.builder("threads")
                .label(Text.translatable("mymod.threads", "Threads"))
                .range(1, 8).step(1)
                .value(() -> config.threads)
                .onChange(v -> config.threads = (int) v)
                .build())
        .build();

MenuScreen.builder("main").title(title).add(advanced).build();   // adds the section and its children

Builder#

Method Required Default Notes
title(Supplier<Text>) / title(Text) yes the title, without the ▼/▶ marker
add(Entry) no appends a child; not a section (sections don't nest)
add(StringListEditor) no appends a list editor's four entries as children
collapsible(boolean) no true false makes a plain heading, always expanded
expanded(boolean) no false (collapsed) whether a collapsible section starts expanded
onToggle(Consumer<Boolean>) no does nothing called with the new state (true = expanded) on every expand or collapse
enabled, tooltip, visible no apply to the header; hiding the section hides its children too

How it is drawn#

Rules#

Methods#

Method Does
setExpanded(boolean) expands or collapses and calls onToggle. Nothing happens if it can't collapse or already is in that state. For example, open the section that holds an error.
toggle() flips it, as a click does
expanded() whether the children are shown (if the section is visible)
children() the children in screen order

Test it#

host.click("advanced");                 // expands it
host.slide("threads", 4);               // children can be used only while expanded

Rendered as [section advanced] ▼ Advanced, with each visible child on the next lines, indented by two spaces.

See also#