Skip to content

Commit 485f776

Browse files
committed
Close modal when clicking outside of its
1 parent 9448a68 commit 485f776

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/gg/essential/ad/modal/Modal.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ public void mouseClicked(int mouseX, int mouseY) {
6262
for (ModalButton button : buttonList) {
6363
if (Draw.hovered(mouseX, mouseY, button.x, button.y, button.width, button.height)) {
6464
button.onClick();
65+
return;
6566
}
6667
}
68+
// Anywhere on the modal
69+
if (Draw.hovered(mouseX, mouseY, startX, startY, width, height)) {
70+
return;
71+
}
72+
// Clicked on the modal background, close the modal
73+
ModalManager.INSTANCE.setModal(null);
6774
}
6875

6976
public void keyPressed(int key) {

0 commit comments

Comments
 (0)