2023-11-10 20:47:08 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
#include <hex/ui/popup.hpp>
|
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-04-08 00:58:53 +02:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
namespace hex::ui {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
|
|
|
class PopupQuestion : public Popup<PopupQuestion> {
|
|
|
|
public:
|
|
|
|
PopupQuestion(std::string message, std::function<void()> yesFunction, std::function<void()> noFunction)
|
2023-12-23 21:09:41 +01:00
|
|
|
: hex::Popup<PopupQuestion>("hex.ui.common.question", false),
|
2023-04-08 00:58:53 +02:00
|
|
|
m_message(std::move(message)),
|
|
|
|
m_yesFunction(std::move(yesFunction)), m_noFunction(std::move(noFunction)) { }
|
|
|
|
|
|
|
|
void drawContent() override {
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGuiExt::TextFormattedWrapped("{}", m_message.c_str());
|
2023-04-08 00:58:53 +02:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
2023-12-23 21:09:41 +01:00
|
|
|
if (ImGui::Button("hex.ui.common.yes"_lang, ImVec2(width / 3, 0))) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_yesFunction();
|
2023-04-16 21:34:29 +02:00
|
|
|
this->close();
|
|
|
|
}
|
2023-04-08 00:58:53 +02:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
2023-12-23 21:09:41 +01:00
|
|
|
if (ImGui::Button("hex.ui.common.no"_lang, ImVec2(width / 3, 0))) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_noFunction();
|
2023-04-16 21:34:29 +02:00
|
|
|
this->close();
|
|
|
|
}
|
2023-04-08 00:58:53 +02:00
|
|
|
|
|
|
|
ImGui::SetWindowPos((ImHexApi::System::getMainWindowSize() - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
|
|
|
|
return ImGuiWindowFlags_AlwaysAutoResize;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMinSize() const override {
|
|
|
|
return scaled({ 400, 100 });
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMaxSize() const override {
|
|
|
|
return scaled({ 600, 300 });
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_message;
|
|
|
|
std::function<void()> m_yesFunction, m_noFunction;
|
|
|
|
};
|
|
|
|
|
2024-04-23 21:01:58 +02:00
|
|
|
class PopupCancelableQuestion : public Popup<PopupCancelableQuestion> {
|
|
|
|
public:
|
|
|
|
PopupCancelableQuestion(std::string message, std::function<void()> yesFunction, std::function<void()> noFunction)
|
|
|
|
: hex::Popup<PopupCancelableQuestion>("hex.ui.common.question", false),
|
|
|
|
m_message(std::move(message)),
|
|
|
|
m_yesFunction(std::move(yesFunction)), m_noFunction(std::move(noFunction)) { }
|
|
|
|
|
|
|
|
void drawContent() override {
|
|
|
|
ImGuiExt::TextFormattedWrapped("{}", m_message.c_str());
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
|
|
|
if (ImGui::Button("hex.ui.common.yes"_lang, ImVec2(width / 3, 0))) {
|
|
|
|
m_yesFunction();
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("hex.ui.common.no"_lang, ImVec2(width / 3, 0))) {
|
|
|
|
m_noFunction();
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("hex.ui.common.cancel"_lang, ImVec2(width / 3, 0))) {
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetWindowPos((ImHexApi::System::getMainWindowSize() - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
|
|
|
|
return ImGuiWindowFlags_AlwaysAutoResize;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMinSize() const override {
|
|
|
|
return scaled({ 400, 100 });
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMaxSize() const override {
|
|
|
|
return scaled({ 600, 300 });
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_message;
|
|
|
|
std::function<void()> m_yesFunction, m_noFunction;
|
|
|
|
};
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
}
|