Skip to content

Commit 6e2d04f

Browse files
authored
Add shortcut method to toggle panel open or closed (#184)
1 parent 448e1a6 commit 6e2d04f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/main/java/com/cleanroommc/modularui/api/IPanelHandler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ static IPanelHandler simple(ModularPanel parent, SecondaryPanel.IPanelBuilder pr
6161
@ApiStatus.OverrideOnly
6262
void closePanelInternal();
6363

64+
/**
65+
* Toggles this panel open or closed. Delegates to {@link #openPanel()} and {@link #closePanel()}.
66+
*
67+
* @return {@code true} if the panel was opened, {@code false} if it was closed
68+
*/
69+
default boolean togglePanel() {
70+
if (isPanelOpen()) {
71+
closePanel();
72+
return false;
73+
} else {
74+
openPanel();
75+
return true;
76+
}
77+
}
78+
6479
/**
6580
* Deletes the current cached panel. Should not be used frequently.
6681
* This only works on panels which don't have {@link ItemSlotSH} sync handlers.

0 commit comments

Comments
 (0)