Skip to content

Commit

Permalink
feat: Add quit button to the menu (#99)
Browse files Browse the repository at this point in the history
Adds a quit button to the main menu.

This option may feel nicer to some users over requiring the use of the
close button on the window.

I was hoping for a somewhat 'cleaner' way of doing this (such as by
manually triggering an `SDL_QUIT` event from the menu), but I have not
yet figured out if that is possible. If you have a better way of
handling this, feel free to close this PR or let me know. Otherwise, I
believe this should work fine.
  • Loading branch information
SnazzyPanda authored Dec 16, 2023
1 parent 9c30861 commit 62d778c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lamp/Menu/lampMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ void Lamp::Core::lampMenu::DefaultMenuBar() {
ImGui::EndMenu();
}

if (ImGui::MenuItem("Quit")) {
this->userRequestedQuit = true;
}


ImGui::EndMenu();
Expand Down
1 change: 1 addition & 0 deletions Lamp/Menu/lampMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Lamp::Core{
};

Menus currentMenu = LICENCE_MENU;
bool userRequestedQuit = false;

void RunMenus();

Expand Down
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ int main(int, char**)
SDL_RenderClear(renderer);
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer);

if(Menus.userRequestedQuit){
done = true;
}
}

ImGui_ImplSDLRenderer2_Shutdown();
Expand Down

0 comments on commit 62d778c

Please sign in to comment.