2023-06-21 20:07:36 +02: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-06-21 20:07:36 +02:00
|
|
|
#include <hex/api/imhex_api.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
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class PopupNotification : public Popup<T> {
|
|
|
|
public:
|
2023-12-19 12:22:28 +01:00
|
|
|
PopupNotification(UnlocalizedString unlocalizedName, std::string message, std::function<void()> function)
|
2023-04-08 00:58:53 +02:00
|
|
|
: hex::Popup<T>(std::move(unlocalizedName), false),
|
|
|
|
m_message(std::move(message)), m_function(std::move(function)) { }
|
|
|
|
|
|
|
|
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();
|
2023-12-23 21:09:41 +01:00
|
|
|
if (ImGui::Button("hex.ui.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape))
|
2023-12-19 13:10:25 +01:00
|
|
|
m_function();
|
2023-04-08 00:58:53 +02:00
|
|
|
|
|
|
|
ImGui::SetWindowPos((ImHexApi::System::getMainWindowSize() - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
2023-12-13 15:08:27 +01:00
|
|
|
|
|
|
|
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
|
|
|
this->close();
|
2023-04-08 00:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[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_function;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class PopupInfo : public impl::PopupNotification<PopupInfo> {
|
|
|
|
public:
|
|
|
|
explicit PopupInfo(std::string message)
|
2023-12-23 21:09:41 +01:00
|
|
|
: PopupNotification("hex.ui.common.info", std::move(message), [this] {
|
2023-04-08 00:58:53 +02:00
|
|
|
Popup::close();
|
|
|
|
}) { }
|
|
|
|
};
|
|
|
|
|
2023-06-21 20:07:36 +02:00
|
|
|
class PopupWarning : public impl::PopupNotification<PopupWarning> {
|
|
|
|
public:
|
|
|
|
explicit PopupWarning(std::string message)
|
2023-12-23 21:09:41 +01:00
|
|
|
: PopupNotification("hex.ui.common.warning", std::move(message), [this] {
|
2023-06-21 20:07:36 +02:00
|
|
|
Popup::close();
|
|
|
|
}) { }
|
|
|
|
};
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
class PopupError : public impl::PopupNotification<PopupError> {
|
|
|
|
public:
|
|
|
|
explicit PopupError(std::string message)
|
2023-12-23 21:09:41 +01:00
|
|
|
: PopupNotification("hex.ui.common.error", std::move(message), [this] {
|
2023-04-08 00:58:53 +02:00
|
|
|
Popup::close();
|
|
|
|
}) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
class PopupFatal : public impl::PopupNotification<PopupFatal> {
|
|
|
|
public:
|
|
|
|
explicit PopupFatal(std::string message)
|
2023-12-23 21:09:41 +01:00
|
|
|
: PopupNotification("hex.ui.common.fatal", std::move(message), [this] {
|
2023-04-08 00:58:53 +02:00
|
|
|
ImHexApi::System::closeImHex();
|
|
|
|
Popup::close();
|
|
|
|
}) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|