Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Add GUI::alertPopup
Browse files Browse the repository at this point in the history
SpaghettDev committed Jan 14, 2024
1 parent 6e13665 commit 823d97a
Showing 3 changed files with 67 additions and 17 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@
[![Discord](https://img.shields.io/badge/Discord-white?style=flat&logo=discord)](https://discord.gg/nbDjEg7SSU)
</div>

# Not updated to 2.204 yet

## How to use

> **Warning**
32 changes: 32 additions & 0 deletions src/GUI/Widgets.cpp
Original file line number Diff line number Diff line change
@@ -160,6 +160,38 @@ bool GUI::modalPopup(std::string name, const std::function<void()>& popupFunctio
return true;
}

bool GUI::alertPopup(std::string name, std::string content, const ButtonFunc& yesButton, const ButtonFunc& noButton, int flags)
{
if (!GUI::isVisible || ImGui::BeginPopupModal(name.c_str(), NULL, flags) || GUI::shortcutLoop)
{
ImGui::Text(content.c_str());

if (GUI::shouldRender())
{
if (ImGui::Button(yesButton.name.c_str()))
{
yesButton.function();
ImGui::CloseCurrentPopup();
}

if (noButton)
{
ImGui::SameLine();

if (ImGui::Button(noButton.name.c_str()))
{
noButton.function();
ImGui::CloseCurrentPopup();
}
}

ImGui::EndPopup();
}
}

return true;
}

void GUI::arrowButton(std::string popupName)
{
if (!GUI::shouldRender())
50 changes: 35 additions & 15 deletions src/GUI/Widgets.h
Original file line number Diff line number Diff line change
@@ -6,19 +6,39 @@

namespace GUI
{
bool button(std::string);
bool checkbox(std::string, bool*);
bool inputText(std::string, std::string*);
bool inputInt(std::string, int*, int = -INT_MAX, int = INT_MAX);
bool inputInt2(std::string, int*, int = -INT_MAX, int = INT_MAX, int = -INT_MAX, int = INT_MAX);
bool inputFloat(std::string, float*, float = -FLT_MAX, float = FLT_MAX);
bool dragInt(std::string, int*, int = -INT_MAX, int = INT_MAX);
bool dragFloat(std::string, float*, float = -FLT_MAX, float = FLT_MAX);
bool combo(std::string name, int* value, const char* const items[], int itemsCount);
bool colorEdit(std::string, float*, bool = false, bool = false);
void arrowButton(std::string);
bool hotkey(std::string, int*, const ImVec2& = ImVec2(0, 0));
bool modalPopup(std::string, const std::function<void()>&, int = ImGuiWindowFlags_AlwaysAutoResize);
void marker(std::string, std::string);
void textURL(std::string, std::string);
struct ButtonFunc
{
std::string name;
std::function<void()> function;

ButtonFunc(std::string name, std::function<void()> function)
: name(name), function(function)
{};

ButtonFunc(std::nullptr_t)
: name(""), function(nullptr)
{};

operator bool() const
{
return function != nullptr;
}
}

bool button(std::string);
bool checkbox(std::string, bool*);
bool inputText(std::string, std::string*);
bool inputInt(std::string, int*, int = -INT_MAX, int = INT_MAX);
bool inputInt2(std::string, int*, int = -INT_MAX, int = INT_MAX, int = -INT_MAX, int = INT_MAX);
bool inputFloat(std::string, float*, float = -FLT_MAX, float = FLT_MAX);
bool dragInt(std::string, int*, int = -INT_MAX, int = INT_MAX);
bool dragFloat(std::string, float*, float = -FLT_MAX, float = FLT_MAX);
bool combo(std::string, int*, const char* const[], int);
bool colorEdit(std::string, float*, bool = false, bool = false);
void arrowButton(std::string);
bool hotkey(std::string, int*, const ImVec2& = { 0, 0 });
bool modalPopup(std::string, const std::function<void()>&, int = ImGuiWindowFlags_AlwaysAutoResize);
bool alertPopup(std::string, std::string, const ButtonFunc&, const ButtonFunc& = nullptr, int = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove);
void marker(std::string, std::string);
void textURL(std::string, std::string);
};

0 comments on commit 823d97a

Please sign in to comment.