Class Section
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Section
A titled group of entries on a
MenuScreen. A collapsible section (the default) hides its children until the
player expands it by clicking 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")…build())
.add(Slider.builder("threads")…build())
.build();
MenuScreen.builder("main").title(title).add(advanced)… // adds the section and its children
How it is drawn
Not an entry type of its own for backends: it is drawn as its header, aButton ("▼ title" while expanded,
"▶ title" while collapsed, see headerText()) that expands and collapses it, or a Label (the title)
if it can't collapse. MenuScreen.Builder.add(Entry) adds its children right after it, and they are
Entry.visible only while the section is visible and expanded. The section's own enabled,
tooltip and visible options apply to the header; hiding the section hides its children too.
Rules
- Whether it is expanded lives in the section object (a refresh doesn't change it);
onTogglelets the mod remember it across menu openings. - Sections don't nest, can't be in the footer, and an entry is in at most one section.
- Children's ids share the screen's id space like any other entries.
- A child must not be added to the screen on its own; add the section.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(EntryVisitor<R> visitor) static Section.BuilderStarts building a section.children()The children in screen order.booleanWhether the player can expand and collapse it;trueunless the builder setcollapsible(false).booleanexpanded()Whether the children are shown (if the section itself is visible); always true for a section that can't collapse.What the header shows: "▼ title" while expanded, "▶ title" while collapsed (UiTexts.SECTION_EXPANDED,UiTexts.SECTION_COLLAPSED); just the title if the section can't collapse.voidsetExpanded(boolean expand) Expands or collapses the section and tellsonToggle.title()The section's title, from the mod's supplier, without the ▼/▶ marker.voidtoggle()Flipsexpanded(), as a click on the header does; seesetExpanded(boolean).
-
Method Details
-
builder
Starts building a section.- Parameters:
id- the section's id, unique within its screen; also its header's id- Returns:
- a new builder;
Section.Builder.titleis required - Throws:
IllegalArgumentException- ifidis invalid
-
title
The section's title, from the mod's supplier, without the ▼/▶ marker.- Returns:
- the title, without the expand marker
-
headerText
What the header shows: "▼ title" while expanded, "▶ title" while collapsed (UiTexts.SECTION_EXPANDED,UiTexts.SECTION_COLLAPSED); just the title if the section can't collapse.- Returns:
- the header text, with the marker, or just the title if the section can't collapse
-
collapsible
public boolean collapsible()Whether the player can expand and collapse it;trueunless the builder setcollapsible(false).- Returns:
trueif the player can expand and collapse the section
-
expanded
public boolean expanded()Whether the children are shown (if the section itself is visible); always true for a section that can't collapse.- Returns:
trueif the children are shown
-
setExpanded
public void setExpanded(boolean expand) Expands or collapses the section and tellsonToggle. Nothing happens if it can't collapse or already is in that state. The change shows on the next refresh (automatic after a click on the header). A mod can call it from an action, e.g. to open a section that has an error in it.- Parameters:
expand-trueto show the children,falseto hide them
-
toggle
public void toggle()Flipsexpanded(), as a click on the header does; seesetExpanded(boolean). -
children
-
accept
-